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 2004/12/22 18:54:08 UTC
cvs commit: jakarta-jetspeed-2/components/security/src/test/org/apache/jetspeed/security TestRoleManager.java TestGroupManager.java
taylor 2004/12/22 09:54:08
Modified: components/security/src/java/org/apache/jetspeed/security/spi
RoleSecurityHandler.java UserSecurityHandler.java
SecurityAccess.java GroupSecurityHandler.java
components/security/src/java/org/apache/jetspeed/security/spi/impl
DefaultGroupSecurityHandler.java
DefaultUserSecurityHandler.java
SecurityAccessImpl.java
DefaultRoleSecurityHandler.java
components/security/src/java/org/apache/jetspeed/security/impl
GroupManagerImpl.java UserManagerImpl.java
RoleManagerImpl.java
components/security/src/test/org/apache/jetspeed/security
TestRoleManager.java TestGroupManager.java
Log:
implemented getRoles and getGroups new apis
CVS: ----------------------------------------------------------------------
CVS: PR:
CVS: If this change addresses a PR in the problem report tracking
CVS: database, then enter the PR number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system, such as NCSA,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to Apache by someone else; i.e.,
CVS: they sent us a patch or a new module, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.
Revision Changes Path
1.4 +12 -1 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/RoleSecurityHandler.java
Index: RoleSecurityHandler.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/RoleSecurityHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RoleSecurityHandler.java 25 Sep 2004 23:03:18 -0000 1.3
+++ RoleSecurityHandler.java 22 Dec 2004 17:54:07 -0000 1.4
@@ -15,6 +15,7 @@
package org.apache.jetspeed.security.spi;
import java.security.Principal;
+import java.util.List;
import org.apache.jetspeed.security.RolePrincipal;
import org.apache.jetspeed.security.SecurityException;
@@ -68,4 +69,14 @@
*/
void removeRolePrincipal(RolePrincipal rolePrincipal) throws SecurityException;
-}
+ /**
+ * <p>
+ * Gets the an iterator of role principals for a given filter.
+ * </p>
+ *
+ * @param filter The filter.
+ * @return The list of <code>Principal</code>
+ */
+ List getRolePrincipals(String filter);
+
+}
1.5 +1 -1 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/UserSecurityHandler.java
Index: UserSecurityHandler.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/UserSecurityHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- UserSecurityHandler.java 27 Oct 2004 22:09:28 -0000 1.4
+++ UserSecurityHandler.java 22 Dec 2004 17:54:07 -0000 1.5
@@ -62,7 +62,7 @@
* </p>
*
* @param filter The filter.
- * @return The list of <code>Principal</p>
+ * @return The list of <code>Principal</code>
*/
List getUserPrincipals(String filter);
1.3 +22 -1 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/SecurityAccess.java
Index: SecurityAccess.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/SecurityAccess.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SecurityAccess.java 8 Nov 2004 03:23:36 -0000 1.2
+++ SecurityAccess.java 22 Dec 2004 17:54:07 -0000 1.3
@@ -159,4 +159,25 @@
* @throws SecurityException Throws a {@link SecurityException}.
*/
void removeInternalGroupPrincipal( InternalGroupPrincipal internalGroup ) throws SecurityException;
+
+ /**
+ * <p>
+ * Returns a collection of Role {@link Principal} given the filter.
+ * </p>
+ *
+ * @param filter The filter.
+ * @return Collection of {@link InternalRolePrincipal}.
+ */
+ Iterator getInternalRolePrincipals(String filter);
+
+ /**
+ * <p>
+ * Returns a collection of Group {@link Principal} given the filter.
+ * </p>
+ *
+ * @param filter The filter.
+ * @return Collection of {@link InternalGroupPrincipal}.
+ */
+ Iterator getInternalGroupPrincipals(String filter);
+
}
1.4 +11 -0 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/GroupSecurityHandler.java
Index: GroupSecurityHandler.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/GroupSecurityHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GroupSecurityHandler.java 2 Oct 2004 23:05:20 -0000 1.3
+++ GroupSecurityHandler.java 22 Dec 2004 17:54:07 -0000 1.4
@@ -15,6 +15,7 @@
package org.apache.jetspeed.security.spi;
import java.security.Principal;
+import java.util.List;
import org.apache.jetspeed.security.GroupPrincipal;
import org.apache.jetspeed.security.SecurityException;
@@ -67,4 +68,14 @@
*/
void removeGroupPrincipal(GroupPrincipal groupPrincipal) throws SecurityException;
+ /**
+ * <p>
+ * Gets the an iterator of group principals for a given filter.
+ * </p>
+ *
+ * @param filter The filter.
+ * @return The list of <code>Principal</code>
+ */
+ List getGroupPrincipals(String filter);
+
}
1.6 +53 -18 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultGroupSecurityHandler.java
Index: DefaultGroupSecurityHandler.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultGroupSecurityHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultGroupSecurityHandler.java 29 Oct 2004 14:08:35 -0000 1.5
+++ DefaultGroupSecurityHandler.java 22 Dec 2004 17:54:08 -0000 1.6
@@ -15,6 +15,9 @@
package org.apache.jetspeed.security.spi.impl;
import java.security.Principal;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import org.apache.jetspeed.security.GroupPrincipal;
import org.apache.jetspeed.security.SecurityException;
@@ -26,58 +29,90 @@
/**
* @see org.apache.jetspeed.security.spi.GroupSecurityHandler
- * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
+ * @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
*/
public class DefaultGroupSecurityHandler implements GroupSecurityHandler
{
+
/** Common queries. */
private SecurityAccess commonQueries = null;
-
+
/**
- * <p>Constructor providing access to the common queries.</p>
+ * <p>
+ * Constructor providing access to the common queries.
+ * </p>
*/
public DefaultGroupSecurityHandler(SecurityAccess commonQueries)
{
this.commonQueries = commonQueries;
}
-
+
/**
* @see org.apache.jetspeed.security.spi.GroupSecurityHandler#getGroupPrincipal(java.lang.String)
*/
public Principal getGroupPrincipal(String groupFullPathName)
{
GroupPrincipal groupPrincipal = null;
- InternalGroupPrincipal internalGroup = commonQueries.getInternalGroupPrincipal(GroupPrincipalImpl
- .getFullPathFromPrincipalName(groupFullPathName));
+ InternalGroupPrincipal internalGroup = commonQueries
+ .getInternalGroupPrincipal(GroupPrincipalImpl
+ .getFullPathFromPrincipalName(groupFullPathName));
if (null != internalGroup)
{
- groupPrincipal = new GroupPrincipalImpl(GroupPrincipalImpl.getPrincipalNameFromFullPath(internalGroup
- .getFullPath()));
+ groupPrincipal = new GroupPrincipalImpl(GroupPrincipalImpl
+ .getPrincipalNameFromFullPath(internalGroup.getFullPath()));
}
return groupPrincipal;
}
-
-
+
/**
* @see org.apache.jetspeed.security.spi.GroupSecurityHandler#setGroupPrincipal(org.apache.jetspeed.security.GroupPrincipal)
*/
- public void setGroupPrincipal(GroupPrincipal groupPrincipal) throws SecurityException
+ public void setGroupPrincipal(GroupPrincipal groupPrincipal)
+ throws SecurityException
{
String fullPath = groupPrincipal.getFullPath();
- InternalGroupPrincipal internalGroup = new InternalGroupPrincipalImpl(fullPath);
- commonQueries.setInternalGroupPrincipal(internalGroup, false);
+ InternalGroupPrincipal internalGroup = new InternalGroupPrincipalImpl(
+ fullPath);
+ commonQueries.setInternalGroupPrincipal(internalGroup, false);
}
-
+
/**
* @see org.apache.jetspeed.security.spi.GroupSecurityHandler#removeGroupPrincipal(org.apache.jetspeed.security.GroupPrincipal)
*/
- public void removeGroupPrincipal(GroupPrincipal groupPrincipal) throws SecurityException
+ public void removeGroupPrincipal(GroupPrincipal groupPrincipal)
+ throws SecurityException
{
- InternalGroupPrincipal internalGroup = commonQueries.getInternalGroupPrincipal(groupPrincipal.getFullPath());
+ InternalGroupPrincipal internalGroup = commonQueries
+ .getInternalGroupPrincipal(groupPrincipal.getFullPath());
if (null != internalGroup)
{
commonQueries.removeInternalGroupPrincipal(internalGroup);
}
}
-
-}
+
+ /**
+ * @see org.apache.jetspeed.security.spi.GroupSecurityHandler#getGroupPrincipals(java.lang.String)
+ */
+ public List 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;
+ }
+ groupPrincipals
+ .add(new GroupPrincipalImpl(GroupPrincipalImpl
+ .getPrincipalNameFromFullPath(internalGroup
+ .getFullPath())));
+ }
+ return groupPrincipals;
+ }
+
+}
\ No newline at end of file
1.6 +1 -1 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultUserSecurityHandler.java
Index: DefaultUserSecurityHandler.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultUserSecurityHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultUserSecurityHandler.java 8 Nov 2004 03:23:35 -0000 1.5
+++ DefaultUserSecurityHandler.java 22 Dec 2004 17:54:08 -0000 1.6
@@ -77,7 +77,7 @@
{
InternalUserPrincipal internalUser = (InternalUserPrincipal) result.next();
String path = internalUser.getFullPath();
- if (path == null || !path.startsWith(UserPrincipal.PREFS_USER_ROOT)) // TODO: FIXME: the extend shouldn't return roles!
+ if (path == null)
{
continue;
}
1.3 +24 -0 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/SecurityAccessImpl.java
Index: SecurityAccessImpl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/SecurityAccessImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SecurityAccessImpl.java 8 Nov 2004 03:23:35 -0000 1.2
+++ SecurityAccessImpl.java 22 Dec 2004 17:54:08 -0000 1.3
@@ -15,6 +15,7 @@
package org.apache.jetspeed.security.spi.impl;
import java.security.Principal;
+import java.util.Collection;
import java.util.Iterator;
import org.apache.jetspeed.components.dao.InitablePersistenceBrokerDaoSupport;
@@ -38,6 +39,7 @@
* </p>
*
* @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
*/
public class SecurityAccessImpl extends InitablePersistenceBrokerDaoSupport implements SecurityAccess
{
@@ -125,6 +127,7 @@
{
Criteria queryCriteria = new Criteria();
queryCriteria.addEqualTo("isMappingOnly", new Boolean(false));
+ queryCriteria.addLike("fullPath", UserPrincipal.PREFS_USER_ROOT + "%");
Query query = QueryFactory.newQuery(InternalUserPrincipalImpl.class, queryCriteria);
Iterator result = getPersistenceBrokerTemplate().getIteratorByQuery(query);
return result;
@@ -334,4 +337,25 @@
}
+ public Iterator getInternalRolePrincipals(String filter)
+ {
+ Criteria queryCriteria = new Criteria();
+ queryCriteria.addEqualTo("isMappingOnly", new Boolean(false));
+ queryCriteria.addLike("fullPath", UserPrincipal.PREFS_ROLE_ROOT + "%");
+ Query query = QueryFactory.newQuery(InternalRolePrincipalImpl.class, queryCriteria);
+ Collection c = getPersistenceBrokerTemplate().getCollectionByQuery(query);
+ return c.iterator();
+ }
+
+ public Iterator getInternalGroupPrincipals(String filter)
+ {
+
+ Criteria queryCriteria = new Criteria();
+ queryCriteria.addEqualTo("isMappingOnly", new Boolean(false));
+ queryCriteria.addLike("fullPath", UserPrincipal.PREFS_GROUP_ROOT + "%");
+ Query query = QueryFactory.newQuery(InternalGroupPrincipalImpl.class, queryCriteria);
+ Collection c = getPersistenceBrokerTemplate().getCollectionByQuery(query);
+ return c.iterator();
+ }
+
}
1.7 +42 -10 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultRoleSecurityHandler.java
Index: DefaultRoleSecurityHandler.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/spi/impl/DefaultRoleSecurityHandler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefaultRoleSecurityHandler.java 29 Oct 2004 14:08:35 -0000 1.6
+++ DefaultRoleSecurityHandler.java 22 Dec 2004 17:54:08 -0000 1.7
@@ -15,6 +15,9 @@
package org.apache.jetspeed.security.spi.impl;
import java.security.Principal;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import org.apache.jetspeed.security.RolePrincipal;
import org.apache.jetspeed.security.SecurityException;
@@ -27,9 +30,11 @@
/**
* @see org.apache.jetspeed.security.spi.RoleSecurityHandler
* @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
*/
public class DefaultRoleSecurityHandler implements RoleSecurityHandler
{
+
/** Common queries. */
private SecurityAccess commonQueries = null;
@@ -49,12 +54,13 @@
public Principal getRolePrincipal(String roleFullPathName)
{
RolePrincipal rolePrincipal = null;
- InternalRolePrincipal internalRole = commonQueries.getInternalRolePrincipal(RolePrincipalImpl
- .getFullPathFromPrincipalName(roleFullPathName));
+ InternalRolePrincipal internalRole = commonQueries
+ .getInternalRolePrincipal(RolePrincipalImpl
+ .getFullPathFromPrincipalName(roleFullPathName));
if (null != internalRole)
{
- rolePrincipal = new RolePrincipalImpl(RolePrincipalImpl.getPrincipalNameFromFullPath(internalRole
- .getFullPath()));
+ rolePrincipal = new RolePrincipalImpl(RolePrincipalImpl
+ .getPrincipalNameFromFullPath(internalRole.getFullPath()));
}
return rolePrincipal;
}
@@ -62,22 +68,48 @@
/**
* @see org.apache.jetspeed.security.spi.RoleSecurityHandler#setRolePrincipal(org.apache.jetspeed.security.RolePrincipal)
*/
- public void setRolePrincipal(RolePrincipal rolePrincipal) throws SecurityException
+ public void setRolePrincipal(RolePrincipal rolePrincipal)
+ throws SecurityException
{
String fullPath = rolePrincipal.getFullPath();
- InternalRolePrincipal internalRole = new InternalRolePrincipalImpl(fullPath);
- commonQueries.setInternalRolePrincipal(internalRole, false);
+ InternalRolePrincipal internalRole = new InternalRolePrincipalImpl(
+ fullPath);
+ commonQueries.setInternalRolePrincipal(internalRole, false);
}
-
+
/**
* @see org.apache.jetspeed.security.spi.RoleSecurityHandler#removeRolePrincipal(org.apache.jetspeed.security.RolePrincipal)
*/
- public void removeRolePrincipal(RolePrincipal rolePrincipal) throws SecurityException
+ public void removeRolePrincipal(RolePrincipal rolePrincipal)
+ throws SecurityException
{
- InternalRolePrincipal internalRole = commonQueries.getInternalRolePrincipal(rolePrincipal.getFullPath());
+ InternalRolePrincipal internalRole = commonQueries
+ .getInternalRolePrincipal(rolePrincipal.getFullPath());
if (null != internalRole)
{
commonQueries.removeInternalRolePrincipal(internalRole);
}
+ }
+
+ /**
+ * @see org.apache.jetspeed.security.spi.RoleSecurityHandler#getRolePrincipals(java.lang.String)
+ */
+ public List getRolePrincipals(String filter)
+ {
+ List rolePrincipals = new LinkedList();
+ Iterator result = commonQueries.getInternalRolePrincipals(filter);
+ while (result.hasNext())
+ {
+ InternalRolePrincipal internalRole = (InternalRolePrincipal) result
+ .next();
+ String path = internalRole.getFullPath();
+ if (path == null)
+ {
+ continue;
+ }
+ rolePrincipals.add(new RolePrincipalImpl(RolePrincipalImpl
+ .getPrincipalNameFromFullPath(internalRole.getFullPath())));
+ }
+ return rolePrincipals;
}
}
1.11 +129 -76 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java
Index: GroupManagerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- GroupManagerImpl.java 11 Oct 2004 23:25:29 -0000 1.10
+++ GroupManagerImpl.java 22 Dec 2004 17:54:08 -0000 1.11
@@ -18,6 +18,8 @@
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;
@@ -50,12 +52,14 @@
* </p>
*
* @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
*/
public class GroupManagerImpl implements GroupManager
{
+
/** The logger. */
private static final Log log = LogFactory.getLog(GroupManagerImpl.class);
-
+
/** The authentication provider proxy. */
private AuthenticationProviderProxy atnProviderProxy = null;
@@ -66,13 +70,16 @@
private SecurityMappingHandler securityMappingHandler = null;
/**
- * @param securityProvider The security provider.
+ * @param securityProvider
+ * The security provider.
*/
public GroupManagerImpl(SecurityProvider securityProvider)
{
- this.atnProviderProxy = securityProvider.getAuthenticationProviderProxy();
+ this.atnProviderProxy = securityProvider
+ .getAuthenticationProviderProxy();
this.groupSecurityHandler = securityProvider.getGroupSecurityHandler();
- this.securityMappingHandler = securityProvider.getSecurityMappingHandler();
+ this.securityMappingHandler = securityProvider
+ .getSecurityMappingHandler();
}
/**
@@ -80,16 +87,17 @@
*/
public void addGroup(String groupFullPathName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { groupFullPathName }, new String[] { "groupFullPathName" },
- "addGroup(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { groupFullPathName}, new String[]
+ { "groupFullPathName"}, "addGroup(java.lang.String)");
// Check if group already exists.
- if (groupExists(groupFullPathName))
- {
- throw new SecurityException(SecurityException.GROUP_ALREADY_EXISTS + " " + groupFullPathName);
- }
+ if (groupExists(groupFullPathName)) { throw new SecurityException(
+ SecurityException.GROUP_ALREADY_EXISTS + " "
+ + groupFullPathName); }
- GroupPrincipal groupPrincipal = new GroupPrincipalImpl(groupFullPathName);
+ GroupPrincipal groupPrincipal = new GroupPrincipalImpl(
+ groupFullPathName);
String fullPath = groupPrincipal.getFullPath();
// Add the preferences.
Preferences preferences = Preferences.userRoot().node(fullPath);
@@ -99,7 +107,8 @@
}
try
{
- if ((null != preferences) && preferences.absolutePath().equals(fullPath))
+ if ((null != preferences)
+ && preferences.absolutePath().equals(fullPath))
{
// Add role principal.
groupSecurityHandler.setGroupPrincipal(groupPrincipal);
@@ -108,8 +117,7 @@
log.debug("Added group: " + fullPath);
}
}
- }
- catch (SecurityException se)
+ } catch (SecurityException se)
{
String msg = "Unable to create the role.";
log.error(msg, se);
@@ -118,8 +126,7 @@
try
{
preferences.removeNode();
- }
- catch (BackingStoreException bse)
+ } catch (BackingStoreException bse)
{
bse.printStackTrace();
}
@@ -132,34 +139,39 @@
*/
public void removeGroup(String groupFullPathName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { groupFullPathName }, new String[] { "groupFullPathName" },
- "removeGroup(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { groupFullPathName}, new String[]
+ { "groupFullPathName"}, "removeGroup(java.lang.String)");
// Resolve the group hierarchy.
Preferences prefs = Preferences.userRoot().node(
- GroupPrincipalImpl.getFullPathFromPrincipalName(groupFullPathName));
- String[] groups = securityMappingHandler.getGroupHierarchyResolver().resolveChildren(prefs);
+ GroupPrincipalImpl
+ .getFullPathFromPrincipalName(groupFullPathName));
+ String[] groups = securityMappingHandler.getGroupHierarchyResolver()
+ .resolveChildren(prefs);
for (int i = 0; i < groups.length; i++)
{
try
{
- groupSecurityHandler.removeGroupPrincipal(new GroupPrincipalImpl(GroupPrincipalImpl
- .getPrincipalNameFromFullPath((String) groups[i])));
- }
- catch (Exception e)
+ groupSecurityHandler
+ .removeGroupPrincipal(new GroupPrincipalImpl(
+ GroupPrincipalImpl
+ .getPrincipalNameFromFullPath((String) groups[i])));
+ } catch (Exception e)
{
String msg = "Unable to remove group: "
- + GroupPrincipalImpl.getPrincipalNameFromFullPath((String) groups[i]);
+ + GroupPrincipalImpl
+ .getPrincipalNameFromFullPath((String) groups[i]);
log.error(msg, e);
throw new SecurityException(msg, e);
}
// Remove preferences
- Preferences groupPref = Preferences.userRoot().node((String) groups[i]);
+ Preferences groupPref = Preferences.userRoot().node(
+ (String) groups[i]);
try
{
groupPref.removeNode();
- }
- catch (BackingStoreException bse)
+ } catch (BackingStoreException bse)
{
String msg = "Unable to remove group preferences: " + groups[i];
log.error(msg, bse);
@@ -173,10 +185,12 @@
*/
public boolean groupExists(String groupFullPathName)
{
- ArgUtil.notNull(new Object[] { groupFullPathName }, new String[] { "groupFullPathName" },
- "groupExists(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { groupFullPathName}, new String[]
+ { "groupFullPathName"}, "groupExists(java.lang.String)");
- Principal principal = groupSecurityHandler.getGroupPrincipal(groupFullPathName);
+ Principal principal = groupSecurityHandler
+ .getGroupPrincipal(groupFullPathName);
boolean groupExists = (null != principal);
if (log.isDebugEnabled())
{
@@ -191,16 +205,18 @@
*/
public Group getGroup(String groupFullPathName) throws SecurityException
{
- ArgUtil.notNull(new Object[] { groupFullPathName }, new String[] { "groupFullPathName" },
- "getGroup(java.lang.String)");
-
- String fullPath = GroupPrincipalImpl.getFullPathFromPrincipalName(groupFullPathName);
-
- Principal groupPrincipal = groupSecurityHandler.getGroupPrincipal(groupFullPathName);
- if (null == groupPrincipal)
- {
- throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST + " " + groupFullPathName);
- }
+ ArgUtil.notNull(new Object[]
+ { groupFullPathName}, new String[]
+ { "groupFullPathName"}, "getGroup(java.lang.String)");
+
+ String fullPath = GroupPrincipalImpl
+ .getFullPathFromPrincipalName(groupFullPathName);
+
+ Principal groupPrincipal = groupSecurityHandler
+ .getGroupPrincipal(groupFullPathName);
+ if (null == groupPrincipal) { throw new SecurityException(
+ SecurityException.GROUP_DOES_NOT_EXIST + " "
+ + groupFullPathName); }
Preferences preferences = Preferences.userRoot().node(fullPath);
Group group = new GroupImpl(groupPrincipal, preferences);
return group;
@@ -209,19 +225,25 @@
/**
* @see org.apache.jetspeed.security.GroupManager#getGroupsForUser(java.lang.String)
*/
- public Collection getGroupsForUser(String username) throws SecurityException
+ public Collection getGroupsForUser(String username)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { username }, new String[] { "username" }, "getGroupsForUser(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { username}, new String[]
+ { "username"}, "getGroupsForUser(java.lang.String)");
Collection groups = new ArrayList();
- Set groupPrincipals = securityMappingHandler.getGroupPrincipals(username);
+ Set groupPrincipals = securityMappingHandler
+ .getGroupPrincipals(username);
Iterator groupPrincipalsIter = groupPrincipals.iterator();
while (groupPrincipalsIter.hasNext())
{
Principal groupPrincipal = (Principal) groupPrincipalsIter.next();
Preferences preferences = Preferences.userRoot().node(
- GroupPrincipalImpl.getFullPathFromPrincipalName(groupPrincipal.getName()));
+ GroupPrincipalImpl
+ .getFullPathFromPrincipalName(groupPrincipal
+ .getName()));
groups.add(new GroupImpl(groupPrincipal, preferences));
}
return groups;
@@ -230,20 +252,25 @@
/**
* @see org.apache.jetspeed.security.GroupManager#getGroupsInRole(java.lang.String)
*/
- public Collection getGroupsInRole(String roleFullPathName) throws SecurityException
+ public Collection getGroupsInRole(String roleFullPathName)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName }, new String[] { "roleFullPathName" },
- "getGroupsInRole(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { roleFullPathName}, new String[]
+ { "roleFullPathName"}, "getGroupsInRole(java.lang.String)");
Collection groups = new ArrayList();
- Set groupPrincipals = securityMappingHandler.getGroupPrincipalsInRole(roleFullPathName);
+ Set groupPrincipals = securityMappingHandler
+ .getGroupPrincipalsInRole(roleFullPathName);
Iterator groupPrincipalsIter = groupPrincipals.iterator();
while (groupPrincipalsIter.hasNext())
{
Principal groupPrincipal = (Principal) groupPrincipalsIter.next();
Preferences preferences = Preferences.userRoot().node(
- GroupPrincipalImpl.getFullPathFromPrincipalName(groupPrincipal.getName()));
+ GroupPrincipalImpl
+ .getFullPathFromPrincipalName(groupPrincipal
+ .getName()));
groups.add(new GroupImpl(groupPrincipal, preferences));
}
return groups;
@@ -253,29 +280,32 @@
* @see org.apache.jetspeed.security.GroupManager#addUserToGroup(java.lang.String,
* java.lang.String)
*/
- public void addUserToGroup(String username, String groupFullPathName) throws SecurityException
+ public void addUserToGroup(String username, String groupFullPathName)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { username, groupFullPathName }, new String[] { "username", "groupFullPathName" },
+ ArgUtil.notNull(new Object[]
+ { username, groupFullPathName}, new String[]
+ { "username", "groupFullPathName"},
"addUserToGroup(java.lang.String, java.lang.String)");
// Get the group principal to add to user.
- Principal groupPrincipal = groupSecurityHandler.getGroupPrincipal(groupFullPathName);
- if (null == groupPrincipal)
- {
- throw new SecurityException(SecurityException.GROUP_DOES_NOT_EXIST + " " + groupFullPathName);
- }
+ Principal groupPrincipal = groupSecurityHandler
+ .getGroupPrincipal(groupFullPathName);
+ if (null == groupPrincipal) { throw new SecurityException(
+ SecurityException.GROUP_DOES_NOT_EXIST + " "
+ + groupFullPathName); }
// Check that user exists.
Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
- if (null == userPrincipal)
- {
- throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST + " " + username);
- }
+ if (null == userPrincipal) { throw new SecurityException(
+ SecurityException.USER_DOES_NOT_EXIST + " " + username); }
// Get the user groups.
- Set groupPrincipals = securityMappingHandler.getGroupPrincipals(username);
+ Set groupPrincipals = securityMappingHandler
+ .getGroupPrincipals(username);
// Add group to user.
if (!groupPrincipals.contains(groupPrincipal))
{
- securityMappingHandler.setUserPrincipalInGroup(username, groupFullPathName);
+ securityMappingHandler.setUserPrincipalInGroup(username,
+ groupFullPathName);
}
}
@@ -283,22 +313,25 @@
* @see org.apache.jetspeed.security.GroupManager#removeUserFromGroup(java.lang.String,
* java.lang.String)
*/
- public void removeUserFromGroup(String username, String groupFullPathName) throws SecurityException
+ public void removeUserFromGroup(String username, String groupFullPathName)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { username, groupFullPathName }, new String[] { "username", "groupFullPathName" },
+ ArgUtil.notNull(new Object[]
+ { username, groupFullPathName}, new String[]
+ { "username", "groupFullPathName"},
"removeUserFromGroup(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 + " " + username);
- }
+ if (null == userPrincipal) { throw new SecurityException(
+ SecurityException.USER_DOES_NOT_EXIST + " " + username); }
// Get the group principal to remove.
- Principal groupPrincipal = groupSecurityHandler.getGroupPrincipal(groupFullPathName);
+ Principal groupPrincipal = groupSecurityHandler
+ .getGroupPrincipal(groupFullPathName);
if (null != groupPrincipal)
{
- securityMappingHandler.removeUserPrincipalInGroup(username, groupFullPathName);
+ securityMappingHandler.removeUserPrincipalInGroup(username,
+ groupFullPathName);
}
}
@@ -306,15 +339,19 @@
* @see org.apache.jetspeed.security.GroupManager#isUserInGroup(java.lang.String,
* java.lang.String)
*/
- public boolean isUserInGroup(String username, String groupFullPathName) throws SecurityException
+ public boolean isUserInGroup(String username, String groupFullPathName)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { username, groupFullPathName }, new String[] { "username", "groupFullPathName" },
+ ArgUtil.notNull(new Object[]
+ { username, groupFullPathName}, new String[]
+ { "username", "groupFullPathName"},
"isUserInGroup(java.lang.String, java.lang.String)");
boolean isUserInGroup = false;
-
- Set groupPrincipals = securityMappingHandler.getGroupPrincipals(username);
- Principal groupPrincipal = new GroupPrincipalImpl(groupFullPathName);
+
+ Set groupPrincipals = securityMappingHandler
+ .getGroupPrincipals(username);
+ Principal groupPrincipal = new GroupPrincipalImpl(groupFullPathName);
if (groupPrincipals.contains(groupPrincipal))
{
isUserInGroup = true;
@@ -322,4 +359,20 @@
return isUserInGroup;
}
+ /**
+ * @see org.apache.jetspeed.security.GroupManager#getGroups(java.lang.String)
+ */
+ public Iterator getGroups(String filter) throws SecurityException
+ {
+ List groups = new LinkedList();
+ Iterator groupPrincipals = groupSecurityHandler.getGroupPrincipals(filter).iterator();
+ while (groupPrincipals.hasNext())
+ {
+ String groupName = ((Principal) groupPrincipals.next()).getName();
+ Group group = getGroup(groupName);
+ groups.add(group);
+ }
+ return groups.iterator();
+ }
+
}
1.18 +155 -112 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/UserManagerImpl.java
Index: UserManagerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/UserManagerImpl.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- UserManagerImpl.java 25 Nov 2004 02:25:57 -0000 1.17
+++ UserManagerImpl.java 22 Dec 2004 17:54:08 -0000 1.18
@@ -49,6 +49,7 @@
*/
public class UserManagerImpl implements UserManager
{
+
private static final Log log = LogFactory.getLog(UserManagerImpl.class);
/** The authenticatino provider proxy. */
@@ -60,56 +61,81 @@
private String anonymousUser = "guest";
/**
- * @param securityProvider The security provider.
+ * @param securityProvider
+ * The security provider.
*/
public UserManagerImpl(SecurityProvider securityProvider)
{
- this.atnProviderProxy = securityProvider.getAuthenticationProviderProxy();
- this.securityMappingHandler = securityProvider.getSecurityMappingHandler();
+ this.atnProviderProxy = securityProvider
+ .getAuthenticationProviderProxy();
+ this.securityMappingHandler = securityProvider
+ .getSecurityMappingHandler();
}
/**
- * @param securityProvider The security provider.
- * @param anonymousUser The anonymous user name
- */
- public UserManagerImpl(SecurityProvider securityProvider, String anonymousUser)
- {
- this.atnProviderProxy = securityProvider.getAuthenticationProviderProxy();
- this.securityMappingHandler = securityProvider.getSecurityMappingHandler();
- if ( anonymousUser != null )
+ * @param securityProvider
+ * The security provider.
+ * @param anonymousUser
+ * The anonymous user name
+ */
+ public UserManagerImpl(SecurityProvider securityProvider,
+ String anonymousUser)
+ {
+ this.atnProviderProxy = securityProvider
+ .getAuthenticationProviderProxy();
+ this.securityMappingHandler = securityProvider
+ .getSecurityMappingHandler();
+ if (anonymousUser != null)
{
this.anonymousUser = anonymousUser;
}
}
/**
- * @param securityProvider The security provider.
- * @param roleHierarchyResolver The role hierachy resolver.
- * @param groupHierarchyResolver The group hierarchy resolver.
+ * @param securityProvider
+ * The security provider.
+ * @param roleHierarchyResolver
+ * The role hierachy resolver.
+ * @param groupHierarchyResolver
+ * The group hierarchy resolver.
*/
- public UserManagerImpl(SecurityProvider securityProvider, HierarchyResolver roleHierarchyResolver,
+ public UserManagerImpl(SecurityProvider securityProvider,
+ HierarchyResolver roleHierarchyResolver,
HierarchyResolver groupHierarchyResolver)
{
- securityProvider.getSecurityMappingHandler().setRoleHierarchyResolver(roleHierarchyResolver);
- securityProvider.getSecurityMappingHandler().setGroupHierarchyResolver(groupHierarchyResolver);
- this.atnProviderProxy = securityProvider.getAuthenticationProviderProxy();
- this.securityMappingHandler = securityProvider.getSecurityMappingHandler();
+ securityProvider.getSecurityMappingHandler().setRoleHierarchyResolver(
+ roleHierarchyResolver);
+ securityProvider.getSecurityMappingHandler().setGroupHierarchyResolver(
+ groupHierarchyResolver);
+ this.atnProviderProxy = securityProvider
+ .getAuthenticationProviderProxy();
+ this.securityMappingHandler = securityProvider
+ .getSecurityMappingHandler();
}
/**
- * @param securityProvider The security provider.
- * @param roleHierarchyResolver The role hierachy resolver.
- * @param groupHierarchyResolver The group hierarchy resolver.
- * @param anonymousUser The anonymous user name
+ * @param securityProvider
+ * The security provider.
+ * @param roleHierarchyResolver
+ * The role hierachy resolver.
+ * @param groupHierarchyResolver
+ * The group hierarchy resolver.
+ * @param anonymousUser
+ * The anonymous user name
*/
- public UserManagerImpl(SecurityProvider securityProvider, HierarchyResolver roleHierarchyResolver,
+ 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 )
+ securityProvider.getSecurityMappingHandler().setRoleHierarchyResolver(
+ roleHierarchyResolver);
+ securityProvider.getSecurityMappingHandler().setGroupHierarchyResolver(
+ groupHierarchyResolver);
+ this.atnProviderProxy = securityProvider
+ .getAuthenticationProviderProxy();
+ this.securityMappingHandler = securityProvider
+ .getSecurityMappingHandler();
+ if (anonymousUser != null)
{
this.anonymousUser = anonymousUser;
}
@@ -131,23 +157,24 @@
*/
public boolean authenticate(String username, String password)
{
- ArgUtil.notNull(new Object[] { username, password }, new String[] { "username", "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) )
+ 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
}
@@ -158,33 +185,36 @@
* @see org.apache.jetspeed.security.UserManager#addUser(java.lang.String,
* java.lang.String)
*/
- public void addUser(String username, String password) throws SecurityException
+ public void addUser(String username, String password)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { username }, new String[] { "username" },
- "addUser(java.lang.String, java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { username}, new String[]
+ { "username"}, "addUser(java.lang.String, java.lang.String)");
- addUser(username, password, atnProviderProxy.getDefaultAuthenticationProvider());
+ addUser(username, password, atnProviderProxy
+ .getDefaultAuthenticationProvider());
}
/**
* @see org.apache.jetspeed.security.UserManager#addUser(java.lang.String,
* java.lang.String, java.lang.String)
*/
- public void addUser(String username, String password, String atnProviderName) throws SecurityException
+ public void addUser(String username, String password, String atnProviderName)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { username, atnProviderName }, new String[] { "username", "atnProviderName"},
- "addUser(java.lang.String, java.lang.String, java.lang.String)");
+ 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); }
- if (getAnonymousUser().equals(username))
- {
- throw new SecurityException(SecurityException.ANONYMOUS_USER_PROTECTED);
- }
-
// Check if user already exists.
- if (userExists(username))
- {
- throw new SecurityException(SecurityException.USER_ALREADY_EXISTS + " " + username);
- }
+ if (userExists(username)) { throw new SecurityException(
+ SecurityException.USER_ALREADY_EXISTS + " " + username); }
UserPrincipal userPrincipal = new UserPrincipalImpl(username);
String fullPath = userPrincipal.getFullPath();
@@ -196,22 +226,23 @@
}
try
{
- if ((null != preferences) && preferences.absolutePath().equals(fullPath))
+ if ((null != preferences)
+ && preferences.absolutePath().equals(fullPath))
{
// Add user principal.
atnProviderProxy.addUserPrincipal(userPrincipal);
- if ( password != null )
+ if (password != null)
{
// Set private password credential
- atnProviderProxy.setPassword(username, null, password, atnProviderName);
+ atnProviderProxy.setPassword(username, null, password,
+ atnProviderName);
}
if (log.isDebugEnabled())
{
log.debug("Added user: " + fullPath);
}
}
- }
- catch (SecurityException se)
+ } catch (SecurityException se)
{
String msg = "Unable to create the user.";
log.error(msg, se);
@@ -220,8 +251,7 @@
try
{
preferences.removeNode();
- }
- catch (BackingStoreException bse)
+ } catch (BackingStoreException bse)
{
bse.printStackTrace();
}
@@ -236,12 +266,12 @@
*/
public void removeUser(String username) throws SecurityException
{
- ArgUtil.notNull(new Object[] { username }, new String[] { "username" }, "removeUser(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { username}, new String[]
+ { "username"}, "removeUser(java.lang.String)");
- if ( getAnonymousUser().equals(username) )
- {
- throw new SecurityException(SecurityException.ANONYMOUS_USER_PROTECTED);
- }
+ if (getAnonymousUser().equals(username)) { throw new SecurityException(
+ SecurityException.ANONYMOUS_USER_PROTECTED); }
UserPrincipal userPrincipal = new UserPrincipalImpl(username);
String fullPath = userPrincipal.getFullPath();
atnProviderProxy.removeUserPrincipal(userPrincipal);
@@ -250,8 +280,7 @@
try
{
preferences.removeNode();
- }
- catch (BackingStoreException bse)
+ } catch (BackingStoreException bse)
{
bse.printStackTrace();
}
@@ -262,7 +291,9 @@
*/
public boolean userExists(String username)
{
- ArgUtil.notNull(new Object[] { username }, new String[] { "username" }, "userExists(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { username}, new String[]
+ { "username"}, "userExists(java.lang.String)");
return atnProviderProxy.getUserPrincipal(username) != null;
}
@@ -272,16 +303,16 @@
*/
public User getUser(String username) throws SecurityException
{
- ArgUtil.notNull(new Object[] { username }, new String[] { "username" }, "getUser(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { username}, new String[]
+ { "username"}, "getUser(java.lang.String)");
Set principals = new HashSet();
String fullPath = (new UserPrincipalImpl(username)).getFullPath();
Principal userPrincipal = atnProviderProxy.getUserPrincipal(username);
- if (null == userPrincipal)
- {
- throw new SecurityException(SecurityException.USER_DOES_NOT_EXIST + " " + username);
- }
+ if (null == userPrincipal) { throw new SecurityException(
+ SecurityException.USER_DOES_NOT_EXIST + " " + username); }
principals.add(userPrincipal);
principals.addAll(securityMappingHandler.getRolePrincipals(username));
@@ -290,12 +321,13 @@
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);
@@ -309,7 +341,8 @@
public Iterator getUsers(String filter) throws SecurityException
{
List users = new LinkedList();
- Iterator userPrincipals = atnProviderProxy.getUserPrincipals(filter).iterator();
+ Iterator userPrincipals = atnProviderProxy.getUserPrincipals(filter)
+ .iterator();
while (userPrincipals.hasNext())
{
String username = ((Principal) userPrincipals.next()).getName();
@@ -322,14 +355,17 @@
/**
* @see org.apache.jetspeed.security.UserManager#getUsersInRole(java.lang.String)
*/
- public Collection getUsersInRole(String roleFullPathName) throws SecurityException
+ public Collection getUsersInRole(String roleFullPathName)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { roleFullPathName }, new String[] { "roleFullPathName" },
- "getUsersInRole(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { roleFullPathName}, new String[]
+ { "roleFullPathName"}, "getUsersInRole(java.lang.String)");
Collection users = new ArrayList();
- Set userPrincipals = securityMappingHandler.getUserPrincipalsInRole(roleFullPathName);
+ Set userPrincipals = securityMappingHandler
+ .getUserPrincipalsInRole(roleFullPathName);
Iterator userPrincipalsIter = userPrincipals.iterator();
while (userPrincipalsIter.hasNext())
{
@@ -342,14 +378,17 @@
/**
* @see org.apache.jetspeed.security.UserManager#getUsersInGroup(java.lang.String)
*/
- public Collection getUsersInGroup(String groupFullPathName) throws SecurityException
+ public Collection getUsersInGroup(String groupFullPathName)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { groupFullPathName }, new String[] { "groupFullPathName" },
- "getUsersInGroup(java.lang.String)");
+ ArgUtil.notNull(new Object[]
+ { groupFullPathName}, new String[]
+ { "groupFullPathName"}, "getUsersInGroup(java.lang.String)");
Collection users = new ArrayList();
- Set userPrincipals = securityMappingHandler.getUserPrincipalsInGroup(groupFullPathName);
+ Set userPrincipals = securityMappingHandler
+ .getUserPrincipalsInGroup(groupFullPathName);
Iterator userPrincipalsIter = userPrincipals.iterator();
while (userPrincipalsIter.hasNext())
{
@@ -365,45 +404,49 @@
*
* TODO Enforce that only administrators can do this.
*/
- public void setPassword(String username, String oldPassword, String newPassword) throws SecurityException
+ 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);
- }
+ 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); }
atnProviderProxy.setPassword(username, oldPassword, newPassword);
}
-
/**
- * @see org.apache.jetspeed.security.UserManager#setPasswordEnabled(java.lang.String, boolean)
+ * @see org.apache.jetspeed.security.UserManager#setPasswordEnabled(java.lang.String,
+ * boolean)
*/
- public void setPasswordEnabled(String userName, boolean enabled) throws SecurityException
+ public void setPasswordEnabled(String userName, boolean enabled)
+ throws SecurityException
{
- ArgUtil.notNull(new Object[] { userName, }, new String[] { "userName" },
- "setPasswordEnabled(java.lang.String, boolean)");
+ ArgUtil.notNull(new Object[]
+ { userName,}, new String[]
+ { "userName"}, "setPasswordEnabled(java.lang.String, boolean)");
- if ( getAnonymousUser().equals(userName) )
- {
- throw new SecurityException(SecurityException.ANONYMOUS_USER_PROTECTED);
- }
+ if (getAnonymousUser().equals(userName)) { throw new SecurityException(
+ SecurityException.ANONYMOUS_USER_PROTECTED); }
atnProviderProxy.setPasswordEnabled(userName, enabled);
}
+
/**
- * @see org.apache.jetspeed.security.UserManager#setPasswordUpdateRequired(java.lang.String, boolean)
+ * @see org.apache.jetspeed.security.UserManager#setPasswordUpdateRequired(java.lang.String,
+ * boolean)
*/
- public void setPasswordUpdateRequired(String userName, boolean updateRequired) throws SecurityException
+ public void setPasswordUpdateRequired(String userName,
+ boolean updateRequired) throws SecurityException
{
- ArgUtil.notNull(new Object[] { userName, }, new String[] { "userName" },
- "setPasswordUpdateRequired(java.lang.String, boolean)");
+ ArgUtil.notNull(new Object[]
+ { userName,}, new String[]
+ { "userName"}, "setPasswordUpdateRequired(java.lang.String, boolean)");
- if ( getAnonymousUser().equals(userName) )
- {
- throw new SecurityException(SecurityException.ANONYMOUS_USER_PROTECTED);
- }
+ if (getAnonymousUser().equals(userName)) { throw new SecurityException(
+ SecurityException.ANONYMOUS_USER_PROTECTED); }
atnProviderProxy.setPasswordUpdateRequired(userName, updateRequired);
}
}
1.12 +19 -0 jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java
Index: RoleManagerImpl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- RoleManagerImpl.java 11 Oct 2004 23:25:29 -0000 1.11
+++ RoleManagerImpl.java 22 Dec 2004 17:54:08 -0000 1.12
@@ -18,6 +18,8 @@
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;
@@ -50,6 +52,7 @@
* </p>
*
* @author <a href="mailto:dlestrat@apache.org">David Le Strat </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
*/
public class RoleManagerImpl implements RoleManager
{
@@ -376,6 +379,22 @@
}
return isGroupInRole;
+ }
+
+ /**
+ * @see org.apache.jetspeed.security.RoleManager#getRoles(java.lang.String)
+ */
+ public Iterator getRoles(String filter) throws SecurityException
+ {
+ List roles = new LinkedList();
+ Iterator rolePrincipals = roleSecurityHandler.getRolePrincipals(filter).iterator();
+ while (rolePrincipals.hasNext())
+ {
+ String roleName = ((Principal) rolePrincipals.next()).getName();
+ Role role = getRole(roleName);
+ roles.add(role);
+ }
+ return roles.iterator();
}
}
1.13 +32 -1 jakarta-jetspeed-2/components/security/src/test/org/apache/jetspeed/security/TestRoleManager.java
Index: TestRoleManager.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/test/org/apache/jetspeed/security/TestRoleManager.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- TestRoleManager.java 29 Oct 2004 14:12:28 -0000 1.12
+++ TestRoleManager.java 22 Dec 2004 17:54:08 -0000 1.13
@@ -16,6 +16,7 @@
import java.security.Principal;
import java.util.Collection;
+import java.util.Iterator;
import java.util.prefs.Preferences;
import junit.framework.Test;
@@ -594,4 +595,34 @@
}
}
+ /**
+ * <p>
+ * Test get roles.
+ * </p>
+ *
+ * @throws Exception Throws an exception.
+ */
+ public void testGetRoles() throws Exception
+ {
+ ums.addUser("notme", "one-pw");
+ gms.addGroup("g1");
+ rms.addRole("r1");
+ rms.addRole("r2");
+ rms.addRole("r3");
+ int count = 0;
+ Iterator it = rms.getRoles("");
+ while (it.hasNext())
+ {
+ Role role = (Role) it.next();
+ count++;
+ }
+ ums.removeUser("notme");
+ gms.removeGroup("g1");
+ rms.removeRole("r1");
+ rms.removeRole("r2");
+ rms.removeRole("r3");
+ assertTrue("role count should be 3", count == 3);
+
+ }
+
}
1.11 +31 -1 jakarta-jetspeed-2/components/security/src/test/org/apache/jetspeed/security/TestGroupManager.java
Index: TestGroupManager.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/security/src/test/org/apache/jetspeed/security/TestGroupManager.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TestGroupManager.java 29 Oct 2004 14:12:28 -0000 1.10
+++ TestGroupManager.java 22 Dec 2004 17:54:08 -0000 1.11
@@ -16,6 +16,7 @@
import java.security.Principal;
import java.util.Collection;
+import java.util.Iterator;
import java.util.prefs.Preferences;
import junit.framework.Test;
@@ -461,6 +462,35 @@
}
}
+ /**
+ * <p>
+ * Test get groups.
+ * </p>
+ *
+ * @throws Exception Throws an exception.
+ */
+ public void testGetGroups() throws Exception
+ {
+ ums.addUser("notme", "one-pw");
+ gms.addGroup("g1");
+ gms.addGroup("g2");
+ gms.addGroup("g3");
+ int count = 0;
+ Iterator it = gms.getGroups("");
+ while (it.hasNext())
+ {
+ Group group = (Group) it.next();
+ System.out.println("Group is " + group);
+ count++;
+ }
+ ums.removeUser("notme");
+ gms.removeGroup("g1");
+ gms.removeGroup("g2");
+ gms.removeGroup("g3");
+ assertTrue("group count should be 3", count == 3);
+
+ }
+
/**
* <p>
* Destroy group test objects.
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org