package org.jboss.security.auth.spi;
import java.util.Map;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;
public class ProxyLoginModule implements LoginModule
{
private String moduleName;
private LoginModule delegate;
public ProxyLoginModule()
{
}
public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options)
{
moduleName = (String) options.get("moduleName");
if( moduleName == null )
{
System.out.println("Required moduleName option not given");
return;
}
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try
{
Class clazz = loader.loadClass(moduleName);
delegate = (LoginModule) clazz.newInstance();
}
catch(Throwable t)
{
System.out.println("ProxyLoginModule failed to load: "+moduleName);
t.printStackTrace();
return;
}
delegate.initialize(subject, callbackHandler, sharedState, options);
}
public boolean login() throws LoginException
{
if( moduleName == null )
throw new LoginException("Required moduleName option not given");
if( delegate == null )
throw new LoginException("Failed to load LoginModule: "+moduleName);
return delegate.login();
}
public boolean commit() throws LoginException
{
boolean ok = false;
if( delegate != null )
ok = delegate.commit();
return ok;
}
public boolean abort() throws LoginException
{
boolean ok = true;
if( delegate != null )
ok = delegate.abort();
return ok;
}
public boolean logout() throws LoginException
{
boolean ok = true;
if( delegate != null )
ok = delegate.logout();
return ok;
}
}