1 7 package org.jboss.security.auth.spi; 8 9 import java.io.IOException ; 10 import java.util.Map ; 11 import java.util.Properties ; 12 13 import java.security.acl.Group ; 14 import javax.security.auth.Subject ; 15 import javax.security.auth.callback.CallbackHandler ; 16 import javax.security.auth.login.LoginException ; 17 18 50 public class UsersRolesLoginModule extends UsernamePasswordLoginModule 51 { 52 53 private String defaultUsersRsrcName = "defaultUsers.properties"; 54 55 private String defaultRolesRsrcName = "defaultRoles.properties"; 56 57 private String usersRsrcName = "users.properties"; 58 59 private String rolesRsrcName = "roles.properties"; 60 61 private Properties users; 62 63 private Properties roles; 64 67 private char roleGroupSeperator = '.'; 68 69 89 public void initialize(Subject subject, CallbackHandler callbackHandler, 90 Map sharedState, Map options) 91 { 92 super.initialize(subject, callbackHandler, sharedState, options); 93 try 94 { 95 String option = (String ) options.get("usersProperties"); 97 if (option != null) 98 usersRsrcName = option; 99 option = (String ) options.get("defaultUsersProperties"); 100 if (option != null) 101 defaultUsersRsrcName = option; 102 option = (String ) options.get("rolesProperties"); 103 if (option != null) 104 rolesRsrcName = option; 105 option = (String ) options.get("defaultRolesProperties"); 106 if (option != null) 107 defaultRolesRsrcName = option; 108 option = (String ) options.get("roleGroupSeperator"); 109 if( option != null ) 110 roleGroupSeperator = option.charAt(0); 111 users = createUsers(options); 113 roles = createRoles(options); 114 } 115 catch (Exception e) 116 { 117 120 super.log.error("Failed to load users/passwords/role files", e); 121 } 122 } 123 124 130 public boolean login() throws LoginException 131 { 132 if (users == null) 133 throw new LoginException ("Missing users.properties file."); 134 if (roles == null) 135 throw new LoginException ("Missing roles.properties file."); 136 137 return super.login(); 138 } 139 140 145 protected Group [] getRoleSets() throws LoginException 146 { 147 String targetUser = getUsername(); 148 Group [] roleSets = Util.getRoleSets(targetUser, roles, roleGroupSeperator, this); 149 return roleSets; 150 } 151 152 protected String getUsersPassword() 153 { 154 String username = getUsername(); 155 String password = null; 156 if (username != null) 157 password = users.getProperty(username, null); 158 return password; 159 } 160 161 163 169 protected void loadUsers() throws IOException 170 { 171 users = Util.loadProperties(defaultUsersRsrcName, usersRsrcName, log); 172 } 173 183 protected Properties createUsers(Map options) throws IOException 184 { 185 loadUsers(); 186 return this.users; 187 } 188 189 195 protected void loadRoles() throws IOException 196 { 197 roles = Util.loadProperties(defaultRolesRsrcName, rolesRsrcName, log); 198 } 199 209 protected Properties createRoles(Map options) throws IOException 210 { 211 loadRoles(); 212 return this.roles; 213 } 214 215 224 protected void parseGroupMembers(Group group, String roles) 225 { 226 Util.parseGroupMembers(group, roles, this); 227 } 228 229 } 230 | Popular Tags |