-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[resolves #723] Add support for Exchange.AUTHENTICATION header
- Loading branch information
Thomas Diesler
committed
Jul 3, 2015
1 parent
854a0e4
commit a70cb31
Showing
21 changed files
with
462 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...s/standalone/extras/src/main/java/org/wildfly/camel/test/policy/SecuredRouteTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2011, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
|
||
package org.wildfly.camel.test.policy; | ||
|
||
import java.security.Principal; | ||
|
||
import javax.security.auth.Subject; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.CamelExecutionException; | ||
import org.apache.camel.Exchange; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.impl.DefaultCamelContext; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.wildfly.extension.camel.security.ClientLoginAuthorizationPolicy; | ||
|
||
@RunWith(Arquillian.class) | ||
public class SecuredRouteTestCase { | ||
|
||
@Deployment | ||
public static JavaArchive createDeployment() { | ||
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "secured-route-test"); | ||
return archive; | ||
} | ||
|
||
@Test | ||
public void testRoleBasedAccessDenied() throws Exception { | ||
CamelContext camelctx = new DefaultCamelContext(); | ||
camelctx.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:start") | ||
.policy(new ClientLoginAuthorizationPolicy()) | ||
.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 e) { | ||
// expected | ||
} | ||
} finally { | ||
camelctx.stop(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRoleBasedAccessAllowed() throws Exception { | ||
CamelContext camelctx = new DefaultCamelContext(); | ||
camelctx.addRoutes(new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("direct:start") | ||
.policy(new ClientLoginAuthorizationPolicy()) | ||
.transform(body().prepend("Hello ")); | ||
} | ||
}); | ||
|
||
camelctx.start(); | ||
try { | ||
ProducerTemplate producer = camelctx.createProducerTemplate(); | ||
Subject subject = getAuthenticationToken(EJBSecurityTestCase.USERNAME, EJBSecurityTestCase.PASSWORD); | ||
String result = producer.requestBodyAndHeader("direct:start", "Kermit", Exchange.AUTHENTICATION, subject, String.class); | ||
Assert.assertEquals("Hello Kermit", result); | ||
} finally { | ||
camelctx.stop(); | ||
} | ||
} | ||
|
||
private Subject getAuthenticationToken(String username, String password) { | ||
Subject subject = new Subject(); | ||
Principal principal = new UsernamePasswordAuthenticationToken(username, password); | ||
subject.getPrincipals().add(principal); | ||
return subject; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...fly/modules/system/layers/fuse/org/apache/camel/component/spring/security/main/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module xmlns="urn:jboss:module:1.1" name="org.apache.camel.component.spring.security"> | ||
<resources> | ||
<resource-root path="camel-spring-security-2.15.2.jar" /> | ||
</resources> | ||
<dependencies> | ||
<module name="javax.api" /> | ||
<module name="org.slf4j" /> | ||
<module name="org.springframework.security" export="true" /> | ||
<module name="javax.xml.bind.api" /> | ||
<module name="org.apache.camel.core" /> | ||
<module name="org.apache.camel.spring" /> | ||
<module name="org.apache.commons.logging" /> | ||
</dependencies> | ||
</module> |
16 changes: 16 additions & 0 deletions
16
...generated/wildfly/modules/system/layers/fuse/org/springframework/security/main/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module xmlns="urn:jboss:module:1.1" name="org.springframework.security"> | ||
<resources> | ||
<resource-root path="spring-security-config-3.2.5.RELEASE.jar" /> | ||
<resource-root path="spring-security-core-3.2.5.RELEASE.jar" /> | ||
</resources> | ||
<dependencies> | ||
<module name="javax.api" /> | ||
<module name="org.apache.commons.logging" /> | ||
<module name="javax.servlet.api" /> | ||
<module name="org.springframework.aop" /> | ||
<module name="org.springframework.beans" /> | ||
<module name="org.springframework.context" /> | ||
<module name="org.springframework.core" /> | ||
</dependencies> | ||
</module> |
54 changes: 0 additions & 54 deletions
54
...c/generated/wildfly/modules/system/layers/fuse/org/springframework/spring/main/module.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.