User: d_jencks
  Date: 02/03/24 13:44:31

  Added:       src/main/org/jboss/resource/security
                        ConfiguredIdentityLoginModule.java
  Log:
  New ConnectionManager implementation
  
  Revision  Changes    Path
  1.1                  
jbosscx/src/main/org/jboss/resource/security/ConfiguredIdentityLoginModule.java
  
  Index: ConfiguredIdentityLoginModule.java
  ===================================================================
  /*
   * JBoss, the OpenSource WebOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  
  package org.jboss.resource.security;
  
  
  import java.security.Principal;
  import java.security.acl.Group;
  import java.util.Map;
  import java.util.StringTokenizer;
  import javax.management.MBeanServer;
  import javax.management.ObjectName;
  import javax.resource.spi.ManagedConnectionFactory;
  import javax.resource.spi.security.PasswordCredential;
  import javax.security.auth.Subject;
  import javax.security.auth.callback.CallbackHandler;
  import javax.security.auth.login.LoginException;
  import org.jboss.security.SimpleGroup;
  import org.jboss.security.SimplePrincipal;
  import org.jboss.security.auth.spi.AbstractServerLoginModule;
  import org.jboss.util.jmx.MBeanServerLocator;
  import org.jboss.logging.Logger;
  
  /**
   * A simple login module that simply associates the principal specified
   * in the module options with any subject authenticated against the module.
   * The type of Principal class used is
   * <code>org.jboss.security.SimplePrincipal.</code>
   * <p>
   * If no principal option is specified a principal with the name of 'guest'
   * is used.
   *
   * @see org.jboss.security.SimpleGroup
   * @see org.jboss.security.SimplePrincipal
   *
   * @author [EMAIL PROTECTED]
   * @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
   * @version $Revision: 1.1 $
   */
  public class ConfiguredIdentityLoginModule extends AbstractServerLoginModule
  {
     private String principalName;
     private String userName;
     private String password;
     private ManagedConnectionFactory mcf;
  
     private static final Logger log = 
Logger.getLogger(ConfiguredIdentityLoginModule.class);
  
  
     public ConfiguredIdentityLoginModule()
     {
     }
  
     public void initialize(Subject subject, CallbackHandler handler, Map sharedState, 
Map options)
     {
        super.initialize(subject, handler, sharedState, options);
        principalName = (String) options.get("principal");
        if( principalName == null )
        {
           throw new IllegalArgumentException("Must supply a principal name!");
        }
        userName = (String) options.get("userName");
        if( principalName == null )
        {
           throw new IllegalArgumentException("Must supply a user name!");
        }
        password = (String) options.get("password");
        if( password == null )
        {
           throw new IllegalArgumentException("Must supply a password name!");
        }
        String managedConnectionFactoryName = (String) 
options.get("managedConnectionFactoryName");
        if( managedConnectionFactoryName == null )
        {
           throw new IllegalArgumentException("Must supply a 
managedConnectionFactoryName!");
        }
        MBeanServer server = MBeanServerLocator.locate();
        try 
        {
           
           mcf = (ManagedConnectionFactory)server.getAttribute(
              new ObjectName(managedConnectionFactoryName),
              "ManagedConnectionFactory");
        }
        catch (Exception e)
        {
           throw new IllegalArgumentException("Managed Connection Factory not found: " 
+ managedConnectionFactoryName);
        } // end of try-catch
        log.info("got principal: " + principalName + ", username: " + userName + ", 
password: " + password + ", mcfname: " + managedConnectionFactoryName);
  
     }
  
     public boolean login() throws LoginException
     {
        log.info("login called");
        if( super.login() == true )
           return true;
  
        Principal principal = new SimplePrincipal(principalName);
        subject.getPrincipals().add(principal);
        // Put the principal name into the sharedState map
        sharedState.put("javax.security.auth.login.name", principalName);
        PasswordCredential cred = new PasswordCredential(userName, 
password.toCharArray());
        cred.setManagedConnectionFactory(mcf);
        subject.getPrivateCredentials().add(cred);
        //???sharedState.put("javax.security.auth.login.name", principalName);
        return true;
     }
  
     protected Principal getIdentity()
     {
        log.info("getIdentity called");
        Principal principal = new SimplePrincipal(principalName);
        return principal;
     }
  
     
     protected Group[] getRoleSets() throws LoginException
     {
        log.info("getRoleSets called");
        return new Group[] {};
        /*
        SimpleGroup roles = new SimpleGroup("Roles");
        Group[] roleSets = {roles};
        if( roleNames != null )
        {
           StringTokenizer tokenizer = new StringTokenizer(roleNames, ",");
           while( tokenizer.hasMoreTokens() )
           {
              String roleName = tokenizer.nextToken();
              roles.addMember(new SimplePrincipal(roleName));
           }
        }
        return roleSets;
        */
     }
     
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to