Collection errors = new ArrayList();
xmlOptions.setErrorListener(errors);
if (!loginConfig.validate(xmlOptions)) {
throw new DeploymentException("Invalid login configuration:\n" + errors + "\nDescriptor: " + loginConfig.toString());
}
XmlCursor xmlCursor = loginConfig.newCursor();
ObjectName nextName = null;
try {
boolean atStart = true;
while ((atStart && xmlCursor.toFirstChild()) || (!atStart && xmlCursor.toNextSibling())) {
atStart = false;
XmlObject child = xmlCursor.getObject();
GerAbstractLoginModuleType abstractLoginModule = (GerAbstractLoginModuleType) child;
String controlFlag = abstractLoginModule.getControlFlag().toString();
ObjectName loginModuleName;
String name;
if (abstractLoginModule instanceof GerLoginModuleRefType) {
GerLoginModuleRefType loginModuleRef = (GerLoginModuleRefType) abstractLoginModule;
String domain = trim(loginModuleRef.getDomain());
String server = trim(loginModuleRef.getServer());
String application = trim(loginModuleRef.getApplication());
String module = trim(loginModuleRef.getModule());
String type = trim(loginModuleRef.getType());
if (type == null) {
type = NameFactory.LOGIN_MODULE;
}
name = trim(loginModuleRef.getName());
try {
loginModuleName = NameFactory.getComponentName(domain, server, application, module, name, type, j2eeContext);
} catch (MalformedObjectNameException e) {
throw new DeploymentException("cannot construct login module name from parts,", e);
}
} else if (abstractLoginModule instanceof GerLoginModuleType) {
//create the LoginModuleGBean also
name = null;
loginModuleName = null;
GerLoginModuleType loginModule = (GerLoginModuleType) abstractLoginModule;
name = trim(loginModule.getLoginDomainName());
String className = trim(loginModule.getLoginModuleClass());
boolean serverSide = loginModule.getServerSide();
Properties options = new Properties();
GerOptionType[] optionArray = loginModule.getOptionArray();
for (int j = 0; j < optionArray.length; j++) {
GerOptionType gerOptionType = optionArray[j];
String key = gerOptionType.getName();
String value = trim(gerOptionType.getStringValue());
options.setProperty(key, value);
}
try {
loginModuleName = NameFactory.getComponentName(null, null, null, null, name, NameFactory.LOGIN_MODULE, j2eeContext);
} catch (MalformedObjectNameException e) {
throw new DeploymentException("cannot construct login module use name from parts,", e);
}
GBeanData loginModuleGBeanData = new GBeanData(loginModuleName, LoginModuleGBean.GBEAN_INFO);
loginModuleGBeanData.setAttribute("loginDomainName", name);
loginModuleGBeanData.setAttribute("loginModuleClass", className);
loginModuleGBeanData.setAttribute("options", options);
loginModuleGBeanData.setAttribute("serverSide", new Boolean(serverSide));
context.addGBean(loginModuleGBeanData);
} else {
throw new DeploymentException("Unknown abstract login module type: " + abstractLoginModule.getClass());
}
ObjectName thisName;
try {
thisName = NameFactory.getComponentName(null, null, null, null, name, "LoginModuleUse", j2eeContext);
} catch (MalformedObjectNameException e) {
throw new DeploymentException("cannot construct login module use name from parts,", e);
}
GBeanData loginModuleUseGBeanData = new GBeanData(thisName, JaasLoginModuleUse.GBEAN_INFO);
loginModuleUseGBeanData.setAttribute("controlFlag", controlFlag);
loginModuleUseGBeanData.setReferencePattern("LoginModule", loginModuleName);
if (nextName != null) {
loginModuleUseGBeanData.setReferencePattern("Next", nextName);
}
context.addGBean(loginModuleUseGBeanData);
nextName = thisName;
}
} finally {
xmlCursor.dispose();
}
return Collections.singleton(nextName);
}