Search in sources :

Example 6 with AuthenticationManager

use of org.jboss.security.AuthenticationManager in project wildfly by wildfly.

the class JNDIBasedSecurityManagement method createAuthenticationManager.

/**
     * Creates an {@code AuthenticationManager}
     *
     * @param securityDomain name of the security domain
     * @return an instance of {@code AuthenticationManager}
     * @throws Exception if creation fails
     */
private AuthenticationManager createAuthenticationManager(String securityDomain) throws Exception {
    int i = callbackHandlerClassName.lastIndexOf(":");
    if (i == -1)
        throw SecurityLogger.ROOT_LOGGER.missingModuleName("default-callback-handler-class-name attribute");
    String moduleSpec = callbackHandlerClassName.substring(0, i);
    String className = callbackHandlerClassName.substring(i + 1);
    Class<?> callbackHandlerClazz = SecurityActions.getModuleClassLoader(loader, moduleSpec).loadClass(className);
    CallbackHandler ch = (CallbackHandler) callbackHandlerClazz.newInstance();
    i = authenticationManagerClassName.lastIndexOf(":");
    if (i == -1)
        throw SecurityLogger.ROOT_LOGGER.missingModuleName("authentication-manager-class-name attribute");
    moduleSpec = authenticationManagerClassName.substring(0, i);
    className = authenticationManagerClassName.substring(i + 1);
    Class<?> clazz = SecurityActions.getModuleClassLoader(loader, moduleSpec).loadClass(className);
    Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class, CallbackHandler.class });
    return (AuthenticationManager) ctr.newInstance(new Object[] { securityDomain, ch });
}
Also used : AuthenticationManager(org.jboss.security.AuthenticationManager) CallbackHandler(javax.security.auth.callback.CallbackHandler)

Example 7 with AuthenticationManager

use of org.jboss.security.AuthenticationManager in project wildfly by wildfly.

the class JNDIBasedSecurityManagement method createSecurityDomainContext.

/**
     * Creates a {@code SecurityDomainContext}
     *
     * @param securityDomain name of the security domain
     * @param cacheFactory creates a cache implementation
     * @return an instance of {@code SecurityDomainContext}
     * @throws Exception if an error occurs during creation
     */
public SecurityDomainContext createSecurityDomainContext(String securityDomain, AuthenticationCacheFactory cacheFactory) throws Exception {
    SecurityLogger.ROOT_LOGGER.debugf("Creating SDC for domain = %s", securityDomain);
    AuthenticationManager am = createAuthenticationManager(securityDomain);
    if (cacheFactory != null && am instanceof CacheableManager) {
        // create authentication cache
        final Map<Principal, ?> cache = cacheFactory.getCache();
        if (cache != null) {
            @SuppressWarnings({ "unchecked", "rawtypes" }) CacheableManager<Map, Principal> cm = (CacheableManager<Map, Principal>) am;
            cm.setCache(cache);
        }
    }
    // set DeepCopySubject option if supported
    if (deepCopySubjectMode) {
        setDeepCopySubjectMode(am);
    }
    SecurityDomainContext securityDomainContext = new SecurityDomainContext(am);
    securityDomainContext.setAuthorizationManager(createAuthorizationManager(securityDomain));
    securityDomainContext.setAuditManager(createAuditManager(securityDomain));
    securityDomainContext.setIdentityTrustManager(createIdentityTrustManager(securityDomain));
    securityDomainContext.setMappingManager(createMappingManager(securityDomain));
    return securityDomainContext;
}
Also used : AuthenticationManager(org.jboss.security.AuthenticationManager) CacheableManager(org.jboss.security.CacheableManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) Principal(java.security.Principal)

Aggregations

AuthenticationManager (org.jboss.security.AuthenticationManager)7 Principal (java.security.Principal)3 Subject (javax.security.auth.Subject)2 JBossCachedAuthenticationManager (org.jboss.security.authentication.JBossCachedAuthenticationManager)2 ImmediateInstanceFactory (io.undertow.servlet.util.ImmediateInstanceFactory)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 AuthorizationManager (org.jboss.security.AuthorizationManager)1 CacheableManager (org.jboss.security.CacheableManager)1 RunAsIdentity (org.jboss.security.RunAsIdentity)1 SecurityContext (org.jboss.security.SecurityContext)1 SecurityContextUtil (org.jboss.security.SecurityContextUtil)1 SimplePrincipal (org.jboss.security.SimplePrincipal)1 SubjectInfo (org.jboss.security.SubjectInfo)1 AuditManager (org.jboss.security.audit.AuditManager)1 SecurityContextCallbackHandler (org.jboss.security.callbacks.SecurityContextCallbackHandler)1 Identity (org.jboss.security.identity.Identity)1 Role (org.jboss.security.identity.Role)1