Search in sources :

Example 1 with Hello

use of org.jboss.as.test.integration.security.common.ejb3.Hello in project wildfly by wildfly.

the class HelloEJBCallServlet method doGet.

/**
     * Writes simple text response.
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");
    final PrintWriter writer = resp.getWriter();
    final String jndiName = req.getParameter(PARAM_JNDI_NAME);
    try {
        final Context ctx = new InitialContext();
        final Hello ejbObject = (Hello) ctx.lookup(jndiName);
        final String msg = ejbObject.sayHello();
        LOGGER.trace(msg);
        writer.append(msg);
        ctx.close();
    } catch (NamingException ex) {
        LOGGER.warn("Unable to get EJB.", ex);
        writer.append(ex.getMessage());
    }
    writer.close();
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) Hello(org.jboss.as.test.integration.security.common.ejb3.Hello) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) PrintWriter(java.io.PrintWriter)

Example 2 with Hello

use of org.jboss.as.test.integration.security.common.ejb3.Hello in project wildfly by wildfly.

the class RemotingLoginModuleUseNewClientCertTestCase method testAuthorizedClient.

/**
     * Tests that an authorized user has access to an EJB method.
     *
     * @throws Exception
     */
@Test
public void testAuthorizedClient() throws Exception {
    final Properties env = configureEjbClient(CLIENT_AUTHORIZED_NAME);
    InitialContext ctx = new InitialContext(env);
    final Hello helloBean = (Hello) ctx.lookup(HELLOBEAN_LOOKUP_NAME);
    assertEquals(HelloBean.HELLO_WORLD, helloBean.sayHelloWorld());
    ctx.close();
}
Also used : Hello(org.jboss.as.test.integration.security.common.ejb3.Hello) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 3 with Hello

use of org.jboss.as.test.integration.security.common.ejb3.Hello in project wildfly by wildfly.

the class RemotingLoginModuleTestCase method testNotAuthorizedClient.

/**
     * Tests if role check is done correctly for authenticated user.
     *
     * @throws Exception
     */
@Test
public void testNotAuthorizedClient() throws Exception {
    final Properties env = configureEjbClient(CLIENT_NOT_AUTHORIZED_NAME);
    InitialContext ctx = new InitialContext(env);
    final Hello helloBean = (Hello) ctx.lookup(HELLOBEAN_LOOKUP_NAME);
    try {
        helloBean.sayHelloWorld();
        fail("The EJB call should fail for unauthorized client.");
    } catch (EJBAccessException e) {
    //OK
    }
    ctx.close();
}
Also used : Hello(org.jboss.as.test.integration.security.common.ejb3.Hello) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EJBAccessException(javax.ejb.EJBAccessException) Test(org.junit.Test)

Example 4 with Hello

use of org.jboss.as.test.integration.security.common.ejb3.Hello in project wildfly by wildfly.

the class RemotingLoginModuleTestCase method testAuthorizedClient.

/**
     * Tests that an authorized user has access to an EJB method.
     *
     * @throws Exception
     */
@Test
public void testAuthorizedClient() throws Exception {
    final Properties env = configureEjbClient(CLIENT_AUTHORIZED_NAME);
    InitialContext ctx = new InitialContext(env);
    final Hello helloBean = (Hello) ctx.lookup(HELLOBEAN_LOOKUP_NAME);
    assertEquals(HelloBean.HELLO_WORLD, helloBean.sayHelloWorld());
    ctx.close();
}
Also used : Hello(org.jboss.as.test.integration.security.common.ejb3.Hello) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 5 with Hello

use of org.jboss.as.test.integration.security.common.ejb3.Hello in project wildfly by wildfly.

the class RemotingLoginModuleUseNewClientCertTestCase method testNotAuthorizedClient.

/**
     * Tests if role check is done correctly for authenticated user.
     *
     * @throws Exception
     */
@Test
public void testNotAuthorizedClient() throws Exception {
    final Properties env = configureEjbClient(CLIENT_NOT_AUTHORIZED_NAME);
    InitialContext ctx = new InitialContext(env);
    final Hello helloBean = (Hello) ctx.lookup(HELLOBEAN_LOOKUP_NAME);
    try {
        helloBean.sayHelloWorld();
        fail("The EJB call should fail for unauthorized client.");
    } catch (EJBAccessException e) {
    //OK
    }
    ctx.close();
}
Also used : Hello(org.jboss.as.test.integration.security.common.ejb3.Hello) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) EJBAccessException(javax.ejb.EJBAccessException) Test(org.junit.Test)

Aggregations

InitialContext (javax.naming.InitialContext)5 Hello (org.jboss.as.test.integration.security.common.ejb3.Hello)5 Properties (java.util.Properties)4 Test (org.junit.Test)4 EJBAccessException (javax.ejb.EJBAccessException)2 PrintWriter (java.io.PrintWriter)1 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1