portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r894273 - in /portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src: main/java/org/apache/jetspeed/om/page/ main/java/org/apache/jetspeed/om/page/psml/ main/resources/JETSPEED-INF/castor/ test/java/org/apache/jetspeed/page/
Date Mon, 28 Dec 2009 23:18:03 GMT
Author: rwatler
Date: Mon Dec 28 23:18:03 2009
New Revision: 894273

URL: http://svn.apache.org/viewvc?rev=894273&view=rev
Log:
implement missing filtering of fragment properties list for XML/File PM implementation

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PropertiesList.java
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/BaseFragmentPropertyImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/resources/JETSPEED-INF/castor/page-mapping.xml
    portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/BaseFragmentPropertyImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/BaseFragmentPropertyImpl.java?rev=894273&r1=894272&r2=894273&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/BaseFragmentPropertyImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/BaseFragmentPropertyImpl.java
Mon Dec 28 23:18:03 2009
@@ -18,6 +18,7 @@
 
 import java.security.AccessController;
 import java.security.Principal;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -149,6 +150,88 @@
     }
 
     /**
+     * Filter fragment properties in list based on current user.
+     * 
+     * @param properties unfiltered fragment properties list
+     * @return filtered fragment properties
+     */
+    public static List filterFragmentProperties(List properties)
+    {
+        List filteredProperties = new ArrayList();
+        
+        // iterate through properties list and merge with current
+        // principals to determine most specific property value
+        Set principals = null;
+        Principal userPrincipal = null;
+        boolean skipPropertyScopes = false;
+        Iterator propertiesIter = properties.iterator();
+        while (propertiesIter.hasNext())
+        {
+            FragmentProperty fragmentProperty = (FragmentProperty)propertiesIter.next();
+            String fragmentPropertyScope = fragmentProperty.getScope();
+            if (fragmentPropertyScope != null)
+            {
+                if (!skipPropertyScopes)
+                {
+                    // get principals
+                    if (principals == null)
+                    {
+                        // get current request context subject for principals
+                        Subject subject = JSSubject.getSubject(AccessController.getContext());
+                        if (subject != null)
+                        {
+                            if (GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
+                            {
+                                principals = subject.getPrincipals();
+                            }
+                            else
+                            {
+                                userPrincipal = SubjectHelper.getBestPrincipal(subject, User.class);
+                            }
+                        }
+                        else
+                        {
+                            skipPropertyScopes = true;
+                        }
+                    }
+                    String fragmentPropertyScopeValue = fragmentProperty.getScopeValue();
+                    if (userPrincipal != null)
+                    {
+                        // match user property scope and scope value with user principal
+                        if (fragmentPropertyScope.equals(USER_PROPERTY_SCOPE) &&
userPrincipal.getName().equals(fragmentPropertyScopeValue))
+                        {
+                            filteredProperties.add(fragmentProperty);
+                        }
+                    }
+                    else if (principals != null)
+                    {
+                        // match property scope and scope value with most specific
+                        // principal without a value
+                        Iterator principalsIter = principals.iterator();
+                        while (principalsIter.hasNext())
+                        {
+                            Principal principal = (Principal)principalsIter.next();
+                            if (principal.getName().equals(fragmentPropertyScopeValue) &&
+                                ((fragmentPropertyScope.equals(USER_PROPERTY_SCOPE) &&
(principal instanceof User)) ||
+                                 (fragmentPropertyScope.equals(GROUP_PROPERTY_SCOPE) &&
(principal instanceof Group)) ||
+                                 (fragmentPropertyScope.equals(ROLE_PROPERTY_SCOPE) &&
(principal instanceof Role))))
+                            {
+                                filteredProperties.add(fragmentProperty);
+                            }
+                        }
+                    }
+                }
+            }
+            else
+            {
+                filteredProperties.add(fragmentProperty);
+            }
+        }
+        
+        return filteredProperties;
+    }
+
+    /**
      * Find fragment property by name, scope, and scope value.
      * 
      * @param propName property name

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java?rev=894273&r1=894272&r2=894273&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/AbstractBaseFragmentElement.java
Mon Dec 28 23:18:03 2009
@@ -46,7 +46,7 @@
 
     private String skin = null;
 
-    private List properties = new ArrayList();
+    private List propertyImpls = new ArrayList();
     
     private List preferences = new ArrayList();
     
@@ -233,7 +233,7 @@
         }
 
         // find specified scoped property value
-        FragmentProperty fragmentProperty = PropertyImpl.findFragmentProperty(propName, propScope,
propScopeValue, properties);
+        FragmentProperty fragmentProperty = PropertyImpl.findFragmentProperty(propName, propScope,
propScopeValue, propertyImpls);
         if (fragmentProperty != null)
         {
             return fragmentProperty.getValue();
@@ -330,7 +330,7 @@
         }
 
         // find specified scoped property value
-        FragmentProperty fragmentProperty = PropertyImpl.findFragmentProperty(propName, propScope,
propScopeValue, properties);
+        FragmentProperty fragmentProperty = PropertyImpl.findFragmentProperty(propName, propScope,
propScopeValue, propertyImpls);
 
         // add, set, or remove property
         if (propValue != null)
@@ -342,7 +342,7 @@
                 fragmentProperty.setScope(propScope);
                 fragmentProperty.setScopeValue(propScopeValue);
                 fragmentProperty.setValue(propValue);
-                properties.add(fragmentProperty);
+                propertyImpls.add(fragmentProperty);
             }
             else
             {
@@ -351,7 +351,7 @@
         }
         else if (fragmentProperty != null)
         {
-            properties.remove(fragmentProperty);
+            propertyImpls.remove(fragmentProperty);
         }
     }
     
@@ -376,7 +376,7 @@
      */
     public List getProperties()
     {
-        return properties;
+        return new PropertiesList(PropertyImpl.filterFragmentProperties(propertyImpls), propertyImpls);
     }
 
     /**
@@ -384,11 +384,11 @@
      */
     public void setProperties(List properties)
     {
-        if (properties == null)
-        {
-            properties = new ArrayList();
-        }
-        this.properties = properties;  
+        // get and remove all filtered properties and replace
+        // with new specified properties
+        List propertiesList = getProperties();
+        propertiesList.clear();
+        propertiesList.addAll(properties);
     } 
     
     /**
@@ -728,6 +728,26 @@
     }
     
     /**
+     * Castor raw properties collection member access.
+     * 
+     * @return properties collection
+     */
+    public List getPropertyImpls()
+    {
+        return propertyImpls;
+    }
+
+    /**
+     * Castor raw properties collection member access.
+     * 
+     * @param propertiesImpls properties collection
+     */
+    public void setPropertyImpls(List propertiesImpls)
+    {
+        this.propertyImpls = propertyImpls;  
+    } 
+    
+    /**
      * unmarshalled - notification that this instance has been
      *                loaded from the persistent store
      * @param generator id generator

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PropertiesList.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PropertiesList.java?rev=894273&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PropertiesList.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/psml/PropertiesList.java
Mon Dec 28 23:18:03 2009
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.om.page.psml;
+
+import java.util.AbstractList;
+import java.util.List;
+
+/**
+ * PropertiesList
+ *
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id$
+ */
+public class PropertiesList extends AbstractList
+{
+    private List filteredProperties;
+    private List properties;
+   
+    PropertiesList(List filteredProperties, List properties)
+    {
+        this.filteredProperties = filteredProperties;
+        this.properties = properties;
+    }
+    
+    /* (non-Javadoc)
+     * @see java.util.List#add(int,java.lang.Object)
+     */
+    public void add(int index, Object element)
+    {
+        // implement for modifiable AbstractList
+        PropertyImpl addFragmentProperty = (PropertyImpl)element;
+        filteredProperties.add(addFragmentProperty);
+        properties.add(addFragmentProperty);
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#get(int)
+     */
+    public Object get(int index)
+    {
+        // implement for modifiable AbstractList
+        return filteredProperties.get(index);
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#remove(int)
+     */
+    public Object remove(int index)
+    {
+        // implement for modifiable AbstractList
+        PropertyImpl removedFragmentProperty = (PropertyImpl)filteredProperties.remove(index);
+        if (removedFragmentProperty != null)
+        {
+            properties.remove(removedFragmentProperty);
+        }
+        return removedFragmentProperty;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#set(int,java.lang.Object)
+     */
+    public Object set(int index, Object element)
+    {
+        // implement for modifiable AbstractList
+        PropertyImpl addFragmentProperty = (PropertyImpl)element;
+        PropertyImpl removedFragmentProperty = (PropertyImpl)filteredProperties.set(index,
element);
+        properties.add(addFragmentProperty);
+        if (removedFragmentProperty != null)
+        {
+            properties.remove(removedFragmentProperty);
+        }
+        return removedFragmentProperty;
+    }
+
+    /* (non-Javadoc)
+     * @see java.util.List#size()
+     */
+    public int size()
+    {
+        // implement for modifiable AbstractList
+        return filteredProperties.size();
+    }
+}
+

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/resources/JETSPEED-INF/castor/page-mapping.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/resources/JETSPEED-INF/castor/page-mapping.xml?rev=894273&r1=894272&r2=894273&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/resources/JETSPEED-INF/castor/page-mapping.xml
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/main/resources/JETSPEED-INF/castor/page-mapping.xml
Mon Dec 28 23:18:03 2009
@@ -170,7 +170,7 @@
       <bind-xml name="short-title"/>
     </field>
 
-    <field name="properties"
+    <field name="propertyImpls"
            type="org.apache.jetspeed.om.page.psml.PropertyImpl" collection="arraylist">
       <bind-xml name="property"/>
     </field>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java?rev=894273&r1=894272&r2=894273&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-page-manager/src/test/java/org/apache/jetspeed/page/TestCastorXmlPageManager.java
Mon Dec 28 23:18:03 2009
@@ -234,7 +234,7 @@
 
         List properties = f.getProperties();
         assertNotNull(properties);
-        assertTrue(properties.size() == 17);
+        assertEquals(11, properties.size());
         assertEquals("0", f.getProperty(Fragment.ROW_PROPERTY_NAME));
         assertEquals(0, f.getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
         assertEquals(0, f.getLayoutRow());
@@ -263,7 +263,7 @@
                     assertTrue(userFragment.getId().equals("pe001"));
                     List properties = userFragment.getProperties();
                     assertNotNull(properties);
-                    assertTrue(properties.size() == 17);
+                    assertEquals((FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED
? 17 : 12), properties.size());
                     assertEquals("0", userFragment.getProperty(Fragment.ROW_PROPERTY_NAME));
                     assertEquals(0, userFragment.getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
                     assertTrue((userFragment.getLayoutHeight() > 55.0F) && (userFragment.getLayoutHeight()
< 56.0F));
@@ -332,7 +332,7 @@
 
         properties = f.getProperties();
         assertNotNull(properties);
-        assertTrue(properties.size() == 2);
+        assertEquals(2, properties.size());
         assertEquals("0", f.getProperty(Fragment.ROW_PROPERTY_NAME));
         assertEquals(1, f.getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
 
@@ -1473,11 +1473,11 @@
         List cloneProperties = cf.getProperties();
 
         assertNotNull(cloneProperties);
-        assertTrue(cloneProperties.size() == 4);
+        assertEquals(3, cloneProperties.size());
         assertEquals("0", cf.getProperty(Fragment.ROW_PROPERTY_NAME));
         assertEquals(0, cf.getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
         assertEquals("custom-value", cf.getProperty("custom"));
-        assertEquals("custom-value-user", cf.getProperty("custom", Fragment.USER_PROPERTY_SCOPE,
"user"));
+        assertNull(cf.getProperty("custom", Fragment.USER_PROPERTY_SCOPE, "user"));
 
         cf = (Fragment) cloneChildren.get(1);
         f = (Fragment) children.get(1);
@@ -1488,7 +1488,7 @@
 
         properties = cf.getProperties();
         assertNotNull(properties);
-        assertTrue(properties.size() == 2);
+        assertEquals(2, properties.size());
         assertEquals("0", cf.getProperty(Fragment.ROW_PROPERTY_NAME));
         assertEquals(1, cf.getIntProperty(Fragment.COLUMN_PROPERTY_NAME));
 



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message