1 7 package org.jboss.security.auth.spi; 8 9 import java.security.acl.Group ; 10 import java.util.Map ; 11 import javax.security.auth.Subject ; 12 import javax.security.auth.callback.CallbackHandler ; 13 import javax.security.auth.login.LoginException ; 14 15 52 public class XMLLoginModule extends UsernamePasswordLoginModule 53 { 54 55 private Users users; 56 57 62 public void initialize(Subject subject, CallbackHandler callbackHandler, 63 Map sharedState, Map options) 64 { 65 super.initialize(subject, callbackHandler, sharedState, options); 66 try 67 { 68 users = (Users) options.get("userInfo"); 69 } 70 catch (Exception e) 71 { 72 super.log.error("Failed to load users/passwords/role files", e); 75 } 76 } 77 78 84 public boolean login() throws LoginException 85 { 86 if (users == null) 87 throw new LoginException ("Missing usersInfo user/role mapping"); 88 89 return super.login(); 90 } 91 92 95 protected Group [] getRoleSets() throws LoginException 96 { 97 String targetUser = getUsername(); 98 Users.User user = users.getUser(targetUser); 99 Group [] roleSets = {}; 100 if( user != null ) 101 roleSets = user.getRoleSets(); 102 103 return roleSets; 104 } 105 106 protected String getUsersPassword() 107 { 108 String username = getUsername(); 109 Users.User user = users.getUser(username); 110 String password = null; 111 if (user != null) 112 { 113 password = user.getPassword(); 114 } 115 116 return password; 117 } 118 119 } 120 | Popular Tags |