Package org.jboss.security.client

Examples of org.jboss.security.client.SecurityClient


   }

   @Test
   public void testTestUser() throws Throwable
   {
      SecurityClient client = SecurityClientFactory.getSecurityClient();
      client.setSimple("testuser", "testpwd");
      client.login();
      try
      {
         DirectContainer<SecuredBean> container = new DirectContainer<SecuredBean>("Test", "SimpleContainer", SecuredBean.class);
         BeanContext<SecuredBean> bean = container.construct();
         Principal callerPrincipal = container.invoke(bean, "getCallerPrincipal");
         assertEquals(CustomPrincipal.class, callerPrincipal.getClass());
         assertEquals("testuser", callerPrincipal.getName());
      }
      finally
      {
         client.logout();
      }
   }
View Full Code Here


        return (WhoAmI)new InitialContext().lookup("java:module/" + Caller.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 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

     * @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();
        }

    }
View Full Code Here

     * @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();
        }

    }
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

     */
    @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:/RemoteConnectionFactory");
            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.stop();
            }
            client.logout();
        }
    }
View Full Code Here

    @Test
    public void testEBActivate() throws Exception {
        deployer.deploy("eb");
        EntityBean eb = setUpEB();
        SecurityClient client = this.login();
        ITestResultsSingleton results = this.getResultsSingleton();

        try {
            Assert.assertEquals(OK, results.getEb("ejbactivate"));
        } finally {
            tearDownEB(eb);
            client.logout();
        }
        deployer.undeploy("eb");
    }
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

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.