From: Julien V. <ju...@jb...> - 2006-02-24 23:07:44
|
User: julien Date: 06/02/24 18:07:42 Modified: core/src/main/org/jboss/portal/core/security/jaas ModelLoginModule.java Log: remove the getRoleNames from the interface RoleModule as the role name set can be contructed from the set of roles Revision Changes Path 1.6 +23 -7 jboss-portal/core/src/main/org/jboss/portal/core/security/jaas/ModelLoginModule.java (In the diff below, changes in quantity of whitespace are not shown.) Index: ModelLoginModule.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/core/src/main/org/jboss/portal/core/security/jaas/ModelLoginModule.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -b -r1.5 -r1.6 --- ModelLoginModule.java 22 Feb 2006 18:22:55 -0000 1.5 +++ ModelLoginModule.java 24 Feb 2006 23:07:42 -0000 1.6 @@ -39,6 +39,7 @@ import org.jboss.portal.core.modules.RoleModule; import org.jboss.portal.core.model.User; import org.jboss.portal.core.model.NoSuchUserException; +import org.jboss.portal.core.model.Role; import org.jboss.security.SimpleGroup; import org.jboss.security.auth.spi.UsernamePasswordLoginModule; @@ -46,7 +47,7 @@ * A login module that uses the user module. * * @author <a href="mailto:ju...@jb...">Julien Viet</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ public class ModelLoginModule extends UsernamePasswordLoginModule @@ -117,12 +118,26 @@ try { User user = getUserModule().findUserByUserName(getUsername()); - Set roleNames = getRoleModule().getRoleNames(user); - if (havingRole == null || roleNames.contains(havingRole)) + if (havingRole != null) { - return Boolean.valueOf(user.validatePassword(inputPassword)); + boolean hasTheRole = false; + Set roles = getRoleModule().getRoleNames(user); + for (Iterator i = roles.iterator(); i.hasNext();) + { + Role role = (Role)i.next(); + if (havingRole.equals(role.getName())) + { + hasTheRole = true; + break; } } + if (!hasTheRole) + { + return Boolean.FALSE; + } + } + return Boolean.valueOf(user.validatePassword(inputPassword)); + } catch (NoSuchUserException e) { } @@ -159,7 +174,7 @@ try { User user = getUserModule().findUserByUserName(getUsername()); - Set roleNames = getRoleModule().getRoleNames(user); + Set roles = getRoleModule().getRoles(user); // Group rolesGroup = new SimpleGroup("Roles"); @@ -171,9 +186,10 @@ } // - for (Iterator iterator = roleNames.iterator(); iterator.hasNext();) + for (Iterator iterator = roles.iterator(); iterator.hasNext();) { - String roleName = (String)iterator.next(); + Role role = (Role)iterator.next(); + String roleName = role.getName(); try { Principal p = createIdentity(roleName); |