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 wo...@apache.org on 2008/09/03 16:12:53 UTC
svn commit: r691620 - 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: woonsan
Date: Wed Sep 3 07:12:52 2008
New Revision: 691620
URL: http://svn.apache.org/viewvc?rev=691620&view=rev
Log:
Flattening the Principal API.
Add `create' argument in SecurityAttributes.getAttribute() method for convenience.
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/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=691620&r1=691619&r2=691620&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 Wed Sep 3 07:12:52 2008
@@ -153,8 +153,7 @@
if (innerSubsite != null)
{
User innerUser = userManager.getUser(innerUserName);
- SecurityAttribute userAttr = innerUser.getSecurityAttributes().addAttribute(User.USER_INFO_SUBSITE);
- userAttr.setStringValue(innerSubsite);
+ innerUser.getSecurityAttributes().getAttribute(User.USER_INFO_SUBSITE, true).setStringValue(innerSubsite);
userManager.updateUser(innerUser);
}
Folder source = innerPageManager.getFolder(innerFolderTemplate);
@@ -190,10 +189,6 @@
{
return ae;
}
- catch (AttributeAlreadyExistsException ae)
- {
- return ae;
- }
}
}, 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=691620&r1=691619&r2=691620&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 Wed Sep 3 07:12:52 2008
@@ -223,11 +223,11 @@
{
SecurityAttributes userAttrs = user.getSecurityAttributes();
Iterator info = userInfo.entrySet().iterator();
+
while (info.hasNext())
{
- Map.Entry entry = (Map.Entry)info.next();
- SecurityAttribute userAttr = userAttrs.addAttribute((String)entry.getKey());
- userAttr.setStringValue((String) entry.getValue());
+ Map.Entry entry = (Map.Entry) info.next();
+ userAttrs.getAttribute((String) entry.getKey(), true).setStringValue((String) entry.getValue());
}
}
@@ -283,9 +283,7 @@
{
if (innerSubsite != null)
{
- SecurityAttributes userAttrs = innerUser.getSecurityAttributes();
- SecurityAttribute userAttr = userAttrs.addAttribute(User.USER_INFO_SUBSITE);
- userAttr.setStringValue(innerSubsite);
+ innerUser.getSecurityAttributes().getAttribute(User.USER_INFO_SUBSITE, true).setStringValue(innerSubsite);
userManager.updateUser(innerUser);
}
// create user's home folder
@@ -325,10 +323,6 @@
{
return e1;
}
- catch (AttributeAlreadyExistsException e1)
- {
- return e1;
- }
}
}, 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=691620&r1=691619&r2=691620&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 Wed Sep 3 07:12:52 2008
@@ -34,6 +34,7 @@
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
import org.apache.jetspeed.request.RequestContext;
import org.apache.jetspeed.security.SecurityAttribute;
+import org.apache.jetspeed.security.SecurityAttributeType;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.SecurityHelper;
import org.apache.jetspeed.security.User;
@@ -178,9 +179,27 @@
{
assertTrue("user exists. should not have thrown an exception.", false);
}
+
SecurityAttributes attributes = user.getSecurityAttributes();
- attributes.addAttribute("user.name.given").setStringValue("Test Dude");
- attributes.addAttribute("user.name.family").setStringValue("Dudley");
+
+ 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");
+ }
+
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=691620&r1=691619&r2=691620&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 Wed Sep 3 07:12:52 2008
@@ -143,22 +143,32 @@
return saMap.get(name);
}
- public SecurityAttribute addAttribute(String name)
- throws AttributesReadOnlyException, AttributeTypeNotFoundException, AttributeAlreadyExistsException
+ public SecurityAttribute getAttribute(String name, boolean create)
+ throws AttributesReadOnlyException, AttributeTypeNotFoundException
{
if (isReadOnly())
{
throw new AttributesReadOnlyException();
- }
+ }
+
SecurityAttributeType sat = getSecurityAttributeTypes().getAttributeTypeMap().get(name);
+
if (sat == null)
{
throw new AttributeTypeNotFoundException();
}
- if (saMap.containsKey(name))
+
+ SecurityAttribute sa = saMap.get(name);
+
+ if (sa != null)
{
- throw new AttributeAlreadyExistsException();
+ return sa;
+ }
+ else if ( create == false )
+ {
+ return null;
}
+
SecurityAttributeValue value = new SecurityAttributeValue(name);
avColl.add(value);
return saMap.put(name, new SecurityAttributeImpl(sat, value));
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=691620&r1=691619&r2=691620&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 Wed Sep 3 07:12:52 2008
@@ -48,8 +48,22 @@
SecurityAttribute getAttribute(String name);
- SecurityAttribute addAttribute(String name)
- throws AttributesReadOnlyException, AttributeTypeNotFoundException, AttributeAlreadyExistsException;
+ /**
+ * Returns an existing (predefined typed) attribute.
+ * 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.
+ * @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;
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org