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

AbstractPasswordCredentialLoginModule

public abstract class AbstractPasswordCredentialLoginModule extends org.jboss.security.auth.spi.AbstractServerLoginModule
A base login module that provides access to the ManagedConnectionFactory needed by the PasswordCredential.
see
javax.resource.spi.security.PasswordCredential
author
David Jencks
author
Scott.Stark@jboss.org
version
$Revision: 57189 $

Fields Summary
private static final Logger
log
private MBeanServer
server
private ObjectName
managedConnectionFactoryName
private javax.resource.spi.ManagedConnectionFactory
mcf
private Boolean
ignoreMissigingMCF
A flag that allows a missing MCF service to be ignored
Constructors Summary
public AbstractPasswordCredentialLoginModule()


    
   
      
   
Methods Summary
protected javax.resource.spi.ManagedConnectionFactorygetMcf()

      if (mcf == null)
      {
         try
         {
            mcf = (ManagedConnectionFactory) server.getAttribute(
               managedConnectionFactoryName,
               "ManagedConnectionFactory");
         }
         catch (Exception e)
         {
            log.error("The ConnectionManager mbean: " + managedConnectionFactoryName
               + " specified in a ConfiguredIdentityLoginModule could not be found."
               + " ConnectionFactory will be unusable!");
            if( Boolean.TRUE != ignoreMissigingMCF )
            {
               throw new IllegalArgumentException("Managed Connection Factory not found: "
                  + managedConnectionFactoryName);
            }
         } // end of try-catch
         if (log.isTraceEnabled())
         {
            log.trace("mcfname: " + managedConnectionFactoryName);
         }
      } // end of if ()

      return mcf;
   
protected javax.management.MBeanServergetServer()

      return server;
   
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);
      String name = (String) options.get("managedConnectionFactoryName");
      try
      {
         managedConnectionFactoryName = new ObjectName(name);
      }
      catch (MalformedObjectNameException mone)
      {
         throw new IllegalArgumentException("Malformed ObjectName: " + name);
      }

      if (managedConnectionFactoryName == null)
      {
         throw new IllegalArgumentException("Must supply a managedConnectionFactoryName!");
      }
      Object flag = options.get("ignoreMissigingMCF");
      if( flag instanceof Boolean )
         ignoreMissigingMCF = (Boolean) flag;
      else if( flag != null )
         ignoreMissigingMCF = Boolean.valueOf(flag.toString());
      server = MBeanServerLocator.locateJBoss();
      getMcf();
   
public booleanlogin()
Return false if there is no mcf, else return super.login(). Override to provide custom authentication.

return
false if there is no mcf, else return super.login().
exception
LoginException if an error occurs

      if (mcf == null)
      {
         return false;
      }
      return super.login();
   
public booleanlogout()

      removeCredentials();
      return super.logout();
   
protected voidremoveCredentials()
This removes the javax.security.auth.login.name and javax.security.auth.login.password settings from the sharteState map along with any PasswordCredential found in the PrivateCredentials set

      sharedState.remove("javax.security.auth.login.name");
      sharedState.remove("javax.security.auth.login.password");
      SubjectActions.removeCredentials(subject, mcf);