Package org.jboss.security.client

Examples of org.jboss.security.client.SecurityClient


    @EJB(lookup = "java:app/ejb3-ear-servlet-ejbs/StatelessBean!org.jboss.as.test.integration.ejb.servlet.StatelessLocal")
    StatelessLocal injectedStateless;

    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:app/ejb3-ear-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();
View Full Code Here


        return (WhoAmI) new InitialContext().lookup("java:module/" + StatelessSingletonUseBean.class.getSimpleName() + "!" + WhoAmI.class.getName());
    }

    @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();
        }
    }
View Full Code Here

        }
    }

    @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();
        }
    }
View Full Code Here

        }
    }

    @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();
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testSingletonPostconstructSecurityNotPropagating() throws Exception {
        SecurityClient client = SecurityClientFactory.getSecurityClient();
        client.setSimple("user1", "password1");
        client.login();
        try {
            WhoAmI bean = lookupSingletonUseBeanWithIdentity(); //To load the singleton
            bean.getCallerPrincipal();
            Assert.fail("Deployment should fail");
        } catch (Exception dex) {
            Throwable t = checkEjbException(dex);
            log.info("Expected deployment error because the Singleton has nosecurity context per itself", dex.getCause());
            Assert.assertThat(t.getMessage(), t.getMessage(), CoreMatchers.containsString("WFLYEJB0364"));
        } finally {
            client.logout();
        }
    }
View Full Code Here

    private ITestResultsSingleton getResultsSingleton() throws NamingException {
        return (ITestResultsSingleton) initialContext.lookup("ejb:/single//" + TestResultsSingleton.class.getSimpleName() + "!" + ITestResultsSingleton.class.getName());
    }

    private SecurityClient login() throws Exception {
        final SecurityClient client = SecurityClientFactory.getSecurityClient();
        client.setSimple("user1", "password1");
        client.login();
        return client;
    }
View Full Code Here

    }

    @Test
    public void testStatelessLifecycle() throws Exception {
        deployer.deploy("slsb");
        SecurityClient client = this.login();
        try {
            ITestResultsSingleton results = this.getResultsSingleton();
            IBeanLifecycleCallback bean = (IBeanLifecycleCallback) initialContext.lookup("ejb:/slsb//" + SLSBLifecycleCallback.class.getSimpleName() + "!" + IBeanLifecycleCallback.class.getName());
            log.debug("Stateless bean returns: " + bean.get());

            Assert.assertEquals(OK + "start", results.getSlsb("postconstruct"));

            deployer.undeploy("slsb");

            Assert.assertEquals(OK + "stop", results.getSlsb("predestroy"));
        } finally {
            client.logout();
        }
    }
View Full Code Here

    }

    @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.debug("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();
        }
    }
View Full Code Here

     */
    @OperateOnDeployment("test")
    @Test
    public void testMDBLifecycle() throws Exception {
        deployer.deploy("mdb");
        SecurityClient client = this.login();
        ITestResultsSingleton results = this.getResultsSingleton();

        MessageProducer producer = null;
        MessageConsumer consumer = null;
        QueueConnection conn = null;
        Session session = null;

        try {
            QueueConnectionFactory qcf = (QueueConnectionFactory) new InitialContext().lookup("java:/ConnectionFactory");
            Queue queue = (Queue) new InitialContext().lookup("java:jboss/" + QUEUE_NAME);

            conn = qcf.createQueueConnection("guest", "guest");
            conn.start();
            session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

            TemporaryQueue replyQueue = session.createTemporaryQueue();

            TextMessage msg = session.createTextMessage("Hello world");
            msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
            msg.setJMSReplyTo(replyQueue);

            producer = session.createProducer(queue);
            producer.send(msg);
            consumer = session.createConsumer(replyQueue);
            Message replyMsg = consumer.receive(5000);

            Object obj = ((ObjectMessage) replyMsg).getObject();
            log.info("MDB message get: " + obj);

            Assert.assertEquals(OK + "start", results.getMdb("postconstruct"));

            deployer.undeploy("mdb");

            Assert.assertEquals(OK + "stop", results.getMdb("predestroy"));
        } finally {
            if(consumer != null) {
                consumer.close();
            }
            if(producer!=null) {
                producer.close();
            }
            if(session!=null) {
                session.close();
            }
            if(conn!=null) {
                conn.close();
            }
            client.logout();
        }
    }
View Full Code Here

    }

    @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();
        }
    }
View Full Code Here

TOP

Related Classes of org.jboss.security.client.SecurityClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.