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 ta...@apache.org on 2008/08/07 05:52:09 UTC
svn commit: r683497 [3/7] - in /portals/jetspeed-2/portal/branches/JS2-869:
components/jetspeed-capability/src/main/java/org/apache/jetspeed/serializer/
components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/serializer/
components/jetspeed-...
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java Wed Aug 6 20:52:05 2008
@@ -19,25 +19,23 @@
import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.i18n.KeyedMessage;
import org.apache.jetspeed.security.AuthenticationProviderProxy;
import org.apache.jetspeed.security.Role;
import org.apache.jetspeed.security.RoleManager;
import org.apache.jetspeed.security.RolePrincipal;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.SecurityProvider;
+import org.apache.jetspeed.security.attributes.SecurityAttributes;
+import org.apache.jetspeed.security.attributes.SecurityAttributesProvider;
import org.apache.jetspeed.security.spi.RoleSecurityHandler;
import org.apache.jetspeed.security.spi.SecurityMappingHandler;
-import org.apache.jetspeed.util.ArgUtil;
/**
* <p>
@@ -71,113 +69,59 @@
/** The security mapping handler. */
private SecurityMappingHandler securityMappingHandler = null;
+ private SecurityAttributesProvider attributesProvider;
+
/**
* @param securityProvider The security provider.
*/
- public RoleManagerImpl(SecurityProvider securityProvider)
+ public RoleManagerImpl(SecurityProvider securityProvider, SecurityAttributesProvider attributesProvider)
{
this.atnProviderProxy = securityProvider.getAuthenticationProviderProxy();
this.roleSecurityHandler = securityProvider.getRoleSecurityHandler();
this.securityMappingHandler = securityProvider.getSecurityMappingHandler();
+ this.attributesProvider = attributesProvider;
}
/**
* @see org.apache.jetspeed.security.RoleManager#addRole(java.lang.String)
*/
- public void addRole(String roleFullPathName) throws SecurityException
+ public void addRole(String roleName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName }, new String[] { "roleFullPathName" },
- "addRole(java.lang.String)");
-
- // Check if role already exists.
- if (roleExists(roleFullPathName))
- {
- throw new SecurityException(SecurityException.ROLE_ALREADY_EXISTS.create(roleFullPathName));
- }
-
- RolePrincipal rolePrincipal = new RolePrincipalImpl(roleFullPathName);
- String fullPath = rolePrincipal.getFullPath();
- // Add the preferences.
- Preferences preferences = Preferences.userRoot().node(fullPath);
+ if (roleExists(roleName))
+ {
+ throw new SecurityException(SecurityException.ROLE_ALREADY_EXISTS.create(roleName));
+ }
+ RolePrincipal rolePrincipal = new RolePrincipalImpl(roleName);
+ roleSecurityHandler.storeRolePrincipal(rolePrincipal);
+ SecurityAttributes sa = attributesProvider.createSecurityAttributes(rolePrincipal);
+ attributesProvider.saveAttributes(sa);
if (log.isDebugEnabled())
- {
- log.debug("Added role preferences node: " + fullPath);
- }
- try
- {
- if ((null != preferences) && preferences.absolutePath().equals(fullPath))
- {
- // Add role principal.
- roleSecurityHandler.setRolePrincipal(rolePrincipal);
- if (log.isDebugEnabled())
- {
- log.debug("Added role: " + fullPath);
- }
- }
- }
- catch (SecurityException se)
- {
- KeyedMessage msg =
- SecurityException.UNEXPECTED.create("RoleManager.addRole",
- "RoleSecurityHandler.setRolePrincipal("+rolePrincipal.getName()+")",
- se.getMessage());
- log.error(msg, se);
-
- // Remove the preferences node.
- try
- {
- preferences.removeNode();
- }
- catch (BackingStoreException bse)
- {
- bse.printStackTrace();
- }
- throw new SecurityException(msg, se);
- }
+ log.debug("Added role: " + roleName);
}
/**
* @see org.apache.jetspeed.security.RoleManager#removeRole(java.lang.String)
*/
- public void removeRole(String roleFullPathName) throws SecurityException
+ public void removeRole(String roleName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName }, new String[] { "roleFullPathName" },
- "removeRole(java.lang.String)");
-
- // Resolve the role hierarchy.
- Preferences prefs = Preferences.userRoot().node(
- RolePrincipalImpl.getFullPathFromPrincipalName(roleFullPathName));
- String[] roles = securityMappingHandler.getRoleHierarchyResolver().resolveChildren(prefs);
- for (int i = 0; i < roles.length; i++)
+ if (securityMappingHandler.getHierarchyResolver() != null)
{
- try
- {
- roleSecurityHandler.removeRolePrincipal(new RolePrincipalImpl(RolePrincipalImpl
- .getPrincipalNameFromFullPath(roles[i])));
- }
- catch (Exception e)
- {
- KeyedMessage msg =
- SecurityException.UNEXPECTED.create("RoleManager.removeRole",
- "RoleSecurityHandler.removeRolePrincipal("+RolePrincipalImpl.getPrincipalNameFromFullPath(roles[i])+")",
- e.getMessage());
- log.error(msg, e);
- throw new SecurityException(msg, e);
- }
- // Remove preferences
- Preferences rolePref = Preferences.userRoot().node(roles[i]);
- try
+ Set<RolePrincipal> roles = securityMappingHandler.getHierarchyResolver().resolveRoles(roleName);
+ for (RolePrincipal gp : roles)
{
- rolePref.removeNode();
+ roleSecurityHandler.removeRolePrincipal(gp);
+// TODO: should we use cascading deletes?
+ attributesProvider.deleteAttributes(gp);
}
- catch (BackingStoreException bse)
+ }
+ else
+ {
+ RolePrincipal rp = roleSecurityHandler.getRolePrincipal(roleName);
+ if (rp != null)
{
- KeyedMessage msg =
- SecurityException.UNEXPECTED.create("RoleManager.removeRole",
- "Preferences.removeNode("+roles[i]+")",
- bse.getMessage());
- log.error(msg, bse);
- throw new SecurityException(msg, bse);
+ roleSecurityHandler.removeRolePrincipal(new RolePrincipalImpl(roleName));
+// TODO: should we use cascading deletes?
+ attributesProvider.deleteAttributes(rp);
}
}
}
@@ -185,58 +129,41 @@
/**
* @see org.apache.jetspeed.security.RoleManager#roleExists(java.lang.String)
*/
- public boolean roleExists(String roleFullPathName)
+ public boolean roleExists(String roleName)
{
- ArgUtil.notNull(new Object[] { roleFullPathName }, new String[] { "roleFullPathName" },
- "roleExists(java.lang.String)");
-
- Principal principal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
+ Principal principal = roleSecurityHandler.getRolePrincipal(roleName);
boolean roleExists = (null != principal);
- if (log.isDebugEnabled())
- {
- log.debug("Role exists: " + roleExists);
- log.debug("Role: " + roleFullPathName);
- }
return roleExists;
}
/**
* @see org.apache.jetspeed.security.RoleManager#getRole(java.lang.String)
*/
- public Role getRole(String roleFullPathName) throws SecurityException
+ public Role getRole(String roleName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName }, new String[] { "roleFullPathName" },
- "getRole(java.lang.String)");
-
- String fullPath = RolePrincipalImpl.getFullPathFromPrincipalName(roleFullPathName);
-
- Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
- if (null == rolePrincipal)
- {
- throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
+ Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleName);
+ if (null == rolePrincipal)
+ {
+ throw new SecurityException(
+ SecurityException.ROLE_DOES_NOT_EXIST.create(roleName));
}
- Preferences preferences = Preferences.userRoot().node(fullPath);
- Role role = new RoleImpl(rolePrincipal, preferences);
+ SecurityAttributes attributes = this.attributesProvider.retrieveAttributes(rolePrincipal);
+ Role role = new RoleImpl(rolePrincipal, attributes);
return role;
}
/**
* @see org.apache.jetspeed.security.RoleManager#getRolesForUser(java.lang.String)
*/
- public Collection getRolesForUser(String username) throws SecurityException
+ public Collection<Role> getRolesForUser(String username) throws SecurityException
{
- ArgUtil.notNull(new Object[] { username }, new String[] { "username" }, "getRolesForUser(java.lang.String)");
-
- Collection roles = new ArrayList();
+ Collection<Role> roles = new ArrayList<Role>();
- Set rolePrincipals = securityMappingHandler.getRolePrincipals(username);
- Iterator rolePrincipalsIter = rolePrincipals.iterator();
- while (rolePrincipalsIter.hasNext())
+ Set<RolePrincipal> rolePrincipals = securityMappingHandler.getRolePrincipals(username);
+ for (RolePrincipal rolePrincipal : rolePrincipals)
{
- Principal rolePrincipal = (Principal) rolePrincipalsIter.next();
- Preferences preferences = Preferences.userRoot().node(
- RolePrincipalImpl.getFullPathFromPrincipalName(rolePrincipal.getName()));
- roles.add(new RoleImpl(rolePrincipal, preferences));
+ SecurityAttributes attributes = this.attributesProvider.retrieveAttributes(rolePrincipal);
+ roles.add(new RoleImpl(rolePrincipal, attributes));
}
return roles;
}
@@ -244,21 +171,14 @@
/**
* @see org.apache.jetspeed.security.RoleManager#getRolesInGroup(java.lang.String)
*/
- public Collection getRolesInGroup(String groupFullPathName) throws SecurityException
+ public Collection<Role> getRolesInGroup(String groupName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { groupFullPathName }, new String[] { "groupFullPathName" },
- "getRolesInGroup(java.lang.String)");
-
- Collection roles = new ArrayList();
-
- Set rolePrincipals = securityMappingHandler.getRolePrincipalsInGroup(groupFullPathName);
- Iterator rolePrincipalsIter = rolePrincipals.iterator();
- while (rolePrincipalsIter.hasNext())
+ Collection<Role> roles = new ArrayList<Role>();
+ Set<RolePrincipal> rolePrincipals = securityMappingHandler.getRolePrincipalsInGroup(groupName);
+ for (RolePrincipal rolePrincipal : rolePrincipals)
{
- Principal rolePrincipal = (Principal) rolePrincipalsIter.next();
- Preferences preferences = Preferences.userRoot().node(
- RolePrincipalImpl.getFullPathFromPrincipalName(rolePrincipal.getName()));
- roles.add(new RoleImpl(rolePrincipal, preferences));
+ SecurityAttributes attributes = this.attributesProvider.retrieveAttributes(rolePrincipal);
+ roles.add(new RoleImpl(rolePrincipal, attributes));
}
return roles;
}
@@ -267,29 +187,22 @@
* @see org.apache.jetspeed.security.RoleManager#addRoleToUser(java.lang.String,
* java.lang.String)
*/
- public void addRoleToUser(String username, String roleFullPathName) throws SecurityException
+ public void addRoleToUser(String username, String roleName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { username, roleFullPathName }, new String[] { "username", "roleFullPathName" },
- "addUserToRole(java.lang.String, java.lang.String)");
-
- // Get the role principal to add to user.
- Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
+ Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleName);
if (null == rolePrincipal)
{
- throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
+ throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleName));
}
- // Check that user exists.
Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
if (null == userPrincipal)
{
throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
}
- // Get the user roles.
- Set rolePrincipals = securityMappingHandler.getRolePrincipals(username);
- // Add role to user.
+ Set<RolePrincipal> rolePrincipals = securityMappingHandler.getRolePrincipals(username);
if (!rolePrincipals.contains(rolePrincipal))
{
- securityMappingHandler.setUserPrincipalInRole(username, roleFullPathName);
+ securityMappingHandler.setUserPrincipalInRole(username, roleName);
}
}
@@ -297,22 +210,17 @@
* @see org.apache.jetspeed.security.RoleManager#removeRoleFromUser(java.lang.String,
* java.lang.String)
*/
- public void removeRoleFromUser(String username, String roleFullPathName) throws SecurityException
+ public void removeRoleFromUser(String username, String roleName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { username, roleFullPathName }, new String[] { "username", "roleFullPathName" },
- "removeRoleFromUser(java.lang.String, java.lang.String)");
-
- // Check that user exists.
Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
if (null == userPrincipal)
{
throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
}
- // Get the role principal to remove.
- Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
+ Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleName);
if (null != rolePrincipal)
{
- securityMappingHandler.removeUserPrincipalInRole(username, roleFullPathName);
+ securityMappingHandler.removeUserPrincipalInRole(username, roleName);
}
}
@@ -320,15 +228,11 @@
* @see org.apache.jetspeed.security.RoleManager#isUserInRole(java.lang.String,
* java.lang.String)
*/
- public boolean isUserInRole(String username, String roleFullPathName) throws SecurityException
+ public boolean isUserInRole(String username, String roleName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { username, roleFullPathName }, new String[] { "username", "roleFullPathName" },
- "isUserInRole(java.lang.String, java.lang.String)");
-
boolean isUserInRole = false;
-
- Set rolePrincipals = securityMappingHandler.getRolePrincipals(username);
- Principal rolePrincipal = new RolePrincipalImpl(roleFullPathName);
+ Set<RolePrincipal> rolePrincipals = securityMappingHandler.getRolePrincipals(username);
+ Principal rolePrincipal = new RolePrincipalImpl(roleName);
if (rolePrincipals.contains(rolePrincipal))
{
isUserInRole = true;
@@ -340,34 +244,26 @@
* @see org.apache.jetspeed.security.RoleManager#addRoleToGroup(java.lang.String,
* java.lang.String)
*/
- public void addRoleToGroup(String roleFullPathName, String groupFullPathName) throws SecurityException
+ public void addRoleToGroup(String roleName, String groupName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName, groupFullPathName }, new String[] { "roleFullPathName",
- "groupFullPathName" }, "addRoleToGroup(java.lang.String, java.lang.String)");
-
- // Get the role principal to add to group.
- Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
+ Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleName);
if (null == rolePrincipal)
{
- throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
+ throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleName));
}
- securityMappingHandler.setRolePrincipalInGroup(groupFullPathName, roleFullPathName);
+ securityMappingHandler.setRolePrincipalInGroup(groupName, roleName);
}
/**
* @see org.apache.jetspeed.security.RoleManager#removeRoleFromGroup(java.lang.String,
* java.lang.String)
*/
- public void removeRoleFromGroup(String roleFullPathName, String groupFullPathName) throws SecurityException
+ public void removeRoleFromGroup(String roleName, String groupName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName, groupFullPathName }, new String[] { "roleFullPathName",
- "groupFullPathName" }, "removeRoleFromGroup(java.lang.String, java.lang.String)");
-
- // Get the role principal to remove.
- Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleFullPathName);
+ Principal rolePrincipal = roleSecurityHandler.getRolePrincipal(roleName);
if (null != rolePrincipal)
{
- securityMappingHandler.removeRolePrincipalInGroup(groupFullPathName, roleFullPathName);
+ securityMappingHandler.removeRolePrincipalInGroup(groupName, roleName);
}
}
@@ -375,56 +271,48 @@
* @see org.apache.jetspeed.security.RoleManager#isGroupInRole(java.lang.String,
* java.lang.String)
*/
- public boolean isGroupInRole(String groupFullPathName, String roleFullPathName) throws SecurityException
+ public boolean isGroupInRole(String groupName, String roleName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName, groupFullPathName }, new String[] { "roleFullPathName",
- "groupFullPathName" }, "isGroupInRole(java.lang.String, java.lang.String)");
-
boolean isGroupInRole = false;
-
- Set rolePrincipals = securityMappingHandler.getRolePrincipalsInGroup(groupFullPathName);
- Principal rolePrincipal = new RolePrincipalImpl(roleFullPathName);
+ Set<RolePrincipal> rolePrincipals = securityMappingHandler.getRolePrincipalsInGroup(groupName);
+ Principal rolePrincipal = new RolePrincipalImpl(roleName);
if (rolePrincipals.contains(rolePrincipal))
{
isGroupInRole = true;
}
-
return isGroupInRole;
}
/**
* @see org.apache.jetspeed.security.RoleManager#getRoles(java.lang.String)
*/
- public Iterator getRoles(String filter) throws SecurityException
+ public Collection<Role> getRoles(String filter) throws SecurityException
{
- List roles = new LinkedList();
- Iterator rolePrincipals = roleSecurityHandler.getRolePrincipals(filter).iterator();
- while (rolePrincipals.hasNext())
+ List<Role> roles = new LinkedList<Role>();
+ Collection<RolePrincipal> rolePrincipals = roleSecurityHandler.getRolePrincipals(filter);
+ for (RolePrincipal principal : rolePrincipals)
{
- String roleName = ((Principal) rolePrincipals.next()).getName();
- Role role = getRole(roleName);
+ SecurityAttributes attributes = this.attributesProvider.retrieveAttributes(principal);
+ Role role = new RoleImpl(principal, attributes);
roles.add(role);
}
- return roles.iterator();
+ return roles;
}
/**
* @see org.apache.jetspeed.security.RoleManager#setRoleEnabled(java.lang.String, boolean)
*/
- public void setRoleEnabled(String roleFullPathName, boolean enabled) throws SecurityException
+ public void setRoleEnabled(String roleName, boolean enabled) throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName }, new String[] { "roleFullPathName" },
- "setRoleEnabled(java.lang.String,boolean)");
-
- RolePrincipalImpl rolePrincipal = (RolePrincipalImpl)roleSecurityHandler.getRolePrincipal(roleFullPathName);
+ RolePrincipalImpl rolePrincipal = (RolePrincipalImpl)roleSecurityHandler.getRolePrincipal(roleName);
if (null == rolePrincipal)
{
- throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleFullPathName));
+ throw new SecurityException(SecurityException.ROLE_DOES_NOT_EXIST.create(roleName));
}
if ( enabled != rolePrincipal.isEnabled() )
{
rolePrincipal.setEnabled(enabled);
- roleSecurityHandler.setRolePrincipal(rolePrincipal);
+ roleSecurityHandler.storeRolePrincipal(rolePrincipal);
}
}
}
\ No newline at end of file
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RolePrincipalImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RolePrincipalImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RolePrincipalImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RolePrincipalImpl.java Wed Aug 6 20:52:05 2008
@@ -29,29 +29,21 @@
/** The serial version uid. */
private static final long serialVersionUID = -3521731040045006314L;
- private static boolean hiearchicalNames = true;
-
- public static final Object useHierarchicalNames(boolean hierarchicalNames)
+ public RolePrincipalImpl(String name)
{
- RolePrincipalImpl.hiearchicalNames = hierarchicalNames;
- return null;
+ super(name);
}
-
- /**
- * <p>The role principal constructor.</p>
- * @param roleName The role principal name.
- */
- public RolePrincipalImpl(String roleName)
+
+ public RolePrincipalImpl(long id, String roleName)
{
- this(roleName, true, false);
+ this(id, roleName, true, false);
}
- public RolePrincipalImpl(String roleName, boolean isEnabled, boolean isMapping)
+ public RolePrincipalImpl(long id, String roleName, boolean isEnabled, boolean isMapping)
{
- super(roleName, PREFS_ROLE_ROOT, hiearchicalNames, isEnabled, isMapping);
+ super(id, roleName, isEnabled, isMapping);
}
-
/**
* <p>Compares this principal to the specified object. Returns true
* if the object passed in matches the principal represented by
@@ -69,32 +61,4 @@
RolePrincipalImpl principal = (RolePrincipalImpl) another;
return this.getName().equals(principal.getName());
}
-
- /**
- * <p>Gets the principal implementation full path from the principal name.</p>
- * <p>Prepends PREFS_ROLE_ROOT if not prepended.</p>
- * @param name The principal name.
- * @return The preferences full path / principal name.
- */
- public static String getFullPathFromPrincipalName(String name)
- {
- return BasePrincipalImpl.getFullPathFromPrincipalName(name, PREFS_ROLE_ROOT, hiearchicalNames);
- }
-
- /**
- * <p>Gets the principal name from the principal implementation full path.</p>
- * <p>Remove prepended PREFS_ROLE_ROOT if present.</p>
- * @param fullPath The principal full path.
- * @return The principal name.
- */
- public static String getPrincipalNameFromFullPath(String fullPath)
- {
- return BasePrincipalImpl.getPrincipalNameFromFullPath(fullPath, PREFS_ROLE_ROOT, hiearchicalNames);
- }
-
- public static String getFullPathFromPrincipalName(String name, String prefsRoot)
- {
- return BasePrincipalImpl.getFullPathFromPrincipalName(name, prefsRoot, hiearchicalNames);
- }
-
}
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserImpl.java Wed Aug 6 20:52:05 2008
@@ -16,20 +16,26 @@
*/
package org.apache.jetspeed.security.impl;
-import java.util.prefs.Preferences;
+import java.util.HashMap;
+import java.util.Map;
import javax.security.auth.Subject;
+import org.apache.jetspeed.security.SecurityHelper;
import org.apache.jetspeed.security.User;
+import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.jetspeed.security.attributes.SecurityAttribute;
+import org.apache.jetspeed.security.attributes.SecurityAttributes;
/**
- * <p>A user made of a {@link Subject} and the user {@link Preferences}.</p>
+ * <p>Represents a security 'user' made of a {@link org.apache.jetspeed.security.RolePrincipal} and security attributes.</p>
+ * <p>Modified 2008-08-05 - DST - decoupled java preferences</p>
* @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
*/
public class UserImpl implements User
{
private Subject subject;
- private Preferences preferences;
+ private SecurityAttributes attributes;
/**
* <p>Default constructor.</p>
@@ -39,14 +45,14 @@
}
/**
- * <p>{@link User} constructor given a subject and preferences.</p>
+ * <p>{@link User} constructor given a subject and security attributes.</p>
* @param subject The subject.
- * @param preferences The preferences.
+ * @param attributes The security attributes
*/
- public UserImpl(Subject subject, Preferences preferences)
+ public UserImpl(Subject subject, SecurityAttributes attributes)
{
this.subject = subject;
- this.preferences = preferences;
+ this.attributes = attributes;
}
/**
@@ -65,28 +71,30 @@
this.subject = subject;
}
- /**
- * @see org.apache.jetspeed.security.User#getPreferences()
- */
- public Preferences getPreferences()
+ public SecurityAttributes getAttributes()
{
- return preferences;
+ return this.attributes;
}
- /**
- * @see org.apache.jetspeed.security.User#setPreferences(java.util.prefs.Preferences)
- */
- public void setPreferences(Preferences preferences)
+ public void setAttributes(SecurityAttributes attributes)
{
- this.preferences = preferences;
+ this.attributes = attributes;
}
- public Preferences getUserAttributes()
+ public Map<String, String> getUserAttributes()
{
- if (preferences != null)
+ Map<String, String> userInfo = new HashMap<String, String>();
+ for (String key : this.attributes.getAttributes().keySet())
{
- return preferences.node(USER_INFO_PROPERTY_SET);
+ SecurityAttribute attr = this.attributes.getAttributes().get(key);
+ if (attr.getType().equals(SecurityAttributes.USER_INFORMATION))
+ userInfo.put(attr.getName(), attr.getValue());
}
- return null;
+ return userInfo;
+ }
+
+ public UserPrincipal getUserPrincipal()
+ {
+ return (UserPrincipal) SecurityHelper.getBestPrincipal(subject, UserPrincipal.class);
}
}
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java Wed Aug 6 20:52:05 2008
@@ -16,31 +16,30 @@
*/
package org.apache.jetspeed.security.impl;
-import java.security.Principal;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.Preferences;
import javax.security.auth.Subject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.security.AuthenticationProviderProxy;
+import org.apache.jetspeed.security.GroupPrincipal;
import org.apache.jetspeed.security.HierarchyResolver;
+import org.apache.jetspeed.security.RolePrincipal;
import org.apache.jetspeed.security.SecurityException;
import org.apache.jetspeed.security.SecurityProvider;
import org.apache.jetspeed.security.User;
import org.apache.jetspeed.security.UserManager;
import org.apache.jetspeed.security.UserPrincipal;
+import org.apache.jetspeed.security.attributes.SecurityAttributes;
+import org.apache.jetspeed.security.attributes.SecurityAttributesProvider;
import org.apache.jetspeed.security.spi.SecurityMappingHandler;
-import org.apache.jetspeed.util.ArgUtil;
/**
* <p>
@@ -52,15 +51,13 @@
*/
public class UserManagerImpl implements UserManager
{
-
private static final Log log = LogFactory.getLog(UserManagerImpl.class);
-
- /** The authenticatino provider proxy. */
+ /** The authentication provider proxy. */
private AuthenticationProviderProxy atnProviderProxy = null;
-
/** The security mapping handler. */
- private SecurityMappingHandler securityMappingHandler = null;
-
+ private SecurityMappingHandler securityMappingHandler = null;
+ /** Security Attributes persistence */
+ private SecurityAttributesProvider attributesProvider;
private String anonymousUser = "guest";
private User guest = null;
@@ -74,12 +71,11 @@
* @param securityProvider
* The security provider.
*/
- public UserManagerImpl(SecurityProvider securityProvider)
+ public UserManagerImpl(SecurityProvider securityProvider, SecurityAttributesProvider attributesProvider)
{
- this.atnProviderProxy = securityProvider
- .getAuthenticationProviderProxy();
- this.securityMappingHandler = securityProvider
- .getSecurityMappingHandler();
+ this.atnProviderProxy = securityProvider.getAuthenticationProviderProxy();
+ this.securityMappingHandler = securityProvider.getSecurityMappingHandler();
+ this.attributesProvider = attributesProvider;
}
/**
@@ -88,67 +84,38 @@
* @param anonymousUser
* The anonymous user name
*/
- public UserManagerImpl(SecurityProvider securityProvider,
- String anonymousUser)
+ public UserManagerImpl(SecurityProvider securityProvider, SecurityAttributesProvider attributesProvider, String anonymousUser)
{
- this.atnProviderProxy = securityProvider
- .getAuthenticationProviderProxy();
- this.securityMappingHandler = securityProvider
- .getSecurityMappingHandler();
- if (anonymousUser != null)
- {
- this.anonymousUser = anonymousUser;
- }
+ this(securityProvider, attributesProvider);
+ this.anonymousUser = anonymousUser;
}
/**
* @param securityProvider
* The security provider.
- * @param roleHierarchyResolver
- * The role hierachy resolver.
- * @param groupHierarchyResolver
- * The group hierarchy resolver.
- */
- public UserManagerImpl(SecurityProvider securityProvider,
- HierarchyResolver roleHierarchyResolver,
- HierarchyResolver groupHierarchyResolver)
- {
- securityProvider.getSecurityMappingHandler().setRoleHierarchyResolver(
- roleHierarchyResolver);
- securityProvider.getSecurityMappingHandler().setGroupHierarchyResolver(
- groupHierarchyResolver);
- this.atnProviderProxy = securityProvider
- .getAuthenticationProviderProxy();
- this.securityMappingHandler = securityProvider
- .getSecurityMappingHandler();
+ * @param hierarchyResolver
+ * The hierarchy resolver.
+ */
+ public UserManagerImpl(SecurityProvider securityProvider, SecurityAttributesProvider attributesProvider,
+ HierarchyResolver hierarchyResolver)
+ {
+ this(securityProvider, attributesProvider);
+ securityProvider.getSecurityMappingHandler().setHierarchyResolver(hierarchyResolver);
}
/**
* @param securityProvider
* The security provider.
- * @param roleHierarchyResolver
- * The role hierachy resolver.
- * @param groupHierarchyResolver
- * The group hierarchy resolver.
+ * @param hierarchyResolver
+ * The hierarchy resolver.
* @param anonymousUser
* The anonymous user name
*/
- public UserManagerImpl(SecurityProvider securityProvider,
- HierarchyResolver roleHierarchyResolver,
- HierarchyResolver groupHierarchyResolver, String anonymousUser)
- {
- securityProvider.getSecurityMappingHandler().setRoleHierarchyResolver(
- roleHierarchyResolver);
- securityProvider.getSecurityMappingHandler().setGroupHierarchyResolver(
- groupHierarchyResolver);
- this.atnProviderProxy = securityProvider
- .getAuthenticationProviderProxy();
- this.securityMappingHandler = securityProvider
- .getSecurityMappingHandler();
- if (anonymousUser != null)
- {
- this.anonymousUser = anonymousUser;
- }
+ public UserManagerImpl(SecurityProvider securityProvider, SecurityAttributesProvider attributesProvider,
+ HierarchyResolver hierarchyResolver, String anonymousUser)
+ {
+ this(securityProvider, attributesProvider, anonymousUser);
+ securityProvider.getSecurityMappingHandler().setHierarchyResolver(hierarchyResolver);
}
/*
@@ -172,24 +139,19 @@
*/
public boolean authenticate(String username, String password)
{
- ArgUtil.notNull(new Object[]
- { username, password}, new String[]
- { "username", "password"},
- "authenticate(java.lang.String, java.lang.String)");
-
boolean authenticated = false;
try
{
if (!getAnonymousUser().equals(username))
{
- authenticated = atnProviderProxy.authenticate(username,
- password);
+ authenticated = atnProviderProxy.authenticate(username, password);
if (authenticated && log.isDebugEnabled())
{
log.debug("Authenticated user: " + username);
}
}
- } catch (SecurityException e)
+ }
+ catch (SecurityException e)
{
// ignore: not authenticated
}
@@ -203,10 +165,6 @@
public void addUser(String username, String password)
throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { username}, new String[]
- { "username"}, "addUser(java.lang.String, java.lang.String)");
-
createUser(username, password, atnProviderProxy
.getDefaultAuthenticationProvider(),false);
}
@@ -220,10 +178,6 @@
public void addUser(String username, String password, String atnProviderName)
throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { username}, new String[]
- { "username"}, "addUser(java.lang.String, java.lang.String)");
-
createUser(username, password, atnProviderName, false);
}
@@ -234,10 +188,6 @@
public void importUser(String username, String password, boolean passThrough)
throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { username}, new String[]
- { "username"}, "addUser(java.lang.String, java.lang.String)");
-
createUser(username, password, atnProviderProxy
.getDefaultAuthenticationProvider(),passThrough);
}
@@ -249,94 +199,33 @@
public void importUser(String username, String password, String atnProviderName, boolean passThrough)
throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { username}, new String[]
- { "username"}, "addUser(java.lang.String, java.lang.String)");
-
- createUser(username, password, atnProviderName,passThrough);
+ createUser(username, password, atnProviderName, passThrough);
}
/**
* @see org.apache.jetspeed.security.UserManager#addUser(java.lang.String,
* java.lang.String, java.lang.String)
*/
- protected void createUser(String username, String password, String atnProviderName, boolean raw)
+ protected void createUser(String userName, String password, String atnProviderName, boolean raw)
throws SecurityException
{
- ArgUtil
- .notNull(new Object[]
- { username, atnProviderName}, new String[]
- { "username", "atnProviderName"},
- "addUser(java.lang.String, java.lang.String, java.lang.String)");
-
-// if (getAnonymousUser().equals(username)) { throw new SecurityException(
-// SecurityException.ANONYMOUS_USER_PROTECTED.create(username)); }
-
- // Check if user already exists.
- if (userExists(username)) {
- throw new SecurityException(SecurityException.USER_ALREADY_EXISTS.create(username));
+ if (userExists(userName))
+ {
+ throw new SecurityException(SecurityException.USER_ALREADY_EXISTS.create(userName));
}
-
- UserPrincipal userPrincipal = new UserPrincipalImpl(username);
- String fullPath = userPrincipal.getFullPath();
- // Add the preferences.
- Preferences preferences = Preferences.userRoot().node(fullPath);
+ UserPrincipal userPrincipal = new UserPrincipalImpl(userName);
+ atnProviderProxy.addUserPrincipal(userPrincipal);
+ if (password != null)
+ {
+ if (raw)
+ atnProviderProxy.importPassword(userName, password, atnProviderName);
+ else
+ atnProviderProxy.setPassword(userName, null, password, atnProviderName);
+ }
+ SecurityAttributes sa = attributesProvider.createSecurityAttributes(userPrincipal);
+ attributesProvider.saveAttributes(sa);
if (log.isDebugEnabled())
- {
- log.debug("Added user preferences node: " + fullPath);
- }
- try
- {
- if ((null != preferences)
- && preferences.absolutePath().equals(fullPath))
- {
- // Add user principal.
- atnProviderProxy.addUserPrincipal(userPrincipal);
- if (password != null)
- {
- try
- {
- // Set private password credential
- if (raw)
- atnProviderProxy.importPassword(username, password,atnProviderName);
- else
- atnProviderProxy.setPassword(username, null, password,atnProviderName);
- }
- catch (SecurityException se1)
- {
- try
- {
- // rollback created user
- atnProviderProxy.removeUserPrincipal(userPrincipal);
- }
- catch (SecurityException se2)
- {
- log.error("Failed to rollback created user after its password turned out to be invalid", se2);
- }
- throw se1;
- }
- }
- if (log.isDebugEnabled())
- {
- log.debug("Added user: " + fullPath);
- }
- }
- } catch (SecurityException se)
- {
- log.error(se.getMessage(), se);
-
- // Remove the preferences node.
- try
- {
- preferences.removeNode();
- } catch (BackingStoreException bse)
- {
- bse.printStackTrace();
- }
- throw se;
- }
- }
-
-
+ log.debug("Added user: " + userName);
+ }
/**
* @see org.apache.jetspeed.security.UserManager#removeUser(java.lang.String)
@@ -345,24 +234,15 @@
*/
public void removeUser(String username) throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { username}, new String[]
- { "username"}, "removeUser(java.lang.String)");
-
- if (getAnonymousUser().equals(username)) { throw new SecurityException(
- SecurityException.ANONYMOUS_USER_PROTECTED.create(username)); }
+ if (getAnonymousUser().equals(username))
+ {
+ throw new SecurityException(
+ SecurityException.ANONYMOUS_USER_PROTECTED.create(username));
+ }
UserPrincipal userPrincipal = new UserPrincipalImpl(username);
- String fullPath = userPrincipal.getFullPath();
atnProviderProxy.removeUserPrincipal(userPrincipal);
- // Remove preferences
- Preferences preferences = Preferences.userRoot().node(fullPath);
- try
- {
- preferences.removeNode();
- } catch (BackingStoreException bse)
- {
- bse.printStackTrace();
- }
+// TODO: should we use cascading deletes?
+ attributesProvider.deleteAttributes(userPrincipal);
}
/**
@@ -370,10 +250,6 @@
*/
public boolean userExists(String username)
{
- ArgUtil.notNull(new Object[]
- { username}, new String[]
- { "username"}, "userExists(java.lang.String)");
-
return atnProviderProxy.getUserPrincipal(username) != null;
}
@@ -381,54 +257,50 @@
* @see org.apache.jetspeed.security.UserManager#getUser(java.lang.String)
*/
public User getUser(String username) throws SecurityException
- {
- ArgUtil.notNull(new Object[]
- { username}, new String[]
- { "username"}, "getUser(java.lang.String)");
-
+ {
// optimize guest lookups as they can be excessive
if (guest != null && getAnonymousUser().equals(username))
{
// TODO: need to handle caching issues
return guest;
- }
-
- Set principals = new PrincipalsSet();
- String fullPath = (new UserPrincipalImpl(username)).getFullPath();
-
- Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
- if (null == userPrincipal) {
+ }
+ UserPrincipal userPrincipal = atnProviderProxy.getUserPrincipal(username);
+ if (null == userPrincipal)
+ {
throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(username));
}
-
+ return constructUser(userPrincipal);
+ }
+
+ private User constructUser(UserPrincipal userPrincipal) throws SecurityException
+ {
+ String username = userPrincipal.getName();
+ PrincipalsSet principals = new PrincipalsSet();
principals.add(userPrincipal);
principals.addAll(securityMappingHandler.getRolePrincipals(username));
- Set groupPrincipals = securityMappingHandler.getGroupPrincipals(username);
- principals.addAll(groupPrincipals);
-
+ Set<GroupPrincipal> groupPrincipals = securityMappingHandler.getGroupPrincipals(username);
+ principals.addAll(groupPrincipals);
if (this.rolesInheritableViaGroups)
{
- for (Iterator it = groupPrincipals.iterator(); it.hasNext(); )
+ for (GroupPrincipal groupPrincipal : groupPrincipals)
{
- Principal groupPrincipal = (Principal) it.next();
- Set rolePrincipalsInGroup = securityMappingHandler.getRolePrincipalsInGroup(groupPrincipal.getName());
+ Set<RolePrincipal> rolePrincipalsInGroup = securityMappingHandler.getRolePrincipalsInGroup(groupPrincipal.getName());
principals.addAll(rolePrincipalsInGroup);
}
}
-
Subject subject = null;
if (getAnonymousUser().equals(username))
{
- subject = new Subject(true, principals, new HashSet(),
- new HashSet());
- } else
- {
- subject = new Subject(true, principals, atnProviderProxy
- .getPublicCredentials(username), atnProviderProxy
- .getPrivateCredentials(username));
+ subject = new Subject(true, principals, new HashSet(), new HashSet());
+ }
+ else
+ {
+ subject = new Subject(true, principals,
+ atnProviderProxy.getPublicCredentials(username),
+ atnProviderProxy.getPrivateCredentials(username));
}
- Preferences preferences = Preferences.userRoot().node(fullPath);
- User user = new UserImpl(subject, preferences);
+ SecurityAttributes attributes = attributesProvider.retrieveAttributes(userPrincipal);
+ User user = new UserImpl(subject, attributes);
if (getAnonymousUser().equals(username))
{
guest = user;
@@ -439,53 +311,40 @@
/**
* @see org.apache.jetspeed.security.UserManager#getUsers(java.lang.String)
*/
- public Iterator getUsers(String filter) throws SecurityException
+ public Collection<User> getUsers(String filter) throws SecurityException
{
- List users = new LinkedList();
- Iterator userPrincipals = atnProviderProxy.getUserPrincipals(filter)
- .iterator();
- while (userPrincipals.hasNext())
+ List<User> users = new LinkedList<User>();
+ for (UserPrincipal userPrincipal : atnProviderProxy.getUserPrincipals(filter))
{
- String username = ((Principal) userPrincipals.next()).getName();
- User user = getUser(username);
+ User user = constructUser(userPrincipal);
users.add(user);
}
- return users.iterator();
+ return users;
}
/**
* @see org.apache.jetspeed.security.UserManager#getUserNames(java.lang.String)
*/
- public Iterator getUserNames(String filter) throws SecurityException
+ public List<String> getUserNames(String filter) throws SecurityException
{
- List usernames = new LinkedList();
- Iterator userPrincipals = atnProviderProxy.getUserPrincipals(filter).iterator();
- while (userPrincipals.hasNext())
+ List<String> usernames = new LinkedList<String>();
+ for (UserPrincipal userPrincipal : atnProviderProxy.getUserPrincipals(filter))
{
- usernames.add(((Principal) userPrincipals.next()).getName());
+ usernames.add(userPrincipal.getName());
}
- return usernames.iterator();
+ return usernames;
}
/**
* @see org.apache.jetspeed.security.UserManager#getUsersInRole(java.lang.String)
*/
- public Collection getUsersInRole(String roleFullPathName)
+ public Collection<User> getUsersInRole(String roleName)
throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { roleFullPathName}, new String[]
- { "roleFullPathName"}, "getUsersInRole(java.lang.String)");
-
- Collection users = new ArrayList();
-
- Set userPrincipals = securityMappingHandler
- .getUserPrincipalsInRole(roleFullPathName);
- Iterator userPrincipalsIter = userPrincipals.iterator();
- while (userPrincipalsIter.hasNext())
+ Collection<User> users = new ArrayList<User>();
+ for (UserPrincipal userPrincipal : securityMappingHandler.getUserPrincipalsInRole(roleName))
{
- Principal userPrincipal = (Principal) userPrincipalsIter.next();
- users.add(getUser(userPrincipal.getName()));
+ users.add(constructUser(userPrincipal));
}
return users;
}
@@ -493,22 +352,13 @@
/**
* @see org.apache.jetspeed.security.UserManager#getUsersInGroup(java.lang.String)
*/
- public Collection getUsersInGroup(String groupFullPathName)
+ public Collection<User> getUsersInGroup(String groupFullPathName)
throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { groupFullPathName}, new String[]
- { "groupFullPathName"}, "getUsersInGroup(java.lang.String)");
-
- Collection users = new ArrayList();
-
- Set userPrincipals = securityMappingHandler
- .getUserPrincipalsInGroup(groupFullPathName);
- Iterator userPrincipalsIter = userPrincipals.iterator();
- while (userPrincipalsIter.hasNext())
+ Collection<User> users = new ArrayList<User>();
+ for (UserPrincipal userPrincipal : securityMappingHandler.getUserPrincipalsInGroup(groupFullPathName))
{
- Principal userPrincipal = (Principal) userPrincipalsIter.next();
- users.add(getUser(userPrincipal.getName()));
+ users.add(constructUser(userPrincipal));
}
return users;
}
@@ -522,14 +372,11 @@
public void setPassword(String username, String oldPassword,
String newPassword) throws SecurityException
{
- ArgUtil
- .notNull(new Object[]
- { username, newPassword}, new String[]
- { "username", "newPassword"},
- "setPassword(java.lang.String, java.lang.String, java.lang.String)");
-
- if (getAnonymousUser().equals(username)) { throw new SecurityException(
- SecurityException.ANONYMOUS_USER_PROTECTED.create(username)); }
+ if (getAnonymousUser().equals(username))
+ {
+ throw new SecurityException(
+ SecurityException.ANONYMOUS_USER_PROTECTED.create(username));
+ }
atnProviderProxy.setPassword(username, oldPassword, newPassword);
}
@@ -540,12 +387,11 @@
public void setPasswordEnabled(String userName, boolean enabled)
throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { userName,}, new String[]
- { "userName"}, "setPasswordEnabled(java.lang.String, boolean)");
-
- if (getAnonymousUser().equals(userName)) { throw new SecurityException(
- SecurityException.ANONYMOUS_USER_PROTECTED.create(userName)); }
+ if (getAnonymousUser().equals(userName))
+ {
+ throw new SecurityException(
+ SecurityException.ANONYMOUS_USER_PROTECTED.create(userName));
+ }
atnProviderProxy.setPasswordEnabled(userName, enabled);
}
@@ -556,12 +402,11 @@
public void setPasswordUpdateRequired(String userName,
boolean updateRequired) throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { userName,}, new String[]
- { "userName"}, "setPasswordUpdateRequired(java.lang.String, boolean)");
-
- if (getAnonymousUser().equals(userName)) { throw new SecurityException(
- SecurityException.ANONYMOUS_USER_PROTECTED.create(userName)); }
+ if (getAnonymousUser().equals(userName))
+ {
+ throw new SecurityException(
+ SecurityException.ANONYMOUS_USER_PROTECTED.create(userName));
+ }
atnProviderProxy.setPasswordUpdateRequired(userName, updateRequired);
}
@@ -571,14 +416,10 @@
*/
public void setUserEnabled(String userName, boolean enabled) throws SecurityException
{
- ArgUtil.notNull(new Object[] { userName, }, new String[] { "userName" },
- "setUserEnabled(java.lang.String, boolean)");
-
if (getAnonymousUser().equals(userName))
{
throw new SecurityException(SecurityException.ANONYMOUS_USER_PROTECTED.create(userName));
}
-
UserPrincipalImpl userPrincipal = (UserPrincipalImpl)atnProviderProxy.getUserPrincipal(userName);
if (null == userPrincipal)
{
@@ -596,14 +437,35 @@
*/
public void setPasswordExpiration(String userName, Date expirationDate) throws SecurityException
{
- ArgUtil.notNull(new Object[]
- { userName,}, new String[]
- { "userName"}, "setPasswordExpiration(java.lang.String, java.sql.Date)");
-
if (getAnonymousUser().equals(userName))
{
throw new SecurityException(SecurityException.ANONYMOUS_USER_PROTECTED.create(userName));
}
atnProviderProxy.setPasswordExpiration(userName, expirationDate);
}
+
+ public void updateUser(User user) throws SecurityException
+ {
+ UserPrincipal userPrincipal = user.getUserPrincipal();
+ atnProviderProxy.updateUserPrincipal(userPrincipal);
+ this.attributesProvider.saveAttributes(user.getAttributes());
+ }
+
+ public Collection<User> lookupUsers(String name, String value) throws SecurityException
+ {
+ Collection<User> resultSet = new LinkedList<User>();
+ Collection<SecurityAttributes> attributes = this.attributesProvider.lookupAttributes(name, value);
+ for (SecurityAttributes sa : attributes)
+ {
+ if (sa.getPrincipal() instanceof UserPrincipal)
+ {
+ User user = this.getUser(sa.getPrincipal().getName());
+ if (user != null)
+ {
+ resultSet.add(user);
+ }
+ }
+ }
+ return resultSet;
+ }
}
\ No newline at end of file
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserPrincipalImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserPrincipalImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserPrincipalImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserPrincipalImpl.java Wed Aug 6 20:52:05 2008
@@ -25,36 +25,22 @@
*/
public class UserPrincipalImpl extends BasePrincipalImpl implements UserPrincipal
{
-
/** The serial version uid. */
private static final long serialVersionUID = 4134905654850335230L;
-
- private static boolean hiearchicalNames = true;
-
- public static final Object useHierarchicalNames(boolean hierarchicalNames)
- {
- UserPrincipalImpl.hiearchicalNames = hierarchicalNames;
- return null;
- }
-
- /**
- * <p>The user principal constructor.</p>
- * @param userName The user principal name.
- */
public UserPrincipalImpl(String userName)
{
- this(userName, true, false);
+ super(userName);
}
-
- public UserPrincipalImpl(String userName, boolean isMapping)
+
+ public UserPrincipalImpl(long id, String userName)
{
- this(userName, true, isMapping);
+ this(id, userName, true, false);
}
-
- public UserPrincipalImpl(String userName, boolean isEnabled, boolean isMapping)
+
+ public UserPrincipalImpl(long id, String userName, boolean isEnabled, boolean isMapping)
{
- super(userName, PREFS_USER_ROOT, hiearchicalNames, isEnabled, isMapping);
+ super(id, userName, isEnabled, isMapping);
}
/**
@@ -74,31 +60,4 @@
return this.getName().equals(principal.getName());
}
- /**
- * <p>Gets the principal implementation full path from the principal name.</p>
- * <p>Prepends PREFS_USER_ROOT if not prepended.</p>
- * @param name The principal name.
- * @return The preferences full path / principal name.
- */
- public static String getFullPathFromPrincipalName(String name)
- {
- return BasePrincipalImpl.getFullPathFromPrincipalName(name, PREFS_USER_ROOT, hiearchicalNames);
- }
-
- /**
- * <p>Gets the principal name from the principal implementation full path.</p>
- * <p>Remove prepended PREFS_GROUP_ROOT if present.</p>
- * @param fullPath The principal full path.
- * @return The principal name.
- */
- public static String getPrincipalNameFromFullPath(String fullPath)
- {
- return BasePrincipalImpl.getPrincipalNameFromFullPath(fullPath, PREFS_USER_ROOT, hiearchicalNames);
- }
-
- public static String getFullPathFromPrincipalName(String name, String prefsRoot)
- {
- return BasePrincipalImpl.getFullPathFromPrincipalName(name, prefsRoot, hiearchicalNames);
- }
-
}
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalGroupPrincipalImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalGroupPrincipalImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalGroupPrincipalImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalGroupPrincipalImpl.java Wed Aug 6 20:52:05 2008
@@ -20,6 +20,8 @@
import java.util.Collection;
import org.apache.jetspeed.security.om.InternalGroupPrincipal;
+import org.apache.jetspeed.security.om.InternalRolePrincipal;
+import org.apache.jetspeed.security.om.InternalUserPrincipal;
/**
* <p>{@link InternalGroupPrincipal} interface implementation.</p>
@@ -29,11 +31,13 @@
public class InternalGroupPrincipalImpl extends InternalPrincipalImpl implements InternalGroupPrincipal
{
/** The serial version uid. */
- private static final long serialVersionUID = -8236429453373927824L;
-
+ private static final long serialVersionUID = -8236429453373927824L;
/** <p>Group principal security class.</p> */
static String GROUP_PRINCIPAL_CLASSNAME = "org.apache.jetspeed.security.InternalGroupPrincipalImpl";
+ private Collection<InternalUserPrincipal> userPrincipals;
+ private Collection<InternalRolePrincipal> rolePrincipals;
+
/**
* <p>Group principal implementation default constructor.</p>
*/
@@ -44,20 +48,19 @@
/**
* <p>Constructor to create a new group principal.</p>
- * @param fullPath The group full path.
+ * @param name The group principal name
*/
- public InternalGroupPrincipalImpl(String fullPath)
+ public InternalGroupPrincipalImpl(String name)
{
- super(GROUP_PRINCIPAL_CLASSNAME, fullPath);
+ super(GROUP_PRINCIPAL_CLASSNAME, GROUP_TYPE, name);
this.rolePrincipals = new ArrayList();
}
- private Collection userPrincipals;
/**
* @see org.apache.jetspeed.security.om.InternalGroupPrincipal#getUserPrincipals()
*/
- public Collection getUserPrincipals()
+ public Collection<InternalUserPrincipal> getUserPrincipals()
{
return this.userPrincipals;
}
@@ -65,17 +68,15 @@
/**
* @see org.apache.jetspeed.security.om.InternalGroupPrincipal#setUserPrincipals(java.util.Collection)
*/
- public void setUserPrincipals(Collection userPrincipals)
+ public void setUserPrincipals(Collection<InternalUserPrincipal> userPrincipals)
{
this.userPrincipals = userPrincipals;
}
- private Collection rolePrincipals;
-
/**
* @see org.apache.jetspeed.security.om.InternalGroupPrincipal#getRolePrincipals()
*/
- public Collection getRolePrincipals()
+ public Collection<InternalRolePrincipal> getRolePrincipals()
{
return this.rolePrincipals;
}
@@ -83,7 +84,7 @@
/**
* @see org.apache.jetspeed.security.om.InternalGroupPrincipal#setRolePrincipals(java.util.Collection)
*/
- public void setRolePrincipals(Collection rolePrincipals)
+ public void setRolePrincipals(Collection<InternalRolePrincipal> rolePrincipals)
{
this.rolePrincipals = rolePrincipals;
}
@@ -99,7 +100,7 @@
return false;
InternalGroupPrincipal r = (InternalGroupPrincipal) object;
- boolean isEqual = (r.getFullPath().equals(this.getFullPath()));
+ boolean isEqual = (r.getName().equals(this.getName()) && r.getType().equals(this.getType()));
return isEqual;
}
}
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalPrincipalImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalPrincipalImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalPrincipalImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalPrincipalImpl.java Wed Aug 6 20:52:05 2008
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Collection;
+import org.apache.jetspeed.security.om.InternalPermission;
import org.apache.jetspeed.security.om.InternalPrincipal;
/**
@@ -43,11 +44,14 @@
/** The is mapping only. */
private boolean isMappingOnly = false;
- /** The full path. */
- private String fullPath;
+ /** The principal type such as user | group | role */
+ private String type;
+
+ /** The name of the principal */
+ private String name;
/** The collection of permissions. */
- private Collection permissions;
+ private Collection<InternalPermission> permissions;
/** The creation date. */
private Timestamp creationDate;
@@ -85,12 +89,13 @@
* @param classname The classname.
* @param fullPath The full path.
*/
- public InternalPrincipalImpl(String classname, String fullPath)
+ public InternalPrincipalImpl(String classname, String type, String name)
{
this.ojbConcreteClass = classname;
this.classname = classname;
- this.fullPath = fullPath;
- this.permissions = new ArrayList();
+ this.type = type;
+ this.name = name;
+ this.permissions = new ArrayList<InternalPermission>();
this.creationDate = new Timestamp(System.currentTimeMillis());
this.modifiedDate = this.creationDate;
}
@@ -145,25 +150,41 @@
}
/**
- * @see org.apache.jetspeed.security.om.InternalPrincipal#getFullPath()
+ * @see org.apache.jetspeed.security.om.InternalPrincipal#getType()
+ */
+ public String getType()
+ {
+ return this.type;
+ }
+
+ /**
+ * @see org.apache.jetspeed.security.om.InternalPrincipal#setType(java.lang.String)
*/
- public String getFullPath()
+ public void setType(String type)
{
- return this.fullPath;
+ this.type = type;
}
/**
- * @see org.apache.jetspeed.security.om.InternalPrincipal#setFullPath(java.lang.String)
+ * @see org.apache.jetspeed.security.om.InternalPrincipal#getName()
*/
- public void setFullPath(String fullPath)
+ public String getName()
{
- this.fullPath = fullPath;
+ return this.name;
}
/**
+ * @see org.apache.jetspeed.security.om.InternalPrincipal#setName(java.lang.String)
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
* @see org.apache.jetspeed.security.om.InternalPrincipal#getPermissions()
*/
- public Collection getPermissions()
+ public Collection<InternalPermission> getPermissions()
{
return this.permissions;
}
@@ -171,7 +192,7 @@
/**
* @see org.apache.jetspeed.security.om.InternalPrincipal#setPermissions(java.util.Collection)
*/
- public void setPermissions(Collection permissions)
+ public void setPermissions(Collection<InternalPermission> permissions)
{
this.permissions = permissions;
}
@@ -222,5 +243,10 @@
public void setEnabled(boolean enabled)
{
this.enabled = enabled;
- }
+ }
+
+ public String getFullPath() // TODO: remove this
+ {
+ return "";
+ }
}
\ No newline at end of file
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalRolePrincipalImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalRolePrincipalImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalRolePrincipalImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalRolePrincipalImpl.java Wed Aug 6 20:52:05 2008
@@ -18,7 +18,9 @@
import java.util.Collection;
+import org.apache.jetspeed.security.om.InternalGroupPrincipal;
import org.apache.jetspeed.security.om.InternalRolePrincipal;
+import org.apache.jetspeed.security.om.InternalUserPrincipal;
/**
* <p>{@link InternalRolePrincipal} interface implementation.</p>
@@ -28,11 +30,13 @@
public class InternalRolePrincipalImpl extends InternalPrincipalImpl implements InternalRolePrincipal
{
/** The serial version uid. */
- private static final long serialVersionUID = 4422827842052325846L;
-
+ private static final long serialVersionUID = 4422827842052325846L;
/** <p>Role principal security class.</p> */
static String ROLE_PRINCIPAL_CLASSNAME = "org.apache.jetspeed.security.InternalRolePrincipalImpl";
+ private Collection<InternalGroupPrincipal> groupPrincipals;
+ private Collection<InternalUserPrincipal> userPrincipals;
+
/**
* <p>Role principal implementation default constructor.</p>
*/
@@ -43,19 +47,17 @@
/**
* <p>Constructor to create a new role principal.</p>
- * @param fullPath The role full path.
+ * @param name The role principal name
*/
- public InternalRolePrincipalImpl(String fullPath)
+ public InternalRolePrincipalImpl(String name)
{
- super(ROLE_PRINCIPAL_CLASSNAME, fullPath);
+ super(ROLE_PRINCIPAL_CLASSNAME, ROLE_TYPE, name);
}
- private Collection userPrincipals;
-
/**
* @see org.apache.jetspeed.security.om.InternalRolePrincipal#getUserPrincipals()
*/
- public Collection getUserPrincipals()
+ public Collection<InternalUserPrincipal> getUserPrincipals()
{
return this.userPrincipals;
}
@@ -63,17 +65,16 @@
/**
* @see org.apache.jetspeed.security.om.InternalRolePrincipal#setUserPrincipals(java.util.Collection)
*/
- public void setUserPrincipals(Collection userPrincipals)
+ public void setUserPrincipals(Collection<InternalUserPrincipal> userPrincipals)
{
this.userPrincipals = userPrincipals;
}
- private Collection groupPrincipals;
/**
* @see org.apache.jetspeed.security.om.InternalRolePrincipal#getGroupPrincipals()
*/
- public Collection getGroupPrincipals()
+ public Collection<InternalGroupPrincipal> getGroupPrincipals()
{
return this.groupPrincipals;
}
@@ -81,7 +82,7 @@
/**
* @see org.apache.jetspeed.security.om.InternalRolePrincipal#setGroupPrincipals(java.util.Collection)
*/
- public void setGroupPrincipals(Collection groupPrincipals)
+ public void setGroupPrincipals(Collection<InternalGroupPrincipal> groupPrincipals)
{
this.groupPrincipals = groupPrincipals;
}
@@ -97,7 +98,7 @@
return false;
InternalRolePrincipal r = (InternalRolePrincipal) object;
- boolean isEqual = (r.getFullPath().equals(this.getFullPath()));
+ boolean isEqual = (r.getName().equals(this.getName()) && r.getType().equals(this.getType()));
return isEqual;
}
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalUserPrincipalImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalUserPrincipalImpl.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalUserPrincipalImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/om/impl/InternalUserPrincipalImpl.java Wed Aug 6 20:52:05 2008
@@ -19,6 +19,9 @@
import java.util.ArrayList;
import java.util.Collection;
+import org.apache.jetspeed.security.om.InternalCredential;
+import org.apache.jetspeed.security.om.InternalGroupPrincipal;
+import org.apache.jetspeed.security.om.InternalRolePrincipal;
import org.apache.jetspeed.security.om.InternalUserPrincipal;
/**
@@ -35,14 +38,14 @@
static String USER_PRINCIPAL_CLASSNAME = "org.apache.jetspeed.security.InternalUserPrincipalImpl";
/** The credentials. */
- private Collection credentials;
+ private Collection<InternalCredential> credentials;
/** The role principals. */
- private Collection rolePrincipals;
+ private Collection<InternalRolePrincipal> rolePrincipals;
/** The group principals. */
- private Collection groupPrincipals;
-
+ private Collection<InternalGroupPrincipal> groupPrincipals;
+
/**
* <p>InternalUserPrincipal implementation default constructor.</p>
*/
@@ -58,15 +61,15 @@
*/
public InternalUserPrincipalImpl(String username)
{
- super(USER_PRINCIPAL_CLASSNAME, username);
- this.rolePrincipals = new ArrayList();
- this.groupPrincipals = new ArrayList();
+ super(USER_PRINCIPAL_CLASSNAME, USER_TYPE, username);
+ this.rolePrincipals = new ArrayList<InternalRolePrincipal>();
+ this.groupPrincipals = new ArrayList<InternalGroupPrincipal>();
}
/**
* @see org.apache.jetspeed.security.om.InternalUserPrincipal#getCredentials()
*/
- public Collection getCredentials()
+ public Collection<InternalCredential> getCredentials()
{
return this.credentials;
}
@@ -74,7 +77,7 @@
/**
* @see org.apache.jetspeed.security.om.InternalUserPrincipal#setCredentials(java.util.Collection)
*/
- public void setCredentials(Collection credentials)
+ public void setCredentials(Collection<InternalCredential> credentials)
{
this.credentials = credentials;
}
@@ -82,7 +85,7 @@
/**
* @see org.apache.jetspeed.security.om.InternalUserPrincipal#getRolePrincipals()
*/
- public Collection getRolePrincipals()
+ public Collection<InternalRolePrincipal> getRolePrincipals()
{
return this.rolePrincipals;
}
@@ -90,7 +93,7 @@
/**
* @see org.apache.jetspeed.security.om.InternalUserPrincipal#setRolePrincipals(java.util.Collection)
*/
- public void setRolePrincipals(Collection rolePrincipals)
+ public void setRolePrincipals(Collection<InternalRolePrincipal> rolePrincipals)
{
this.rolePrincipals = rolePrincipals;
}
@@ -98,7 +101,7 @@
/**
* @see org.apache.jetspeed.security.om.InternalUserPrincipal#getGroupPrincipals()
*/
- public Collection getGroupPrincipals()
+ public Collection<InternalGroupPrincipal> getGroupPrincipals()
{
return this.groupPrincipals;
}
@@ -106,7 +109,7 @@
/**
* @see org.apache.jetspeed.security.om.InternalUserPrincipal#setGroupPrincipals(java.util.Collection)
*/
- public void setGroupPrincipals(Collection groupPrincipals)
+ public void setGroupPrincipals(Collection<InternalGroupPrincipal> groupPrincipals)
{
this.groupPrincipals = groupPrincipals;
}
@@ -122,7 +125,7 @@
return false;
InternalUserPrincipal r = (InternalUserPrincipal) object;
- boolean isEqual = (r.getFullPath().equals(this.getFullPath()));
+ boolean isEqual = (r.getName().equals(this.getName()) && r.getType().equals(this.getType()));
return isEqual;
}
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultCredentialHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultCredentialHandler.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultCredentialHandler.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultCredentialHandler.java Wed Aug 6 20:52:05 2008
@@ -27,6 +27,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.security.AlgorithmUpgradePasswordEncodingService;
+import org.apache.jetspeed.security.Credential;
import org.apache.jetspeed.security.InvalidNewPasswordException;
import org.apache.jetspeed.security.InvalidPasswordException;
import org.apache.jetspeed.security.PasswordAlreadyUsedException;
@@ -34,8 +35,8 @@
import org.apache.jetspeed.security.om.InternalCredential;
import org.apache.jetspeed.security.om.InternalUserPrincipal;
import org.apache.jetspeed.security.om.impl.InternalCredentialImpl;
-import org.apache.jetspeed.security.spi.CredentialHandler;
import org.apache.jetspeed.security.spi.AlgorithmUpgradeCredentialPasswordEncoder;
+import org.apache.jetspeed.security.spi.CredentialHandler;
import org.apache.jetspeed.security.spi.InternalPasswordCredentialInterceptor;
import org.apache.jetspeed.security.spi.PasswordCredentialProvider;
import org.apache.jetspeed.security.spi.SecurityAccess;
@@ -65,9 +66,9 @@
/**
* @see org.apache.jetspeed.security.spi.CredentialHandler#getPrivateCredentials(java.lang.String)
*/
- public Set getPrivateCredentials(String username)
+ public Set<Credential> getPrivateCredentials(String username)
{
- Set credentials = new HashSet();
+ Set<Credential> credentials = new HashSet<Credential>();
InternalUserPrincipal internalUser = securityAccess.getInternalUserPrincipal(username, false);
if (null != internalUser)
{
@@ -91,23 +92,21 @@
/**
* @see org.apache.jetspeed.security.spi.CredentialHandler#getPublicCredentials(java.lang.String)
*/
- public Set getPublicCredentials(String username)
+ public Set<Credential> getPublicCredentials(String username)
{
- return new HashSet();
+ return new HashSet<Credential>();
}
private InternalCredential getPasswordCredential(InternalUserPrincipal internalUser, String username)
{
- InternalCredential credential = null;
-
- Collection internalCredentials = internalUser.getCredentials();
+ InternalCredential credential = null;
+ Collection<InternalCredential> internalCredentials = internalUser.getCredentials();
if ( internalCredentials != null )
{
- Iterator iter = internalCredentials.iterator();
-
+ Iterator<InternalCredential> iter = internalCredentials.iterator();
while (iter.hasNext())
{
- credential = (InternalCredential) iter.next();
+ credential = iter.next();
if (credential.getType() == InternalCredential.PRIVATE )
{
if ((null != credential.getClassname())
@@ -118,7 +117,7 @@
if ( ipcInterceptor != null && ipcInterceptor.afterLoad(pcProvider, username, credential) )
{
// update InternalUserPrincipal to save post processed data
- securityAccess.setInternalUserPrincipal(internalUser,internalUser.isMappingOnly());
+ securityAccess.storeInternalUserPrincipal(internalUser, internalUser.isMappingOnly());
}
break;
}
@@ -160,16 +159,13 @@
if (null == internalUser)
{
throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST.create(userName));
- }
-
- Collection credentials = internalUser.getCredentials();
+ }
+ Collection<InternalCredential> credentials = internalUser.getCredentials();
if (null == credentials)
{
- credentials = new ArrayList();
+ credentials = new ArrayList<InternalCredential>();
}
-
- InternalCredential credential = getPasswordCredential(internalUser, userName );
-
+ InternalCredential credential = getPasswordCredential(internalUser, userName );
if (null != oldPassword)
{
if ( credential != null &&
@@ -282,7 +278,7 @@
internalUser.setModifiedDate(new Timestamp(time));
internalUser.setCredentials(credentials);
// Set the user with the new credentials.
- securityAccess.setInternalUserPrincipal(internalUser, false);
+ securityAccess.storeInternalUserPrincipal(internalUser, false);
}
@@ -302,7 +298,7 @@
credential.setAuthenticationFailures(0);
credential.setModifiedDate(new Timestamp(time));
internalUser.setModifiedDate(new Timestamp(time));
- securityAccess.setInternalUserPrincipal(internalUser, false);
+ securityAccess.storeInternalUserPrincipal(internalUser, false);
}
}
else
@@ -337,7 +333,7 @@
credential.setPreviousAuthenticationDate(new Timestamp(time));
credential.setModifiedDate(new Timestamp(time));
internalUser.setModifiedDate(new Timestamp(time));
- securityAccess.setInternalUserPrincipal(internalUser, false);
+ securityAccess.storeInternalUserPrincipal(internalUser, false);
}
}
else
@@ -370,7 +366,7 @@
credential.setModifiedDate(new Timestamp(time));
internalUser.setModifiedDate(new Timestamp(time));
- securityAccess.setInternalUserPrincipal(internalUser, false);
+ securityAccess.storeInternalUserPrincipal(internalUser, false);
}
}
else
@@ -435,7 +431,7 @@
{
credential.setModifiedDate(new Timestamp(time));
internalUser.setModifiedDate(new Timestamp(time));
- securityAccess.setInternalUserPrincipal(internalUser, false);
+ securityAccess.storeInternalUserPrincipal(internalUser, false);
}
}
}
Modified: portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultGroupSecurityHandler.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultGroupSecurityHandler.java?rev=683497&r1=683496&r2=683497&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultGroupSecurityHandler.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-869/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/spi/impl/DefaultGroupSecurityHandler.java Wed Aug 6 20:52:05 2008
@@ -16,7 +16,7 @@
*/
package org.apache.jetspeed.security.spi.impl;
-import java.util.Iterator;
+import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
@@ -52,16 +52,14 @@
/**
* @see org.apache.jetspeed.security.spi.GroupSecurityHandler#getGroupPrincipal(java.lang.String)
*/
- public GroupPrincipal getGroupPrincipal(String groupFullPathName)
+ public GroupPrincipal getGroupPrincipal(String groupName)
{
GroupPrincipal groupPrincipal = null;
- InternalGroupPrincipal internalGroup = commonQueries
- .getInternalGroupPrincipal(GroupPrincipalImpl
- .getFullPathFromPrincipalName(groupFullPathName));
+ InternalGroupPrincipal internalGroup = commonQueries.getInternalGroupPrincipal(groupName);
if (null != internalGroup)
{
- groupPrincipal = new GroupPrincipalImpl(GroupPrincipalImpl
- .getPrincipalNameFromFullPath(internalGroup.getFullPath()), internalGroup.isEnabled(), internalGroup.isMappingOnly());
+ groupPrincipal = new GroupPrincipalImpl(internalGroup.getPrincipalId(), internalGroup.getName(),
+ internalGroup.isEnabled(), internalGroup.isMappingOnly());
}
return groupPrincipal;
}
@@ -69,23 +67,22 @@
/**
* @see org.apache.jetspeed.security.spi.GroupSecurityHandler#setGroupPrincipal(org.apache.jetspeed.security.GroupPrincipal)
*/
- public void setGroupPrincipal(GroupPrincipal groupPrincipal)
+ public void storeGroupPrincipal(GroupPrincipal groupPrincipal)
throws SecurityException
{
- String fullPath = groupPrincipal.getFullPath();
- InternalGroupPrincipal internalGroup = commonQueries.getInternalGroupPrincipal(fullPath);
- if ( null == internalGroup )
+ InternalGroupPrincipal internalGroup = commonQueries.getInternalGroupPrincipal(groupPrincipal.getName());
+ if (null == internalGroup)
{
- internalGroup = new InternalGroupPrincipalImpl(fullPath);
+ internalGroup = new InternalGroupPrincipalImpl(groupPrincipal.getName());
internalGroup.setEnabled(groupPrincipal.isEnabled());
- commonQueries.setInternalGroupPrincipal(internalGroup, false);
+ commonQueries.storeInternalGroupPrincipal(internalGroup, false);
}
else if ( !internalGroup.isMappingOnly() )
{
if ( internalGroup.isEnabled() != groupPrincipal.isEnabled() )
{
internalGroup.setEnabled(groupPrincipal.isEnabled());
- commonQueries.setInternalGroupPrincipal(internalGroup, false);
+ commonQueries.storeInternalGroupPrincipal(internalGroup, false);
}
}
else
@@ -100,8 +97,7 @@
public void removeGroupPrincipal(GroupPrincipal groupPrincipal)
throws SecurityException
{
- InternalGroupPrincipal internalGroup = commonQueries
- .getInternalGroupPrincipal(groupPrincipal.getFullPath());
+ InternalGroupPrincipal internalGroup = commonQueries.getInternalGroupPrincipal(groupPrincipal.getName());
if (null != internalGroup)
{
commonQueries.removeInternalGroupPrincipal(internalGroup);
@@ -111,21 +107,14 @@
/**
* @see org.apache.jetspeed.security.spi.GroupSecurityHandler#getGroupPrincipals(java.lang.String)
*/
- public List getGroupPrincipals(String filter)
+ public List<GroupPrincipal> getGroupPrincipals(String filter)
{
- List groupPrincipals = new LinkedList();
- Iterator result = commonQueries.getInternalGroupPrincipals(filter);
- while (result.hasNext())
- {
- InternalGroupPrincipal internalGroup = (InternalGroupPrincipal) result
- .next();
- String path = internalGroup.getFullPath();
- if (path == null)
- {
- continue;
- }
+ List<GroupPrincipal> groupPrincipals = new LinkedList<GroupPrincipal>();
+ Collection<InternalGroupPrincipal> internalGroups = commonQueries.getInternalGroupPrincipals(filter);
+ for (InternalGroupPrincipal internalGroup : internalGroups)
+ {
groupPrincipals
- .add(new GroupPrincipalImpl(GroupPrincipalImpl.getPrincipalNameFromFullPath(internalGroup.getFullPath()),
+ .add(new GroupPrincipalImpl(internalGroup.getPrincipalId(), internalGroup.getName(),
internalGroup.isEnabled(), internalGroup.isMappingOnly())
);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org