You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2008/09/18 12:04:21 UTC

svn commit: r696618 - in /portals/jetspeed-2/portal/branches/security-refactoring: components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/ components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/ components/je...

Author: ate
Date: Thu Sep 18 03:04:21 2008
New Revision: 696618

URL: http://svn.apache.org/viewvc?rev=696618&view=rev
Log:
Simplifying SecurityAttributes handing for adding/updating attributes

Removed:
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AttributeAlreadyExistsException.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AttributeTypeAlreadyDefinedException.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/AttributeTypeNotFoundException.java
Modified:
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/test/java/org/apache/jetspeed/userinfo/TestUserInfoManager.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java
    portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttribute.java
    portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttributes.java

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java?rev=696618&r1=696617&r2=696618&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/JetspeedUserTemplateSerializer.java Thu Sep 18 03:04:21 2008
@@ -32,7 +32,8 @@
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.page.PageManagerUtils;
 import org.apache.jetspeed.page.document.NodeException;
-import org.apache.jetspeed.security.AttributeTypeNotFoundException;
+import org.apache.jetspeed.security.AttributeReadOnlyException;
+import org.apache.jetspeed.security.AttributesNotExtendableException;
 import org.apache.jetspeed.security.AttributesReadOnlyException;
 import org.apache.jetspeed.security.JSSubject;
 import org.apache.jetspeed.security.SecurityException;
@@ -190,10 +191,14 @@
                 catch (AttributesReadOnlyException ae)
                 {
                     return ae;
-                } 
-                catch (AttributeTypeNotFoundException ae)
+                }
+                catch (AttributeReadOnlyException e)
                 {
-                    return ae;
+                    return e;
+                }
+                catch (AttributesNotExtendableException e)
+                {
+                    return e;
                 } 
             }
         }, null);

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java?rev=696618&r1=696617&r2=696618&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/main/java/org/apache/jetspeed/administration/PortalAdministrationImpl.java Thu Sep 18 03:04:21 2008
@@ -43,7 +43,8 @@
 import org.apache.jetspeed.profiler.Profiler;
 import org.apache.jetspeed.profiler.rules.ProfilingRule;
 import org.apache.jetspeed.request.RequestContext;
-import org.apache.jetspeed.security.AttributeTypeNotFoundException;
+import org.apache.jetspeed.security.AttributeReadOnlyException;
+import org.apache.jetspeed.security.AttributesNotExtendableException;
 import org.apache.jetspeed.security.AttributesReadOnlyException;
 import org.apache.jetspeed.security.GroupManager;
 import org.apache.jetspeed.security.JSSubject;
@@ -315,9 +316,13 @@
                         {
                             return e1;
                         } 
-                        catch (AttributeTypeNotFoundException e1)
+                        catch (AttributeReadOnlyException e)
                         {
-                            return e1;
+                            return e;
+                        }
+                        catch (AttributesNotExtendableException e)
+                        {
+                            return e;
                         } 
                     }
                 }, null);

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/test/java/org/apache/jetspeed/userinfo/TestUserInfoManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/test/java/org/apache/jetspeed/userinfo/TestUserInfoManager.java?rev=696618&r1=696617&r2=696618&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/test/java/org/apache/jetspeed/userinfo/TestUserInfoManager.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-portal/src/test/java/org/apache/jetspeed/userinfo/TestUserInfoManager.java Thu Sep 18 03:04:21 2008
@@ -32,7 +32,6 @@
 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.security.JetspeedSubjectFactory;
-import org.apache.jetspeed.security.SecurityAttributeType;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.User;
 import org.apache.jetspeed.security.SecurityAttributes;
@@ -178,24 +177,8 @@
         }
         
         SecurityAttributes attributes = user.getSecurityAttributes();
