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