final ModelNode authentication = operation.hasDefined(AUTHENTICATION) ? operation.get(AUTHENTICATION) : null;
final ModelNode serverIdentities = operation.hasDefined(SERVER_IDENTITIES) ? operation.get(SERVER_IDENTITIES) : null;
final ServiceTarget serviceTarget = context.getServiceTarget();
final SecurityRealmService securityRealmService = new SecurityRealmService(realmName);
final ServiceName realmServiceName = SecurityRealmService.BASE_SERVICE_NAME.append(realmName);
ServiceBuilder<?> realmBuilder = serviceTarget.addService(realmServiceName, securityRealmService);
ServiceName authenticationName = null;
if (authentication != null) {
if (authentication.hasDefined(LDAP)) {
authenticationName = addLdapService(authentication.require(LDAP), realmServiceName, serviceTarget, newControllers);
} else if (authentication.hasDefined(PROPERTIES)) {
authenticationName = addPropertiesService(authentication.require(PROPERTIES), realmServiceName, realmName, serviceTarget, newControllers);
} else if (authentication.hasDefined(USERS)) {
authenticationName = addUsersService(context, authentication.require(USERS), realmServiceName, realmName, serviceTarget, newControllers);
}
}
if (authenticationName != null) {
realmBuilder.addDependency(authenticationName, DomainCallbackHandler.class, securityRealmService.getCallbackHandlerInjector());
}
if (serverIdentities != null) {
if (serverIdentities.hasDefined(SSL)) {
ServiceName sslServiceName = addSSLService(context, serverIdentities.require(SSL), realmServiceName, serviceTarget, newControllers);
realmBuilder.addDependency(sslServiceName, SSLIdentityService.class, securityRealmService.getSSLIdentityInjector());
}
if (serverIdentities.hasDefined(SECRET)) {
ServiceName secretServiceName = addSecretService(serverIdentities.require(SECRET),realmServiceName,serviceTarget,newControllers);
realmBuilder.addDependency(secretServiceName, CallbackHandlerFactory.class,securityRealmService.getSecretCallbackFactory());
}
}
newControllers.add(realmBuilder.setInitialMode(ServiceController.Mode.ON_DEMAND)
.install());