//Was a virtual server defined?
String virtualServer = ctx.getVirtualServer();
if (virtualServer == null) {
virtualServer = engine.getDefaultHost();
}
Container host = engine.findChild(virtualServer);
if (host == null) {
throw new IllegalArgumentException("Invalid virtual host '" + virtualServer + "'. Do you have a matching Host entry in the plan?");
}
//Get the security-realm-name if there is one
String securityRealmName = null;
SecurityHolder secHolder = ctx.getSecurityHolder();
if (secHolder != null)
securityRealmName = secHolder.getSecurityRealm();
//Did we declare a GBean at the context level?
if (ctx.getRealm() != null) {
Realm realm = ctx.getRealm();
//Allow for the <security-realm-name> override from the
//geronimo-web.xml file to be used if our Realm is a JAAS type
if (securityRealmName != null) {
if (realm instanceof JAASRealm) {
((JAASRealm) realm).setAppName(securityRealmName);
}
}
anotherCtxObj.setRealm(realm);
} else {
Realm realm = host.getRealm();
//Check and see if we have a declared realm name and no match to a parent name
if (securityRealmName != null) {
String parentRealmName = null;
if (realm instanceof JAASRealm) {
parentRealmName = ((JAASRealm) realm).getAppName();
}
//Do we have a match to a parent?
if (!securityRealmName.equals(parentRealmName)) {
//No...we need to create a default adapter
//Is the context requiring JACC?
if (secHolder.isSecurity()) {
//JACC
realm = new TomcatGeronimoRealm();
} else {
//JAAS
realm = new TomcatJAASRealm();
}
log.debug("The security-realm-name '" + securityRealmName +
"' was specified and a parent (Engine/Host) is not named the same or no RealmGBean was configured for this context. " +
"Creating a default " + realm.getClass().getName() +
" adapter for this context.");
((JAASRealm) realm).setUserClassNames("org.apache.geronimo.security.realm.providers.GeronimoUserPrincipal");
((JAASRealm) realm).setRoleClassNames("org.apache.geronimo.security.realm.providers.GeronimoGroupPrincipal");
((JAASRealm) realm).setAppName(securityRealmName);
anotherCtxObj.setRealm(realm);
} else {
//Use the parent since a name matches
anotherCtxObj.setRealm(realm);
}
} else {
anotherCtxObj.setRealm(realm);
}
}
// add application listeners to the new context
if (applicationListeners != null) {
for (String listener : applicationListeners) {
anotherCtxObj.addApplicationListener(listener);
}
}
host.addChild(anotherCtxObj);
}