Search in sources :

Example 6 with SecurityClient

use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.

the class EjbXACMLAuthorizationModuleTestCase method testAuthz.

/**
     * Test secured EJB call for authenticated and authorized user.
     *
     * @throws Exception
     */
@Test
public void testAuthz() throws Exception {
    SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
    securityClient.setSimple("jduke", "theduke");
    try {
        securityClient.login();
        assertEquals(HelloBean.HELLO_WORLD, hello.sayHelloWorld());
    } finally {
        securityClient.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) Test(org.junit.Test)

Example 7 with SecurityClient

use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.

the class AuthenticationTestCase method testAuthenticatedCall.

@Test
@Ignore("[WFLY-7778] EJB identity propagation does not work with Elytron")
public void testAuthenticatedCall() throws Exception {
    // TODO: this is not spec
    final SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("user1", "password1");
    client.login();
    try {
        try {
            final Principal principal = whoAmIBean.getCallerPrincipal();
            assertNotNull("EJB 3.1 FR 17.6.5 The container must never return a null from the getCallerPrincipal method.", principal);
            assertEquals("user1", principal.getName());
        } catch (RuntimeException e) {
            e.printStackTrace();
            fail("EJB 3.1 FR 17.6.5 The EJB container must provide the caller’s security context information during the execution of a business method (" + e.getMessage() + ")");
        }
    } finally {
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) Principal(java.security.Principal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with SecurityClient

use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.

the class RunAsPrincipalTestCase method testSingletonPostconstructSecurity.

@Test
public void testSingletonPostconstructSecurity() throws Exception {
    SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("user1", "password1");
    client.login();
    try {
        WhoAmI bean = lookupSingleCallerWithIdentity();
        String actual = bean.getCallerPrincipal();
        Assert.assertEquals("Helloween", actual);
    } finally {
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) WhoAmI(org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI) Test(org.junit.Test)

Example 9 with SecurityClient

use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.

the class RunAsPrincipalTestCase method testJackInABox.

@Test
public void testJackInABox() throws Exception {
    SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("user1", "password1");
    client.login();
    try {
        WhoAmI bean = lookupCallerWithIdentity();
        String actual = bean.getCallerPrincipal();
        Assert.assertEquals("jackinabox", actual);
    } finally {
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) WhoAmI(org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI) Test(org.junit.Test)

Example 10 with SecurityClient

use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.

the class RunAsPrincipalTestCase method testAnonymous.

@Test
public void testAnonymous() throws Exception {
    SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("user1", "password1");
    client.login();
    try {
        WhoAmI bean = lookupCaller();
        String actual = bean.getCallerPrincipal();
        Assert.assertEquals("anonymous", actual);
    } finally {
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) WhoAmI(org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI) Test(org.junit.Test)

Aggregations

SecurityClient (org.jboss.security.client.SecurityClient)21 Test (org.junit.Test)18 InitialContext (javax.naming.InitialContext)7 EJBAccessException (javax.ejb.EJBAccessException)4 WhoAmI (org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI)4 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 Principal (java.security.Principal)2 ServletException (javax.servlet.ServletException)2 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 ObjectMessage (javax.jms.ObjectMessage)1 Queue (javax.jms.Queue)1 QueueConnection (javax.jms.QueueConnection)1 QueueConnectionFactory (javax.jms.QueueConnectionFactory)1 QueueSession (javax.jms.QueueSession)1 Session (javax.jms.Session)1 TemporaryQueue (javax.jms.TemporaryQueue)1 TextMessage (javax.jms.TextMessage)1