Search in sources :

Example 1 with SecurityRealm

use of org.wildfly.security.auth.server.SecurityRealm in project wildfly by wildfly.

the class ElytronIntegrationResourceDefinitions method getElytronRealmResourceDefinition.

/**
     * Defines a resource that represents an Elytron-compatible realm that can be exported by the legacy security subsystem.
     * The constructed {@code SecurityRealm} wraps a legacy {@code SecurityDomainContext} and delegates authentication
     * decisions to that context.
     *
     * To export the realm the resource uses a {@code BasicAddHandler} implementation that registers the security-realm
     * capability and implements a {@code org.jboss.as.security.elytron.BasicService.ValueSupplier} that uses the injected
     * {@code SecurityDomainContext} to create and return an instance of {@code SecurityDomainContextRealm}.
     */
public static ResourceDefinition getElytronRealmResourceDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { LEGACY_JAAS_CONFIG };
    final AbstractAddStepHandler addHandler = new BasicAddHandler<SecurityRealm>(attributes, SECURITY_REALM_RUNTIME_CAPABILITY) {

        @Override
        protected BasicService.ValueSupplier<SecurityRealm> getValueSupplier(ServiceBuilder<SecurityRealm> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String legacyJAASConfig = asStringIfDefined(context, LEGACY_JAAS_CONFIG, model);
            final InjectedValue<SecurityDomainContext> securityDomainContextInjector = new InjectedValue<>();
            if (legacyJAASConfig != null) {
                serviceBuilder.addDependency(SecurityDomainService.SERVICE_NAME.append(legacyJAASConfig), SecurityDomainContext.class, securityDomainContextInjector);
            }
            return () -> {
                final SecurityDomainContext domainContext = securityDomainContextInjector.getValue();
                return new SecurityDomainContextRealm(domainContext);
            };
        }
    };
    return new BasicResourceDefinition(Constants.ELYTRON_REALM, addHandler, attributes, SECURITY_REALM_RUNTIME_CAPABILITY);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InjectedValue(org.jboss.msc.value.InjectedValue) SecurityRealm(org.wildfly.security.auth.server.SecurityRealm) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)1 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)1 OperationContext (org.jboss.as.controller.OperationContext)1 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)1 SecurityDomainContext (org.jboss.as.security.plugins.SecurityDomainContext)1 ModelNode (org.jboss.dmr.ModelNode)1 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)1 InjectedValue (org.jboss.msc.value.InjectedValue)1 SecurityRealm (org.wildfly.security.auth.server.SecurityRealm)1