Skip to content

Commit

Permalink
[resolves #723] Add support for Exchange.AUTHENTICATION header
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Diesler committed Jul 3, 2015
1 parent 854a0e4 commit a70cb31
Show file tree
Hide file tree
Showing 21 changed files with 462 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testAccessAllowed() throws Exception {
public void testAuthorizedAccess() throws Exception {

AnnotatedSLSB bean = lookup(new InitialContext(), AnnotatedSLSB.class, AnnotatedSLSB.class);
LoginContext lc = ClientLoginContext.newLoginContext(USERNAME, PASSWORD);
LoginContext lc = ClientLoginContext.newLoginContext(USERNAME, PASSWORD.toCharArray());
lc.login();
try {
Assert.assertEquals("Hello Kermit", bean.doSelected("Kermit"));
Expand All @@ -83,7 +83,7 @@ public void testUnauthorizedAccess() throws Exception {
//expected
}

LoginContext lc = ClientLoginContext.newLoginContext("user1", "wrongpass");
LoginContext lc = ClientLoginContext.newLoginContext("user1", "wrongpass".toCharArray());
lc.login();
try {
bean.doSelected("Kermit");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@

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;
Expand All @@ -35,7 +40,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.camel.test.policy.subA.AnnotatedSLSB;
import org.wildfly.extension.camel.security.AuthorizationPolicy;
import org.wildfly.extension.camel.security.ClientLoginAuthorizationPolicy;
import org.wildfly.extension.camel.security.UsernamePasswordAuthentication;

@RunWith(Arquillian.class)
public class PolicyIntegrationTestCase {
Expand Down Expand Up @@ -101,18 +107,26 @@ public void testRoleBasedAccessAllowed() throws Exception {
@Override
public void configure() throws Exception {
from("direct:start")
.policy(new AuthorizationPolicy(EJBSecurityTestCase.USERNAME, EJBSecurityTestCase.PASSWORD))
.policy(new ClientLoginAuthorizationPolicy())
.to("ejb:java:module/AnnotatedSLSB?method=doSelected");
}
});

camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", "Kermit", String.class);
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 UsernamePasswordAuthentication(username, password.toCharArray());
subject.getPrincipals().add(principal);
return subject;
}
}
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;
}
}
72 changes: 72 additions & 0 deletions modules/etc/baseline/exported-paths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ org/apache/camel/component/salesforce/api/dto
org/apache/camel/component/salesforce/api/dto/bulk
org/apache/camel/component/servlet
org/apache/camel/component/servlet/osgi
org/apache/camel/component/spring
org/apache/camel/component/spring/security
org/apache/camel/component/spring/security/config
org/apache/camel/component/sql
org/apache/camel/component/swagger
org/apache/camel/component/velocity
Expand Down Expand Up @@ -513,6 +516,75 @@ org/dozer/osgi
org/dozer/propertydescriptor
org/dozer/stats
org/dozer/util
org/springframework
org/springframework/security
org/springframework/security/access
org/springframework/security/access/annotation
org/springframework/security/access/event
org/springframework/security/access/expression
org/springframework/security/access/expression/method
org/springframework/security/access/hierarchicalroles
org/springframework/security/access/intercept
org/springframework/security/access/intercept/aopalliance
org/springframework/security/access/intercept/aspectj
org/springframework/security/access/method
org/springframework/security/access/prepost
org/springframework/security/access/vote
org/springframework/security/authentication
org/springframework/security/authentication/dao
org/springframework/security/authentication/encoding
org/springframework/security/authentication/event
org/springframework/security/authentication/jaas
org/springframework/security/authentication/jaas/event
org/springframework/security/authentication/jaas/memory
org/springframework/security/authentication/rcp
org/springframework/security/concurrent
org/springframework/security/config
org/springframework/security/config/annotation
org/springframework/security/config/annotation/authentication
org/springframework/security/config/annotation/authentication/builders
org/springframework/security/config/annotation/authentication/configuration
org/springframework/security/config/annotation/authentication/configurers
org/springframework/security/config/annotation/authentication/configurers/ldap
org/springframework/security/config/annotation/authentication/configurers/provisioning
org/springframework/security/config/annotation/authentication/configurers/userdetails
org/springframework/security/config/annotation/configuration
org/springframework/security/config/annotation/method
org/springframework/security/config/annotation/method/configuration
org/springframework/security/config/annotation/web
org/springframework/security/config/annotation/web/builders
org/springframework/security/config/annotation/web/configuration
org/springframework/security/config/annotation/web/configurers
org/springframework/security/config/annotation/web/configurers/openid
org/springframework/security/config/annotation/web/servlet
org/springframework/security/config/annotation/web/servlet/configuration
org/springframework/security/config/authentication
org/springframework/security/config/debug
org/springframework/security/config/http
org/springframework/security/config/ldap
org/springframework/security/config/method
org/springframework/security/core
org/springframework/security/core/authority
org/springframework/security/core/authority/mapping
org/springframework/security/core/context
org/springframework/security/core/parameters
org/springframework/security/core/session
org/springframework/security/core/token
org/springframework/security/core/userdetails
org/springframework/security/core/userdetails/cache
org/springframework/security/core/userdetails/jdbc
org/springframework/security/core/userdetails/memory
org/springframework/security/crypto
org/springframework/security/crypto/bcrypt
org/springframework/security/crypto/codec
org/springframework/security/crypto/encrypt
org/springframework/security/crypto/keygen
org/springframework/security/crypto/password
org/springframework/security/crypto/util
org/springframework/security/provisioning
org/springframework/security/scheduling
org/springframework/security/task
org/springframework/security/util
org/xmlsoap
org/xmlsoap/schemas
org/xmlsoap/schemas/soap
Expand Down
3 changes: 3 additions & 0 deletions modules/etc/baseline/module-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
/org/apache/camel/component/script/main/camel-script-2.15.2.jar
/org/apache/camel/component/servlet/main/camel-servlet-2.15.2.jar
/org/apache/camel/component/soap/main/camel-soap-2.15.2.jar
/org/apache/camel/component/spring/security/main/camel-spring-security-2.15.2.jar
/org/apache/camel/component/sql/main/camel-sql-2.15.2.jar
/org/apache/camel/component/swagger/main/camel-swagger-2.15.2.jar
/org/apache/camel/component/swagger/main/swagger-annotations-1.3.12.jar
Expand Down Expand Up @@ -156,5 +157,7 @@
/org/springframework/jdbc/main/spring-jdbc-4.1.6.RELEASE.jar
/org/springframework/jms/main/spring-jms-4.1.6.RELEASE.jar
/org/springframework/orm/main/spring-orm-4.1.6.RELEASE.jar
/org/springframework/security/main/spring-security-config-3.2.5.RELEASE.jar
/org/springframework/security/main/spring-security-core-3.2.5.RELEASE.jar
/org/springframework/spring-messaging/main/spring-messaging-4.1.6.RELEASE.jar
/org/springframework/tx/main/spring-tx-4.1.6.RELEASE.jar
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>
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>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<module name="org.apache.camel.component.script" export="true" services="export" />
<module name="org.apache.camel.component.servlet" export="true" services="export" />
<module name="org.apache.camel.component.soap" export="true" services="export" />
<module name="org.apache.camel.component.spring.security" export="true" services="export" />
<module name="org.apache.camel.component.sql" export="true" services="export" />
<module name="org.apache.camel.component.swagger" export="true" services="export" />
<module name="org.apache.camel.component.tagsoup" export="true" services="export" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#L%
-->




<!--
This is referenced in the base layer from org.apache.cxf as an optional dependency
-->
<module xmlns="urn:jboss:module:1.1" name="org.springframework.spring">

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<module name="org.springframework.beans"/>
<module name="org.springframework.core"/>
<module name="org.springframework.context"/>
<module name="org.springframework.security"/>
<module name="org.springframework.tx"/>
<module name="org.slf4j"/>
</dependencies>
Expand Down
Loading

0 comments on commit a70cb31

Please sign in to comment.