Search in sources :

Example 1 with SecurityClient

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

the class DefaultContextServiceTestCase method testTaskSubmit.

@Test
public void testTaskSubmit() throws Exception {
    SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("guest", "guest");
    client.login();
    try {
        final DefaultContextServiceTestEJB testEJB = (DefaultContextServiceTestEJB) new InitialContext().lookup("java:module/" + DefaultContextServiceTestEJB.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 2 with SecurityClient

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

the class DefaultManagedThreadFactoryTestCase method testTaskSubmit.

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

Example 3 with SecurityClient

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

the class EjbXACMLAuthorizationModuleTestCase method testAuthz.

/**
     * Test secured EJB call for authenticated and authorized user.
     *
     * @throws Exception
     */
@Test
public void testAuthz() throws Exception {
    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) Test(org.junit.Test)

Example 4 with SecurityClient

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

the class RunAsPrincipalTestCase method testSingletonPostconstructSecurityNotPropagating.

@Test
public void testSingletonPostconstructSecurityNotPropagating() throws Exception {
    SecurityClient client = SecurityClientFactory.getSecurityClient();
    client.setSimple("user1", "password1");
    client.login();
    try {
        //To load the singleton
        WhoAmI bean = lookupSingletonUseBeanWithIdentity();
        bean.getCallerPrincipal();
        Assert.fail("Deployment should fail");
    } catch (Exception dex) {
        Throwable t = checkEjbException(dex);
        log.trace("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();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) WhoAmI(org.jboss.as.test.integration.ejb.security.runasprincipal.WhoAmI) EJBAccessException(javax.ejb.EJBAccessException) Test(org.junit.Test)

Example 5 with SecurityClient

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

the class GetCallerPrincipalTestCase method testMDBLifecycle.

/**
     * Run this one in the container so it can lookup the queue
     * @throws Exception
     */
@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.trace("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();
    }
}
Also used : SecurityClient(org.jboss.security.client.SecurityClient) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueConnectionFactory(javax.jms.QueueConnectionFactory) InitialContext(javax.naming.InitialContext) QueueConnection(javax.jms.QueueConnection) ObjectMessage(javax.jms.ObjectMessage) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) 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