org.apache.camel.CamelAuthorizationException Java Examples

The following examples show how to use org.apache.camel.CamelAuthorizationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringSecurityTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdminOnly() throws Exception {
    getMockEndpoint("mock:secure").expectedBodiesReceived("Davs Claus!");
    getMockEndpoint("mock:unsecure").expectedBodiesReceived("Davs Claus!", "Hello Jon!");      
    
    sendMessageWithAuth("direct:start", "Davs Claus!", "claus", "secret");
    try {
    sendMessageWithAuth("direct:start", "Hello Jon!", "jon", "secret");        
    } catch (CamelExecutionException e) {
        assertIsInstanceOf(CamelAuthorizationException.class, e.getCause());
    }

    assertMockEndpointsSatisfied();        
}
 
Example #2
Source File: SpringSecurityHeadersSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadPassword() {
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("username", "jakub");
    headers.put("password", "iforgotmypassword");
    try {
        template.sendBodyAndHeaders("direct:in", "foo", headers);
        fail();
    } catch (CamelExecutionException ex) {
        CamelAuthorizationException cax = (CamelAuthorizationException) ex.getCause();
        assertTrue(ExceptionUtils.getRootCause(cax) instanceof BadCredentialsException);
    }
}
 
Example #3
Source File: SpringSecurityHeadersSpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotAuthorized() {
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("username", "scott");
    headers.put("password", "supersecretpassword2");
    try {
        template.sendBodyAndHeaders("direct:in", "foo", headers);
        fail();
    } catch (CamelExecutionException ex) {
        assertTrue(ExceptionUtils.getCause(ex) instanceof CamelAuthorizationException);
    }
}
 
Example #4
Source File: SpringSecuritySpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadPassword() {
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("username", "jakub");
    headers.put("password", "iforgotmypassword");
    try {
        template.sendBodyAndHeaders("direct:in", "foo", headers);
        fail();
    } catch (CamelExecutionException ex) {
        CamelAuthorizationException cax = (CamelAuthorizationException) ex.getCause();
        assertTrue(ExceptionUtils.getRootCause(cax) instanceof BadCredentialsException);
    }
}
 
Example #5
Source File: SpringSecuritySpringTest.java    From camel-cookbook-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotAuthorized() {
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("username", "scott");
    headers.put("password", "supersecretpassword2");
    try {
        template.sendBodyAndHeaders("direct:in", "foo", headers);
        fail();
    } catch (CamelExecutionException ex) {
        assertTrue(ExceptionUtils.getCause(ex) instanceof CamelAuthorizationException);
    }
}
 
Example #6
Source File: AuthorizationPolicyTestCase.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoAuthenticationHeader() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("contextA");
    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(CamelAuthorizationException.class, cause.getClass());
        Assert.assertTrue(cause.getMessage(), cause.getMessage().startsWith("Cannot find the Authentication instance"));
    }
}
 
Example #7
Source File: AuthorizationPolicyTestCase.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidCredentials() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("contextA");
    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(CamelAuthorizationException.class, cause.getClass());
        Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Password invalid/Password required"));
    }
}
 
Example #8
Source File: AuthorizationPolicyTestCase.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testInsufficientRoles() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("contextC");
    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(CamelAuthorizationException.class, cause.getClass());
        Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("User does not have required roles: [Role3]"));
    }
}