-        
-        if (attributes.getSecurityAttributeTypes().getAttributeTypeMap().containsKey("user.name.given"))
-        {
-            attributes.getAttribute("user.name.given", true).setStringValue("Test Dude");
-        }
-        else
-        {
-            attributes.addNewInfoAttribute("user.name.given", SecurityAttributeType.DataType.STRING).setStringValue("Test Dude");
-        }
-        
-        if (attributes.getSecurityAttributeTypes().getAttributeTypeMap().containsKey("user.name.family"))
-        {
-            attributes.getAttribute("user.name.family", true).setStringValue("Dudley");
-        }
-        else
-        {
-            attributes.addNewInfoAttribute("user.name.family", SecurityAttributeType.DataType.STRING).setStringValue("Dudley");
-        }
+        attributes.getAttribute("user.name.given", true).setStringValue("Test Dude");
+        attributes.getAttribute("user.name.family", true).setStringValue("Dudley");
         
         ums.updateUser(user);
     }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java?rev=696618&r1=696617&r2=696618&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/SecurityAttributesImpl.java Thu Sep 18 03:04:21 2008
@@ -25,7 +25,6 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.jetspeed.security.AttributeAlreadyExistsException;
 import org.apache.jetspeed.security.AttributesNotExtendableException;
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.AttributeReadOnlyException;
@@ -33,11 +32,8 @@
 import org.apache.jetspeed.security.AttributeRequiredException;
 import org.apache.jetspeed.security.SecurityAttribute;
 import org.apache.jetspeed.security.SecurityAttributeType;
-import org.apache.jetspeed.security.AttributeTypeAlreadyDefinedException;
-import org.apache.jetspeed.security.AttributeTypeNotFoundException;
 import org.apache.jetspeed.security.SecurityAttributeTypes;
 import org.apache.jetspeed.security.SecurityAttributes;
