Search in sources :

Example 6 with DomainAuthorizationPolicy

use of org.wildfly.extension.camel.security.DomainAuthorizationPolicy in project wildfly-camel by wildfly-extras.

the class SecuredRouteTestCase method testInsufficientRoles.

@Test
public void testInsufficientRoles() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").policy(new DomainAuthorizationPolicy().roles("Role3")).transform(body().prepend("Hello "));
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        try {
            Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, AnnotatedSLSB.PASSWORD);
            producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
            Assert.fail("CamelExecutionException expected");
        } catch (CamelExecutionException ex) {
            Throwable cause = ex.getCause();
            Assert.assertEquals(LoginException.class, cause.getClass());
            Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("User does not have required roles: [Role3]"));
        }
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) DomainAuthorizationPolicy(org.wildfly.extension.camel.security.DomainAuthorizationPolicy) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) LoginException(javax.security.auth.login.LoginException) CamelExecutionException(org.apache.camel.CamelExecutionException) FailedLoginException(javax.security.auth.login.FailedLoginException) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Aggregations

DomainAuthorizationPolicy (org.wildfly.extension.camel.security.DomainAuthorizationPolicy)6 FailedLoginException (javax.security.auth.login.FailedLoginException)5 LoginException (javax.security.auth.login.LoginException)5 CamelContext (org.apache.camel.CamelContext)5 CamelExecutionException (org.apache.camel.CamelExecutionException)5 ProducerTemplate (org.apache.camel.ProducerTemplate)5 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)5 Test (org.junit.Test)5 Subject (javax.security.auth.Subject)4 ExplicitCamelContextNameStrategy (org.apache.camel.impl.ExplicitCamelContextNameStrategy)1