Search in sources :

Example 1 with DomainAuthorizationPolicy

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

the class SecureRouteBuilder method configure.

@Override
public void configure() throws Exception {
    getContext().setNameStrategy(new ExplicitCamelContextNameStrategy("secured-context"));
    from("direct:start").policy(new DomainAuthorizationPolicy().roles("Role2")).transform(body().prepend("Hello "));
}
Also used : ExplicitCamelContextNameStrategy(org.apache.camel.impl.ExplicitCamelContextNameStrategy) DomainAuthorizationPolicy(org.wildfly.extension.camel.security.DomainAuthorizationPolicy)

Example 2 with DomainAuthorizationPolicy

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

the class SecuredRouteTestCase method testNoAuthenticationHeader.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").policy(new DomainAuthorizationPolicy()).transform(body().prepend("Hello "));
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        try {
            producer.requestBody("direct:start", "Kermit", String.class);
            Assert.fail("CamelExecutionException expected");
        } catch (CamelExecutionException ex) {
            Throwable cause = ex.getCause();
            Assert.assertEquals(SecurityException.class, cause.getClass());
            Assert.assertTrue(cause.getMessage(), cause.getMessage().startsWith("Cannot obtain authentication subject"));
        }
    } 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) 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) Test(org.junit.Test)

Example 3 with DomainAuthorizationPolicy

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

the class SecuredRouteTestCase method testAuthenticatedAccess.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").policy(new DomainAuthorizationPolicy()).transform(body().prepend("Hello "));
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, AnnotatedSLSB.PASSWORD);
        String result = producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) 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)

Example 4 with DomainAuthorizationPolicy

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

the class SecuredRouteTestCase method testRoleBasedAccess.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").policy(new DomainAuthorizationPolicy().roles("Role2")).transform(body().prepend("Hello "));
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, AnnotatedSLSB.PASSWORD);
        String result = producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
        Assert.assertEquals("Hello Kermit", result);
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) 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)

Example 5 with DomainAuthorizationPolicy

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

the class SecuredRouteTestCase method testInvalidCredentials.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").policy(new DomainAuthorizationPolicy()).transform(body().prepend("Hello "));
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        try {
            Subject subject = getAuthenticationToken("user-domain", AnnotatedSLSB.USERNAME, "bogus");
            producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class);
            Assert.fail("CamelExecutionException expected");
        } catch (CamelExecutionException ex) {
            Throwable cause = ex.getCause();
            Assert.assertEquals(FailedLoginException.class, cause.getClass());
            Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Password invalid/Password required"));
        }
    } 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) FailedLoginException(javax.security.auth.login.FailedLoginException) RouteBuilder(org.apache.camel.builder.RouteBuilder) 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