-import org.apache.jetspeed.security.SecurityAttributeType.DataType;
 
 /**
  * @version $Id$
@@ -132,6 +128,11 @@
         return Collections.unmodifiableSet(set);
     }
 
+    public boolean isDefinedAttribute(String name)
+    {
+        return jp.getType().getAttributeTypes().getAttributeTypeMap().containsKey(name);
+    }
+
     public Map<String, SecurityAttribute> getAttributeMap()
     {
         return Collections.unmodifiableMap(new HashMap<String, SecurityAttribute>(saMap));
@@ -174,64 +175,47 @@
     }
 
     public SecurityAttribute getAttribute(String name, boolean create)
-        throws AttributesReadOnlyException, AttributeTypeNotFoundException
+        throws AttributesReadOnlyException, AttributesNotExtendableException
     {
-        if (isReadOnly())
-        {
-            throw new AttributesReadOnlyException();
-        }
-        
-        SecurityAttributeType sat = getSecurityAttributeTypes().getAttributeTypeMap().get(name);
-        
-        if (sat == null)
-        {
-            throw new AttributeTypeNotFoundException();
-        }
-        
-        SecurityAttribute sa = saMap.get(name);
+        SecurityAttributeImpl sa = saMap.get(name);
         
         if (sa != null)
         {
             return sa;
         }
-        else if ( create == false )
+        else if (!create)
         {
             return null;
         }
         
-        SecurityAttributeValue value = new SecurityAttributeValue(name);
-        avColl.add(value);
-        SecurityAttributeImpl attr = new SecurityAttributeImpl(sat, value, persistent);
-        saMap.put(name, attr);
-        return attr;
-    }
-
-    public SecurityAttribute addNewInfoAttribute(String name, DataType type)
-        throws AttributesReadOnlyException, AttributeTypeAlreadyDefinedException, AttributeAlreadyExistsException, AttributesNotExtendableException
-    {
         if (isReadOnly())
         {
             throw new AttributesReadOnlyException();
-        }        
-        if (!isExtendable())
-        {
-            throw new AttributesNotExtendableException();
-        }        
+        }
+        
         SecurityAttributeType sat = getSecurityAttributeTypes().getAttributeTypeMap().get(name);
-        if (sat != null)
+                
+        if (sat == null)
         {
-            throw new AttributeTypeAlreadyDefinedException();
+            if (!isExtendable())
+            {
+                throw new AttributesNotExtendableException();
+            }
+            // New INFO_CATEGORY attribute, always of type STRING
+            SecurityAttributeValue value = new SecurityAttributeValue(name);
+            avColl.add(value);
+            sa = new SecurityAttributeImpl(new SecurityAttributeTypeImpl(name), value, persistent);
+            
         }
-        if (saMap.containsKey(name))
+        else
         {
-            throw new AttributeAlreadyExistsException();
+            SecurityAttributeValue value = new SecurityAttributeValue(name);
+            avColl.add(value);
+            sa = new SecurityAttributeImpl(sat, value, persistent);
         }
-        // TODO: making use of the DataType parameter (now ignored)
-        SecurityAttributeValue value = new SecurityAttributeValue(name);
-        avColl.add(value);
-        SecurityAttributeImpl attr = new SecurityAttributeImpl(new SecurityAttributeTypeImpl(name), value, persistent);
-        saMap.put(name, attr);
-        return attr;
+        
+        saMap.put(name, sa);
+        return sa;
     }
 
     public void removeAttribute(String name) throws AttributesReadOnlyException, AttributeReadOnlyException, AttributeRequiredException

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java?rev=696618&r1=696617&r2=696618&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultJetspeedPrincipalSynchronizer.java Thu Sep 18 03:04:21 2008
@@ -31,9 +31,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.security.AttributeReadOnlyException;
 import org.apache.jetspeed.security.AttributeRequiredException;
-import org.apache.jetspeed.security.AttributeTypeNotFoundException;
+import org.apache.jetspeed.security.AttributesNotExtendableException;
 import org.apache.jetspeed.security.AttributesReadOnlyException;
-import org.apache.jetspeed.security.DependentPrincipalException;
 import org.apache.jetspeed.security.JetspeedPrincipal;
 import org.apache.jetspeed.security.JetspeedPrincipalManager;
 import org.apache.jetspeed.security.JetspeedPrincipalManagerProvider;
@@ -42,7 +41,6 @@
 import org.apache.jetspeed.security.PrincipalAssociationRequiredException;
 import org.apache.jetspeed.security.PrincipalAssociationUnsupportedException;
 import org.apache.jetspeed.security.PrincipalNotFoundException;
-import org.apache.jetspeed.security.PrincipalNotRemovableException;
 import org.apache.jetspeed.security.PrincipalUpdateException;
 import org.apache.jetspeed.security.SecurityAttribute;
 import org.apache.jetspeed.security.SecurityAttributeType;
@@ -298,11 +296,19 @@
                         {
                             logger.error("Unexpected read-only exception for attribute " + addedEntityAttr.getMappedName() + ".", e);
                         }
-                    } catch (AttributeTypeNotFoundException e)
+                    } 
+                    catch (AttributesNotExtendableException e)
                     {
                         if (logger.isErrorEnabled())
                         {
-                            logger.error("Unexpected missing type exception for attribute " + addedEntityAttr.getMappedName() + ".", e);
+                            logger.error("Unexpected not extendable exception for attribute " + addedEntityAttr.getMappedName() + ".", e);
+                        }
+                    }
+                    catch (AttributeReadOnlyException e)
+                    {
+                        if (logger.isErrorEnabled())
+                        {
+                            logger.error("Unexpected read-only exception for attribute " + addedEntityAttr.getMappedName() + ".", e);
                         }
                     }
                 }

Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java?rev=696618&r1=696617&r2=696618&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/serializer/JetspeedSecuritySerializer.java Thu Sep 18 03:04:21 2008
@@ -38,7 +38,6 @@
 import org.apache.jetspeed.security.PermissionManager;
 import org.apache.jetspeed.security.Role;
 import org.apache.jetspeed.security.RoleManager;
-import org.apache.jetspeed.security.SecurityAttributeType;
 import org.apache.jetspeed.security.SecurityException;
 import org.apache.jetspeed.security.User;
 import org.apache.jetspeed.security.UserManager;
@@ -250,18 +249,9 @@
                         updated = true;
                     }
                     
-                    Map<String, SecurityAttributeType> secAttrTypeMap = secAttrs.getSecurityAttributeTypes().getAttributeTypeMap();
-                    
                     for (JSNVPElement elem : jsPrincipal.getInfoAttributes().getValues())
                     {
-                        if (secAttrTypeMap.containsKey(elem.getKey()))
-                        {
-                            secAttrs.getAttribute(elem.getKey(), true).setStringValue(elem.getValue());
-                        }
-                        else
-                        {
-                            secAttrs.addNewInfoAttribute(elem.getKey(), SecurityAttributeType.DataType.STRING).setStringValue(elem.getValue());
-                        }
+                        secAttrs.getAttribute(elem.getKey(), true).setStringValue(elem.getValue());
                         
                         updated = true;
                     }
@@ -422,21 +412,10 @@
                     if (attributes != null)
                     {
                         SecurityAttributes userSecAttrs = user.getSecurityAttributes();
-                        Map<String, SecurityAttributeType> userSecAttrTypeMap = userSecAttrs.getSecurityAttributeTypes().getAttributeTypeMap();
                         
                         for (JSNVPElement element : attributes.getValues())
                         {
-                            String attrName = element.getKey();
-                            String attrValue = element.getValue();
-                            
-                            if (userSecAttrTypeMap.containsKey(attrName))
-                            {
-                                userSecAttrs.getAttribute(attrName, true).setStringValue(attrValue);
-                            }
-                            else
-                            {
-                                userSecAttrs.addNewInfoAttribute(attrName, SecurityAttributeType.DataType.STRING).setStringValue(attrValue);
-                            }                            
+                            userSecAttrs.getAttribute(element.getKey(), true).setStringValue(element.getValue());
                         }
                     }
                     JSNVPElements jsNVP = jsuser.getSecurityAttributes();

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttribute.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttribute.java?rev=696618&r1=696617&r2=696618&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttribute.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttribute.java Thu Sep 18 03:04:21 2008
@@ -23,5 +23,5 @@
 {
     String getStringValue();
 
-    void setStringValue(String value);
+    void setStringValue(String value) throws AttributeReadOnlyException;
 }
\ No newline at end of file

Modified: portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttributes.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttributes.java?rev=696618&r1=696617&r2=696618&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttributes.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/jetspeed-api/src/main/java/org/apache/jetspeed/security/SecurityAttributes.java Thu Sep 18 03:04:21 2008
@@ -33,6 +33,8 @@
     boolean isExtendable();
     
     SecurityAttributeTypes getSecurityAttributeTypes();
+    
+    boolean isDefinedAttribute(String name);
 
     Set<String> getAttributeNames();
 
@@ -52,24 +54,20 @@
     SecurityAttribute getAttribute(String name);
 
     /**
-     * Returns an existing (predefined typed) attribute.
+     * Returns an existing (predefined typed) attribute or create one if parameter create is true.
      * If parameter create is true and it doesn't exist yet it will be created (based
      * upon its SecurityAttributeType) first, but only if the SecurityAttributes itself
      * isn't readOnly (then a AttributesReadOnlyException will be thrown).
      * If parameter create is false and it doesn't exist yet a NULL value will be
      * returned.
-     * If there is no SecurityAttributeType defined for the attribute (name), an
-     * AttributeTypeNotFoundException will be thrown.
-     * and parameter create is true will add it before returning it.
+     * If there is no SecurityAttributeType defined for the attribute (name), a new attribute
+     * with INFO_CATEGORY will be created.
      * @param name name of a predefined SecurityAttributeType (for this JetspeedPrincipal type)
      * @param create add the attribute when it doesn't exist yet
      * @return an existing attribute or one created on the fly (if parameter create is true)
      */
     SecurityAttribute getAttribute(String name, boolean create)
-        throws AttributesReadOnlyException, AttributeTypeNotFoundException;
-
-    SecurityAttribute addNewInfoAttribute(String name, SecurityAttributeType.DataType type)
-        throws AttributesReadOnlyException, AttributeTypeAlreadyDefinedException, AttributeAlreadyExistsException, AttributesNotExtendableException;
+        throws AttributesReadOnlyException, AttributesNotExtendableException;
 
     void removeAttribute(String name) throws AttributesReadOnlyException, AttributeReadOnlyException, AttributeRequiredException;
 }



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