public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) {
debug = "true".equalsIgnoreCase((String) options.get("debug"));
String uri = (String) options.get("uri");
String realm = (String) options.get("realm");
if (uri == null) throw new GeronimoSecurityException("Initialize error: uri to security service is not set");
if (realm == null) throw new GeronimoSecurityException("Initialize error: realm name not specified");
try {
connectURI = new URI(uri);
remoteLoginService = RemoteLoginServiceFactory.create(connectURI.getHost(), connectURI.getPort());
SerializableACE[] entries = remoteLoginService.getAppConfigurationEntries(realm);
modules = new LoginModuleConfiguration[entries.length];
for(int i = 0; i < entries.length; i++) {
SerializableACE entry = entries[i];
final String finalClass = entry.getLoginModuleName();
LoginModule wrapper;
wrapper = (LoginModule) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
return Class.forName(finalClass, true, classLoader).newInstance();
}
});
HashMap map = new HashMap(entry.getOptions());
map.put(LOGIN_SERVICE, remoteLoginService);
wrapper.initialize(subject, callbackHandler, sharedState, map);
modules[i] = new LoginModuleConfiguration(wrapper, entry.getControlFlag());
}
if (debug) {
System.out.print("[GeronimoLoginModule] Debug is " + debug + " uri " + uri + " realm " + realm + "\n");
}
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof InstantiationException) {
throw (GeronimoSecurityException) new GeronimoSecurityException("Initialize error:" + e.getCause().getMessage()).initCause(e.getCause());
} else {
throw (GeronimoSecurityException) new GeronimoSecurityException("Initialize error: " + e.toString()).initCause(e);
}
} catch (URISyntaxException e) {
throw (GeronimoSecurityException) new GeronimoSecurityException("Initialize error: " + e.toString()).initCause(e);
}
}