Search in sources :

Example 16 with SecurityClient

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

the class AuthenticationTestCase method testAuthenticatedCall.

@Test
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) Test(org.junit.Test)

Example 17 with SecurityClient

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

the class EjbXACMLAuthorizationModuleTestCase method testAuthenticationCache.

/**
     * Tests unauthenticated call followed by the authentication and second call to the same instance.
     *
     * @throws Exception
     */
@Test
public void testAuthenticationCache() throws Exception {
    try {
        hello.sayHelloWorld();
        fail("Access to sayHello() should be denied if not authenticated.");
    } catch (EJBAccessException e) {
    //OK
    }
    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) EJBAccessException(javax.ejb.EJBAccessException) Test(org.junit.Test)

Example 18 with SecurityClient

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

the class EjbXACMLAuthorizationModuleTestCase method testNotAuthz.

/**
     * Test secured EJB call for authenticated but not authorized authorized user.
     *
     * @throws Exception
     */
@Test
public void testNotAuthz() throws Exception {
    SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
    securityClient.setSimple("JohnDoe", "jdoe");
    try {
        securityClient.login();
        hello.sayHelloWorld();
        fail("Access to sayHelloWorld() should be denied for JohnDoe.");
    } catch (EJBAccessException e) {
    //OK - expected
    } finally {
        securityClient.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) EJBAccessException(javax.ejb.EJBAccessException) Test(org.junit.Test)

Example 19 with SecurityClient

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

the class DefaultManagedExecutorServiceTestCase method testTaskSubmit.

@Test
public void testTaskSubmit() throws Exception {
    SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("guest", "guest");
    client.login();
    try {
        final DefaultManagedExecutorServiceTestEJB testEJB = (DefaultManagedExecutorServiceTestEJB) new InitialContext().lookup("java:module/" + DefaultManagedExecutorServiceTestEJB.class.getSimpleName());
        testEJB.submit(new TestEJBRunnable()).get();
    } finally {
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 20 with SecurityClient

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

the class DefaultManagedScheduledExecutorServiceTestCase method testTaskSubmit.

@Test
public void testTaskSubmit() throws Exception {
    SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("guest", "guest");
    client.login();
    try {
        final DefaultManagedScheduledExecutorServiceTestEJB testEJB = (DefaultManagedScheduledExecutorServiceTestEJB) new InitialContext().lookup("java:module/" + DefaultManagedScheduledExecutorServiceTestEJB.class.getSimpleName());
        testEJB.schedule(new TestEJBRunnable(), 10L, TimeUnit.MILLISECONDS).get();
    } finally {
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) InitialContext(javax.naming.InitialContext) 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