LoginModuleCacheObject lm = null;
synchronized (LoginService.class) {
try {
for (Iterator iter = getRealms().iterator(); iter.hasNext();) {
SecurityRealm securityRealm = (SecurityRealm) iter.next();
if (realmName.equals(securityRealm.getRealmName())) {
AppConfigurationEntry[] entries = securityRealm.getAppConfigurationEntries();
Subject subject = new Subject();
CallbackProxy callback = new CallbackProxy();
LoginModuleConfiguration[] modules = new LoginModuleConfiguration[entries.length];
for(int i = 0; i < entries.length; i++) {
AppConfigurationEntry entry = entries[i];
final String finalClass = entry.getLoginModuleName();
LoginModule module = (LoginModule) AccessController.doPrivileged(new java.security.PrivilegedExceptionAction() {
public Object run() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
return Class.forName(finalClass, true, classLoader).newInstance();
}
});
module.initialize(subject, callback, new HashMap(), entry.getOptions());
modules[i] = new LoginModuleConfiguration(module, LoginModuleControlFlag.getInstance(entry.getControlFlag()));
}
lm = allocateLoginModuleCacheObject(securityRealm.getMaxLoginModuleAge());
lm.setRealmName(realmName);
lm.setLoginModules(modules);
lm.setSubject(subject);
lm.setCallbackHandler(callback);
log.trace("LoginModule [" + lm.getLoginModuleId() + "] created for realm " + realmName);