1 7 package org.jboss.security.auth.spi; 8 9 import java.io.IOException ; 10 import java.security.acl.Group ; 11 import java.util.Map ; 12 import java.util.Properties ; 13 14 import javax.security.auth.Subject ; 15 import javax.security.auth.callback.CallbackHandler ; 16 import javax.security.auth.login.LoginException ; 17 18 29 public class CertRolesLoginModule extends BaseCertLoginModule 30 { 31 32 private String defaultRolesRsrcName = "defaultRoles.properties"; 33 36 private String rolesRsrcName = "roles.properties"; 37 40 private Properties roles; 41 44 private char roleGroupSeperator = '.'; 45 46 private boolean trace; 47 48 62 public void initialize(Subject subject, CallbackHandler callbackHandler, 63 Map sharedState, Map options) 64 { 65 super.initialize(subject, callbackHandler, sharedState, options); 66 trace = log.isTraceEnabled(); 67 if( trace ) 68 log.trace("enter: initialize(Subject, CallbackHandler, Map, Map)"); 69 70 try 71 { 72 String option = (String ) options.get("rolesProperties"); 73 if (option != null) 74 rolesRsrcName = option; 75 option = (String ) options.get("defaultRolesProperties"); 76 if (option != null) 77 defaultRolesRsrcName = option; 78 option = (String ) options.get("roleGroupSeperator"); 79 if( option != null ) 80 roleGroupSeperator = option.charAt(0); 81 loadRoles(); 83 } 84 catch (Exception e) 85 { 86 super.log.error("Failed to load users/passwords/role files", e); 89 } 90 91 if( trace ) 92 log.trace("exit: initialize(Subject, CallbackHandler, Map, Map)"); 93 } 94 95 public boolean login() throws LoginException 96 { 97 if( trace ) 98 log.trace("enter: login()"); 99 100 if (roles == null) 101 throw new LoginException ("Missing roles.properties file."); 102 boolean wasSuccessful = super.login(); 103 104 if( trace ) 105 log.trace("exit: login()"); 106 107 return wasSuccessful; 108 } 109 110 114 protected Group [] getRoleSets() throws LoginException 115 { 116 if( trace ) 117 log.trace("enter: getRoleSets()"); 118 String targetUser = getUsername(); 119 Group [] roleSets = Util.getRoleSets(targetUser, roles, roleGroupSeperator, this); 120 if( trace ) 121 log.trace("exit: getRoleSets()"); 122 return roleSets; 123 } 124 125 private void loadRoles() throws IOException 126 { 127 roles = Util.loadProperties(defaultRolesRsrcName, rolesRsrcName, log); 128 } 129 130 } 131 | Popular Tags |