Search in sources :

Example 1 with SecurityDomainContext

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

the class UndertowDeploymentInfoService method handleIdentityManager.

private void handleIdentityManager(final DeploymentInfo deploymentInfo) {
    if (securityDomain != null) {
        SecurityDomainContext sdc = securityDomainContextValue.getValue();
        deploymentInfo.setIdentityManager(new JAASIdentityManagerImpl(sdc));
        AuditManager auditManager = sdc.getAuditManager();
        if (auditManager != null && !mergedMetaData.isDisableAudit()) {
            deploymentInfo.addNotificationReceiver(new AuditNotificationReceiver(auditManager));
        }
    }
}
Also used : JAASIdentityManagerImpl(org.wildfly.extension.undertow.security.JAASIdentityManagerImpl) AuditNotificationReceiver(org.wildfly.extension.undertow.security.AuditNotificationReceiver) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) AuditManager(org.jboss.security.audit.AuditManager)

Example 2 with SecurityDomainContext

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

the class SecurityDomainJndiInjectable method lookupSecurityDomain.

/**
     * Creates a {@code SecurityDomainContext} if one cannot be found in JNDI for a given security domain
     *
     * @param securityManagement security management
     * @param securityManagerMap security manager map
     * @param securityDomain the name of the security domain
     * @return an instance of {@code SecurityDomainContext}
     * @throws Exception if an error occurs
     */
private SecurityDomainContext lookupSecurityDomain(final JNDIBasedSecurityManagement securityManagement, final ConcurrentHashMap<String, SecurityDomainContext> securityManagerMap, final String securityDomain) throws Exception {
    SecurityDomainContext sdc = securityManagerMap.get(securityDomain);
    if (sdc == null) {
        sdc = securityManagement.createSecurityDomainContext(securityDomain, new DefaultAuthenticationCacheFactory());
        securityManagerMap.put(securityDomain, sdc);
    }
    return sdc;
}
Also used : DefaultAuthenticationCacheFactory(org.jboss.as.security.plugins.DefaultAuthenticationCacheFactory) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext)

Example 3 with SecurityDomainContext

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

the class TestJBossSecurityHelper method testAuthenticate.

public void testAuthenticate() throws Exception {
    Credentials credentials = new Credentials("pass1".toCharArray());
    String domains = "testFile";
    AuthenticationManager authManager = new AuthenticationManager() {

        public String getSecurityDomain() {
            return null;
        }

        public boolean isValid(Principal principal, Object credential, Subject activeSubject) {
            return true;
        }

        public boolean isValid(Principal principal, Object credential) {
            return true;
        }

        @Override
        public Principal getTargetPrincipal(Principal anotherDomainPrincipal, Map<String, Object> contextMap) {
            return null;
        }

        @Override
        public Subject getActiveSubject() {
            return null;
        }

        @Override
        public void logout(Principal arg0, Subject arg1) {
        }
    };
    final SecurityDomainContext securityContext = new SecurityDomainContext(authManager, null, null, null, null, null);
    JBossSecurityHelper ms = buildSecurityHelper(domains, securityContext);
    // $NON-NLS-1$
    Object c = ms.authenticate(domains, "user1", credentials, null);
    // $NON-NLS-1$
    assertTrue(c instanceof JBossSecurityContext);
    assertEquals(domains, ((JBossSecurityContext) c).getSecurityDomain());
}
Also used : AuthenticationManager(org.jboss.security.AuthenticationManager) JBossSecurityContext(org.jboss.security.plugins.JBossSecurityContext) Map(java.util.Map) Credentials(org.teiid.security.Credentials) Principal(java.security.Principal) SimplePrincipal(org.jboss.security.SimplePrincipal) Subject(javax.security.auth.Subject) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext)

Example 4 with SecurityDomainContext

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

the class TestJBossSecurityHelper method validateSession.

public void validateSession(boolean securityEnabled) throws Exception {
    final ArrayList<String> domains = new ArrayList<String>();
    domains.add("somedomain");
    AuthenticationManager authManager = Mockito.mock(AuthenticationManager.class);
    Mockito.stub(authManager.isValid(new SimplePrincipal("steve"), "pass1", new Subject())).toReturn(true);
    final SecurityDomainContext securityContext = new SecurityDomainContext(authManager, null, null, null, null, null);
    SessionServiceImpl jss = new SessionServiceImpl() {

        @Override
        protected VDBMetaData getActiveVDB(String vdbName, String vdbVersion) throws SessionServiceException {
            return Mockito.mock(VDBMetaData.class);
        }
    };
    jss.setSecurityHelper(buildSecurityHelper("somedomain", securityContext));
    jss.setSecurityDomain("somedomain");
    try {
        jss.validateSession(String.valueOf(1));
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    SessionMetadata info = jss.createSession("x", "1", AuthenticationType.USERPASSWORD, "steve", new Credentials("pass1".toCharArray()), "foo", new Properties());
    if (securityEnabled) {
        Mockito.verify(authManager).isValid(new SimplePrincipal("steve"), "pass1", new Subject());
    }
    String id1 = info.getSessionId();
    jss.validateSession(id1);
    assertEquals(1, jss.getActiveSessionsCount());
    // $NON-NLS-1$
    assertEquals(0, jss.getSessionsLoggedInToVDB(new VDBKey("a", 1)).size());
    jss.closeSession(id1);
    try {
        jss.validateSession(id1);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
    try {
        jss.closeSession(id1);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionServiceImpl(org.teiid.services.SessionServiceImpl) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Subject(javax.security.auth.Subject) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) AuthenticationManager(org.jboss.security.AuthenticationManager) VDBKey(org.teiid.vdb.runtime.VDBKey) SimplePrincipal(org.jboss.security.SimplePrincipal) Credentials(org.teiid.security.Credentials)

Example 5 with SecurityDomainContext

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

the class JBossSecurityHelper method getSecurityDomainContext.

protected SecurityDomainContext getSecurityDomainContext(String securityDomain) {
    if (securityDomain != null && !securityDomain.isEmpty()) {
        // $NON-NLS-1$ //$NON-NLS-2$
        ServiceName name = ServiceName.JBOSS.append("security", "security-domain", securityDomain);
        ServiceController<SecurityDomainContext> controller = (ServiceController<SecurityDomainContext>) CurrentServiceContainer.getServiceContainer().getService(name);
        if (controller != null) {
            return controller.getService().getValue();
        }
    }
    return null;
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext)

Aggregations

SecurityDomainContext (org.jboss.as.security.plugins.SecurityDomainContext)9 Subject (javax.security.auth.Subject)4 AuthenticationManager (org.jboss.security.AuthenticationManager)4 SimplePrincipal (org.jboss.security.SimplePrincipal)4 Principal (java.security.Principal)3 LoginException (javax.security.auth.login.LoginException)2 SecurityContext (org.jboss.security.SecurityContext)2 Credentials (org.teiid.security.Credentials)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 Name (javax.naming.Name)1 NameParser (javax.naming.NameParser)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 ServiceController (org.jboss.msc.service.ServiceController)1