Search in sources :

Example 11 with SecurityClient

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

the class GetCallerPrincipalTestCase method login.

private SecurityClient login() throws Exception {
    final SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("user1", "password1");
    client.login();
    return client;
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient)

Example 12 with SecurityClient

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

the class GetCallerPrincipalTestCase method testStatefulLifecycle.

@Test
public void testStatefulLifecycle() throws Exception {
    deployer.deploy("sfsb");
    SecurityClient client = this.login();
    ITestResultsSingleton results = this.getResultsSingleton();
    try {
        IBeanLifecycleCallback bean = (IBeanLifecycleCallback) initialContext.lookup("ejb:/sfsb//" + SFSBLifecycleCallback.class.getSimpleName() + "!" + IBeanLifecycleCallback.class.getName() + "?stateful");
        log.trace("Stateful bean returns: " + bean.get());
        Assert.assertEquals(ANONYMOUS + "start", results.getSfsb("postconstruct"));
        bean.remove();
        Assert.assertEquals(LOCAL_USER + "stop", results.getSfsb("predestroy"));
    } finally {
        deployer.undeploy("sfsb");
        client.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) Test(org.junit.Test)

Example 13 with SecurityClient

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

the class SingletonSecurityTestCase method testInvocationOnSecuredMethodWithInCorrectRole.

/**
     * Test a method invocation on a singleton bean with an incorrect role.
     *
     * @throws Exception
     */
@Test
public void testInvocationOnSecuredMethodWithInCorrectRole() throws Exception {
    final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName());
    final SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
    securityClient.setSimple("user2", "password2");
    try {
        // login
        securityClient.login();
        try {
            // expects role1, so should fail
            securedSingleton.allowedForRole1();
            Assert.fail("Call to secured method, with incorrect role, was expected to fail");
        } catch (EJBAccessException ejbae) {
        // expected
        }
    } finally {
        securityClient.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) EJBAccessException(javax.ejb.EJBAccessException) Test(org.junit.Test)

Example 14 with SecurityClient

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

the class SingletonSecurityTestCase method testInvocationOnSecuredMethodWithCorrectRole.

/**
     * Test a method invocation on a singleton bean with the correct expected role.
     *
     * @throws Exception
     */
@Test
public void testInvocationOnSecuredMethodWithCorrectRole() throws Exception {
    final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName());
    final SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
    securityClient.setSimple("user1", "password1");
    try {
        // login
        securityClient.login();
        // expects role1, so should succeed
        securedSingleton.allowedForRole1();
    } finally {
        securityClient.logout();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) Test(org.junit.Test)

Example 15 with SecurityClient

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

the class EJBServlet method processRequest.

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    SecurityClient client = null;
    try {
        InitialContext ctx = new InitialContext();
        client = SecurityClientFactory.getSecurityClient();
        client.setSimple("user1", "password1");
        client.login();
        injectedSession.hello();
        injectedSession.goodbye();
        injectedStateless.hello();
        injectedStateless.goodbye();
        String lookupString = "java:global/ejb3-servlet-ejbs/Session30!";
        EJBServletHelper test = new EJBServletHelper();
        test.processRequest(lookupString, ctx);
    } catch (Exception e) {
        log.error(e);
        throw new ServletException("Failed to call EJBs/Session30 through remote and local interfaces", e);
    } finally {
        client.logout();
    }
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    out.print("EJBServlet OK");
    out.close();
}
Also used : ServletException(javax.servlet.ServletException) SecurityClient(org.jboss.security.client.SecurityClient) InitialContext(javax.naming.InitialContext) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

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