Search in sources :

Example 6 with SecurityDomainContext

use of org.jboss.as.security.plugins.SecurityDomainContext in project wildfly by wildfly.

the class SecurityDomainAdd method launchServices.

public void launchServices(OperationContext context, String securityDomain, ModelNode model) throws OperationFailedException {
    final ApplicationPolicy applicationPolicy = createApplicationPolicy(context, securityDomain, model);
    final JSSESecurityDomain jsseSecurityDomain = createJSSESecurityDomain(context, securityDomain, model);
    final String cacheType = getAuthenticationCacheType(model);
    final SecurityDomainService securityDomainService = new SecurityDomainService(securityDomain, applicationPolicy, jsseSecurityDomain, cacheType);
    final ServiceTarget target = context.getServiceTarget();
    ServiceBuilder<SecurityDomainContext> builder = target.addService(SecurityDomainService.SERVICE_NAME.append(securityDomain), securityDomainService).addDependency(SecurityManagementService.SERVICE_NAME, ISecurityManagement.class, securityDomainService.getSecurityManagementInjector()).addDependency(JaasConfigurationService.SERVICE_NAME, Configuration.class, securityDomainService.getConfigurationInjector());
    if (SecurityDomainResourceDefinition.INFINISPAN_CACHE_TYPE.equals(cacheType)) {
        builder.addDependency(InfinispanRequirement.CONTAINER.getServiceName(context.getCapabilityServiceSupport(), SecurityDomainResourceDefinition.CACHE_CONTAINER_NAME), Object.class, securityDomainService.getCacheManagerInjector());
        builder.addDependency(InfinispanDefaultCacheRequirement.CONFIGURATION.getServiceName(context, SecurityDomainResourceDefinition.CACHE_CONTAINER_NAME));
    }
    builder.setInitialMode(ServiceController.Mode.ACTIVE).install();
}
Also used : SecurityDomainService(org.jboss.as.security.service.SecurityDomainService) ISecurityManagement(org.jboss.security.ISecurityManagement) ApplicationPolicy(org.jboss.security.config.ApplicationPolicy) JBossJSSESecurityDomain(org.jboss.security.JBossJSSESecurityDomain) JSSESecurityDomain(org.jboss.security.JSSESecurityDomain) ServiceTarget(org.jboss.msc.service.ServiceTarget) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext)

Example 7 with SecurityDomainContext

use of org.jboss.as.security.plugins.SecurityDomainContext in project wildfly by wildfly.

the class SecurityDomainJndiInjectable method invoke.

/**
     * This is the InvocationHandler callback for the Context interface that was created by our getObjectInstance() method. We
     * handle the java:jboss/jaas/domain level operations here.
     */
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Context ctx = new InitialContext();
    NameParser parser = ctx.getNameParser("");
    String securityDomain = null;
    Name name = null;
    final JNDIBasedSecurityManagement securityManagement = JNDIBasedSecurityManagement.class.cast(securityManagementValue.getValue());
    final ConcurrentHashMap<String, SecurityDomainContext> securityManagerMap = securityManagement.getSecurityManagerMap();
    String methodName = method.getName();
    if (methodName.equals("toString"))
        return SecurityConstants.JAAS_CONTEXT_ROOT + " Context proxy";
    if (methodName.equals("list"))
        return new DomainEnumeration(securityManagerMap.keys(), securityManagerMap);
    if (methodName.equals("bind") || methodName.equals("rebind")) {
        if (args[0] instanceof String)
            name = parser.parse((String) args[0]);
        else
            name = (Name) args[0];
        securityDomain = name.get(0);
        SecurityDomainContext val = (SecurityDomainContext) args[1];
        securityManagerMap.put(securityDomain, val);
        return proxy;
    }
    if (!methodName.equals("lookup"))
        throw SecurityLogger.ROOT_LOGGER.operationNotSupported(method);
    if (args[0] instanceof String)
        name = parser.parse((String) args[0]);
    else
        name = (Name) args[0];
    securityDomain = name.get(0);
    SecurityDomainContext securityDomainCtx = lookupSecurityDomain(securityManagement, securityManagerMap, securityDomain);
    Object binding = securityDomainCtx.getAuthenticationManager();
    // Look for requests against the security domain context
    if (name.size() == 2) {
        String request = name.get(1);
        binding = securityDomainCtx.lookup(request);
    }
    return binding;
}
Also used : Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) InitialContext(javax.naming.InitialContext) NameParser(javax.naming.NameParser) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) Name(javax.naming.Name) JNDIBasedSecurityManagement(org.jboss.as.security.plugins.JNDIBasedSecurityManagement)

