package org.jboss.security.auth.spi;
import java.io.IOException;
import java.security.acl.Group;
import java.util.Map;
import java.util.Properties;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
public class CertRolesLoginModule extends BaseCertLoginModule
{
private String defaultRolesRsrcName = "defaultRoles.properties";
private String rolesRsrcName = "roles.properties";
private Properties roles;
private char roleGroupSeperator = '.';
private boolean trace;
public void initialize(Subject subject, CallbackHandler callbackHandler,
Map sharedState, Map options)
{
super.initialize(subject, callbackHandler, sharedState, options);
trace = log.isTraceEnabled();
if( trace )
log.trace("enter: initialize(Subject, CallbackHandler, Map, Map)");
try
{
String option = (String) options.get("rolesProperties");
if (option != null)
rolesRsrcName = option;
option = (String) options.get("defaultRolesProperties");
if (option != null)
defaultRolesRsrcName = option;
option = (String) options.get("roleGroupSeperator");
if( option != null )
roleGroupSeperator = option.charAt(0);
loadRoles();
}
catch (Exception e)
{
super.log.error("Failed to load users/passwords/role files", e);
}
if( trace )
log.trace("exit: initialize(Subject, CallbackHandler, Map, Map)");
}
public boolean login() throws LoginException
{
if( trace )
log.trace("enter: login()");
if (roles == null)
throw new LoginException("Missing roles.properties file.");
boolean wasSuccessful = super.login();
if( trace )
log.trace("exit: login()");
return wasSuccessful;
}
protected Group[] getRoleSets() throws LoginException
{
if( trace )
log.trace("enter: getRoleSets()");
String targetUser = getUsername();
Group[] roleSets = Util.getRoleSets(targetUser, roles, roleGroupSeperator, this);
if( trace )
log.trace("exit: getRoleSets()");
return roleSets;
}
private void loadRoles() throws IOException
{
roles = Util.loadProperties(defaultRolesRsrcName, rolesRsrcName, log);
}
}