1 22 package org.jboss.resource.security; 23 24 25 import java.security.Principal ; 26 import java.security.acl.Group ; 27 import java.util.Map ; 28 29 import javax.resource.spi.security.PasswordCredential ; 30 import javax.security.auth.Subject ; 31 import javax.security.auth.callback.CallbackHandler ; 32 import javax.security.auth.login.LoginException ; 33 34 import org.jboss.logging.Logger; 35 import org.jboss.security.SimplePrincipal; 36 37 53 public class ConfiguredIdentityLoginModule extends AbstractPasswordCredentialLoginModule 54 { 55 private String principalName; 56 private String userName; 57 private String password; 58 59 private static final Logger log = Logger.getLogger(ConfiguredIdentityLoginModule.class); 60 61 62 public ConfiguredIdentityLoginModule() 63 { 64 } 65 66 public void initialize(Subject subject, CallbackHandler handler, Map sharedState, Map options) 67 { 68 super.initialize(subject, handler, sharedState, options); 69 principalName = (String ) options.get("principal"); 70 if( principalName == null ) 71 { 72 throw new IllegalArgumentException ("Must supply a principal name!"); 73 } 74 userName = (String ) options.get("userName"); 75 if( userName == null ) 76 { 77 throw new IllegalArgumentException ("Must supply a user name!"); 78 } 79 password = (String ) options.get("password"); 80 if( password == null ) 81 { 82 log.warn("Creating LoginModule with no configured password!"); 83 password = ""; 84 } 85 log.trace("got principal: " + principalName + ", username: " + userName + ", password: " + password); 86 87 } 88 89 public boolean login() throws LoginException 90 { 91 log.trace("login called"); 92 if( super.login() == true ) 93 return true; 94 95 Principal principal = new SimplePrincipal(principalName); 96 SubjectActions.addPrincipals(subject, principal); 97 sharedState.put("javax.security.auth.login.name", principalName); 99 PasswordCredential cred = new PasswordCredential (userName, password.toCharArray()); 100 cred.setManagedConnectionFactory(getMcf()); 101 SubjectActions.addCredentials(subject, cred); 102 super.loginOk = true; 103 return true; 104 } 105 106 protected Principal getIdentity() 107 { 108 log.trace("getIdentity called"); 109 Principal principal = new SimplePrincipal(principalName); 110 return principal; 111 } 112 113 116 protected Group [] getRoleSets() throws LoginException 117 { 118 log.trace("getRoleSets called"); 119 return new Group [] {}; 120 } 121 122 } 123 | Popular Tags |