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 "));
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations