FileDocCategorySizeDatePackage
JaasSecurityDomainIdentityLoginModule.javaAPI DocJBoss 4.2.17656Fri Jul 13 21:01:18 BST 2007org.jboss.resource.security

JaasSecurityDomainIdentityLoginModule

public class JaasSecurityDomainIdentityLoginModule extends AbstractPasswordCredentialLoginModule
A login module for statically defining a data source username and password that uses a password that has been ecrypted by a JaasSecurityDomain. The base64 format of the data source password may be generated using the PBEUtils command: java -cp jbosssx.jar org.jboss.security.plugins.PBEUtils salt count domain-password data-source-password salt : the Salt attribute from the JaasSecurityDomain count : the IterationCount attribute from the JaasSecurityDomain domain-password : the plaintext password that maps to the KeyStorePass attribute from the JaasSecurityDomain data-source-password : the plaintext password for the data source that should be encrypted with the JaasSecurityDomain password for example: java -cp jbosssx.jar org.jboss.security.plugins.PBEUtils abcdefgh 13 master '' Encoded password: E5gtGMKcXPP A sample login-config.xml configuration entry would be: sa E5gtGMKcXPP jboss.jca:service=LocalTxCM,name=DefaultDS jboss.security:service=JaasSecurityDomain,domain=ServerMasterPassword
author
Scott.Stark@jboss.org
author
Noel Rocher 29, june 2004 username & userName issue
version
$Revision: 57189 $

Fields Summary
private static final Logger
log
private String
username
private String
password
private ObjectName
jaasSecurityDomain
Constructors Summary
Methods Summary
public booleanabort()

      username = null;
      password = null;
      return true;
   
public booleancommit()

      Principal principal = new SimplePrincipal(username);
      SubjectActions.addPrincipals(subject, principal);
      sharedState.put("javax.security.auth.login.name", username);
      // Decode the encrypted password
      try
      {
         char[] decodedPassword = DecodeAction.decode(password,
            jaasSecurityDomain, getServer());
         PasswordCredential cred = new PasswordCredential(username, decodedPassword);
         cred.setManagedConnectionFactory(getMcf());
         SubjectActions.addCredentials(subject, cred);
      }
      catch(Exception e)
      {
         log.debug("Failed to decode password", e);
         throw new LoginException("Failed to decode password: " + e.getMessage());
      }
      return true;
   
protected java.security.PrincipalgetIdentity()

      log.trace("getIdentity called, username=" + username);
      Principal principal = new SimplePrincipal(username);
      return principal;
   
protected java.security.acl.Group[]getRoleSets()

      Group[] empty = new Group[0];
      return empty;
   
public voidinitialize(javax.security.auth.Subject subject, javax.security.auth.callback.CallbackHandler handler, java.util.Map sharedState, java.util.Map options)


        
         
   
      super.initialize(subject, handler, sharedState, options);
      // NR : we keep this username for compatibility
      username = (String) options.get("username");
      if( username == null )
      {
      	// NR : try with userName
        username = (String) options.get("userName");      	
        if( username == null )
        {
         throw new IllegalArgumentException("The user name is a required option");
        }
     }

      password = (String) options.get("password");
      if( password == null )
      {
         throw new IllegalArgumentException("The password is a required option");
      }

      String name = (String) options.get("jaasSecurityDomain");
      if( name == null )
      {
         throw new IllegalArgumentException("The jaasSecurityDomain is a required option");
      }

      try
      {
         jaasSecurityDomain = new ObjectName(name);
      }
      catch(Exception e)
      {
         throw new IllegalArgumentException("Invalid jaasSecurityDomain: " + e.getMessage());
      }
   
public booleanlogin()

      log.trace("login called");
      if( super.login() == true )
         return true;

      super.loginOk = true;
      return true;