Example 8 with SecurityDomainContext

use of org.jboss.as.security.plugins.SecurityDomainContext in project wildfly by wildfly.

the class ElytronIntegrationResourceDefinitions method getElytronKeyStoreResourceDefinition.

/**
     * Defines a resource that represents an Elytron-compatible key store that can be exported by a JSSE-enabled domain
     * in the legacy security subsystem.
     *
     * To export the key store the resource uses a {@code BasicAddHandler} implementation that registers the elytron key-store
     * capability and implements a {@code org.jboss.as.security.elytron.BasicService.ValueSupplier} that uses the injected
     * {@code SecurityDomainContext} to obtain a {@code JSSESecurityDomain}. If such domain is found, its configured key
     * store is obtained and returned.
     *
     * The {@code ValueSupplier} implementation throws an exception if the referenced legacy domain is not a JSSE-enabled
     * domain or if the domain doesn't contain a key store configuration.
     */
public static ResourceDefinition getElytronKeyStoreResourceDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { LEGACY_JSSE_CONFIG };
    final AbstractAddStepHandler addHandler = new BasicAddHandler<KeyStore>(attributes, KEY_STORE_RUNTIME_CAPABILITY) {

        @Override
        protected BasicService.ValueSupplier<KeyStore> getValueSupplier(ServiceBuilder<KeyStore> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String legacyJSSEConfig = asStringIfDefined(context, LEGACY_JSSE_CONFIG, model);
            final InjectedValue<SecurityDomainContext> securityDomainContextInjector = new InjectedValue<>();
            if (legacyJSSEConfig != null) {
                serviceBuilder.addDependency(SecurityDomainService.SERVICE_NAME.append(legacyJSSEConfig), SecurityDomainContext.class, securityDomainContextInjector);
            }
            return () -> {
                final SecurityDomainContext domainContext = securityDomainContextInjector.getValue();
                final JSSESecurityDomain jsseDomain = domainContext.getJSSE();
                if (jsseDomain == null) {
                    throw SecurityLogger.ROOT_LOGGER.unableToLocateJSSEConfig(legacyJSSEConfig);
                }
                final KeyStore keyStore = jsseDomain.getKeyStore();
                if (keyStore == null) {
                    throw SecurityLogger.ROOT_LOGGER.unableToLocateComponentInJSSEDomain("key store", legacyJSSEConfig);
                }
                return keyStore;
            };
        }
    };
    return new BasicResourceDefinition(Constants.ELYTRON_KEY_STORE, addHandler, attributes, KEY_STORE_RUNTIME_CAPABILITY);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InjectedValue(org.jboss.msc.value.InjectedValue) JSSESecurityDomain(org.jboss.security.JSSESecurityDomain) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) KeyStore(java.security.KeyStore) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) ModelNode(org.jboss.dmr.ModelNode)

Example 9 with SecurityDomainContext

use of org.jboss.as.security.plugins.SecurityDomainContext 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

SecurityDomainContext (org.jboss.as.security.plugins.SecurityDomainContext)9 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)5 OperationContext (org.jboss.as.controller.OperationContext)5 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)5 ModelNode (org.jboss.dmr.ModelNode)5 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)5 InjectedValue (org.jboss.msc.value.InjectedValue)5 JSSESecurityDomain (org.jboss.security.JSSESecurityDomain)5 KeyStore (java.security.KeyStore)2 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 Name (javax.naming.Name)1 NameParser (javax.naming.NameParser)1 KeyManager (javax.net.ssl.KeyManager)1 TrustManager (javax.net.ssl.TrustManager)1 DefaultAuthenticationCacheFactory (org.jboss.as.security.plugins.DefaultAuthenticationCacheFactory)1 JNDIBasedSecurityManagement (org.jboss.as.security.plugins.JNDIBasedSecurityManagement)1 SecurityDomainService (org.jboss.as.security.service.SecurityDomainService)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1