[jboss-cvs] jboss-seam/src/main/org/jboss/seam/security/jaas ...
Shane Bryzak
Shane_Bryzak at symantec.com
Sun Feb 4 04:36:55 EST 2007
User: sbryzak2
Date: 07/02/04 04:36:55
Modified: src/main/org/jboss/seam/security/jaas SeamLoginModule.java
Log:
Simplified authentication model
Revision Changes Path
1.3 +27 -59 jboss-seam/src/main/org/jboss/seam/security/jaas/SeamLoginModule.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SeamLoginModule.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/jaas/SeamLoginModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- SeamLoginModule.java 31 Jan 2007 00:16:58 -0000 1.2
+++ SeamLoginModule.java 4 Feb 2007 09:36:55 -0000 1.3
@@ -19,7 +19,6 @@
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.SimpleGroup;
import org.jboss.seam.security.SimplePrincipal;
-import org.jboss.seam.util.Reflections;
/**
* Performs authentication using a Seam component
@@ -28,8 +27,6 @@
*/
public class SeamLoginModule implements LoginModule
{
- private static final String OPTS_PARAM_TYPES = "paramTypes";
-
private static final LogProvider log = Logging.getLogProvider(SeamLoginModule.class);
protected Set<String> roles = new HashSet<String>();
@@ -49,7 +46,19 @@
{
subject.getPrincipals().add(new SimplePrincipal(username));
- Group roleGroup = new SimpleGroup("roles");
+ Group roleGroup = null;
+
+ for ( Group g : subject.getPrincipals(Group.class) )
+ {
+ if ( "roles".equals( g.getName() ) )
+ {
+ roleGroup = g;
+ break;
+ }
+ }
+
+ if (roleGroup == null) roleGroup = new SimpleGroup("roles");
+
for (String role : roles)
{
roleGroup.addMember(new SimplePrincipal(role));
@@ -71,73 +80,32 @@
public boolean login()
throws LoginException
{
- MethodBinding mb = Identity.instance().getAuthenticateMethod();
-
- Object[] params = null;
-
try
{
- params = getLoginParams();
+ NameCallback cbName = new NameCallback("Enter username");
+ PasswordCallback cbPassword = new PasswordCallback("Enter password", false);
+
+ // Get the username and password from the callback handler
+ callbackHandler.handle(new Callback[] { cbName, cbPassword });
+ username = cbName.getName();
}
- catch (Exception e)
+ catch (Exception ex)
{
- log.error("Error logging in", e);
- throw new LoginException(e.getMessage());
+ log.error("Error logging in", ex);
+ return false;
}
+ MethodBinding mb = Identity.instance().getAuthenticateMethod();
+
try
{
- return (Boolean) mb.invoke(getLoginParamTypes(), params);
+ return (Boolean) mb.invoke();
}
catch (RuntimeException ex)
{
log.error("Error invoking login method", ex);
return false;
}
- catch (ClassNotFoundException ex)
- {
- log.error("Error determining parameter types", ex);
- return false;
- }
- }
-
- /**
- * Returns the authentication method param types as a Class array.
- *
- * @throws ClassNotFoundException
- */
- public Class[] getLoginParamTypes()
- throws ClassNotFoundException
- {
- if (!options.containsKey(OPTS_PARAM_TYPES))
- return new Class[] {String.class, String.class, Set.class };
-
- String[] paramTypes = ((String) options.get(OPTS_PARAM_TYPES)).split("[,]");
- Class[] types = new Class[paramTypes.length];
- for (int i = 0; i < paramTypes.length; i++)
- types[i] = Reflections.classForName(paramTypes[i].trim());
-
- return types;
- }
-
- /**
- * Override this method if this isn't a standard username/password-based
- * authentication.
- *
- * @throws Exception
- */
- public Object[] getLoginParams()
- throws Exception
- {
- NameCallback cbName = new NameCallback("Enter username");
- PasswordCallback cbPassword = new PasswordCallback("Enter password", false);
-
- // Get the username and password from the callback handler
- callbackHandler.handle(new Callback[] { cbName, cbPassword });
- username = cbName.getName();
-
- return new Object[] { username, new String(cbPassword.getPassword()),
- roles };
}
public boolean logout() throws LoginException
More information about the jboss-cvs-commits
mailing list