}
} else {
SecurityRealm realm = (SecurityRealm) PortletManager.getManagedBean(request, new AbstractName(URI.create(data.getAbstractName())));
// index existing modules
Map nodes = new HashMap();
JaasLoginModuleChain node = realm.getLoginModuleChain();
while (node != null) {
LoginModuleSettings module = node.getLoginModule();
nodes.put(module.getLoginDomainName(), node);
node = node.getNext();
if (node == null) {
break;
}
}
// apply settings
for (int i = 0; i < data.getModules().length; i++) {
LoginModuleDetails details = data.getModules()[i];
node = (JaasLoginModuleChain)PortletManager.getManagedBean(request, PortletManager.getNameFor(request, nodes.get(details.getLoginDomainName())));
node.setControlFlag(details.getControlFlag());
LoginModuleSettings module =(LoginModuleSettings)PortletManager.getManagedBean(request, PortletManager.getNameFor(request, node.getLoginModule()));
module.setOptions(details.getOptions());
module.setWrapPrincipals(details.isWrapPrincipals());
module.setLoginModuleClass(details.getClassName());
}
}