refactored security namespace to use separate schema

This commit is contained in:
Jonas Partner
2008-06-25 17:29:32 +00:00
parent a2a40bca4d
commit 5709c4e144
32 changed files with 997 additions and 549 deletions

View File

@@ -0,0 +1,139 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.List;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.ChannelInterceptor;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.selector.MessageSelector;
/**
*
* @author Jonas Partner
*
*/
public class ChannelInterceptorRegisteringBeanPostProcessorTests {
public ArrayList<String> matchAll;
@Before
public void setUp() {
matchAll = new ArrayList<String>();
matchAll.add(".*");
}
@Test
public void testWithAbstractMessageChannel() {
ChannelInterceptorRegisteringBeanPostProcessor postprocessor = new ChannelInterceptorRegisteringBeanPostProcessor(
new TestInterceptor(), matchAll);
TestChannel channel = new TestChannel();
postprocessor.postProcessAfterInitialization(channel, "shouldNotMatter");
assertNotNull("No channel interceptor present after post processing", channel.channelInterceptor);
}
@Test
public void testWithAbstractMessageChannelAndPatternThatDoes() {
ChannelInterceptorRegisteringBeanPostProcessor postprocessor = new ChannelInterceptorRegisteringBeanPostProcessor(
new TestInterceptor(), matchAll);
TestChannel channel = new TestChannel();
postprocessor.postProcessAfterInitialization(channel, "shouldNotMatter");
assertNotNull("No channel interceptor present after post processing", channel.channelInterceptor);
}
@Test
public void testWithMockMessageChanne() {
MessageChannel channel = EasyMock.createStrictMock(MessageChannel.class);
EasyMock.replay(channel);
ChannelInterceptorRegisteringBeanPostProcessor postprocessor = new ChannelInterceptorRegisteringBeanPostProcessor(
new TestInterceptor(), matchAll);
postprocessor.postProcessAfterInitialization(channel, "shouldNotMatter");
EasyMock.verify(channel);
}
static class TestInterceptor implements ChannelInterceptor {
public void postReceive(Message<?> message, MessageChannel channel) {
// TODO Auto-generated method stub
}
public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
// TODO Auto-generated method stub
}
public boolean preReceive(MessageChannel channel) {
// TODO Auto-generated method stub
return false;
}
public boolean preSend(Message<?> message, MessageChannel channel) {
// TODO Auto-generated method stub
return false;
}
}
static class TestChannel extends AbstractMessageChannel {
ChannelInterceptor channelInterceptor;
public TestChannel() {
super(null);
}
@Override
public void addInterceptor(ChannelInterceptor interceptor) {
channelInterceptor = interceptor;
super.addInterceptor(interceptor);
}
@Override
protected Message<?> doReceive(long timeout) {
// TODO Auto-generated method stub
return null;
}
@Override
protected boolean doSend(Message<?> message, long timeout) {
// TODO Auto-generated method stub
return false;
}
public List<Message<?>> clear() {
// TODO Auto-generated method stub
return null;
}
public List<Message<?>> purge(MessageSelector selector) {
// TODO Auto-generated method stub
return null;
}
}
}

View File

@@ -45,8 +45,7 @@ public class SecurityContextAssociatingHandlerInterceptorTests {
public void testMessageWithSecurityContext() {
final StubSecurityContext securityContext = new StubSecurityContext();
StringMessage message = new StringMessage("test");
message.getHeader().setAttribute(
SecurityContextPropagatingChannelInterceptor.SECURITY_CONTEXT_HEADER_ATTRIBUTE, securityContext);
SecurityContextUtils.setSecurityContextHeader(securityContext, message);
MessageHandler handler = new MessageHandler() {
public Message<?> handle(Message<?> message) {
SecurityContext associatedContext = SecurityContextHolder.getContext();
@@ -65,8 +64,7 @@ public class SecurityContextAssociatingHandlerInterceptorTests {
public void testForSecurityLeakageIfHandlerThrowsException() {
final StubSecurityContext securityContext = new StubSecurityContext();
StringMessage message = new StringMessage("test");
message.getHeader().setAttribute(
SecurityContextPropagatingChannelInterceptor.SECURITY_CONTEXT_HEADER_ATTRIBUTE, securityContext);
SecurityContextUtils.setSecurityContextHeader(securityContext, message);
MessageHandler handler = new MessageHandler() {
public Message<?> handle(Message<?> message) {
SecurityContext associatedContext = SecurityContextHolder.getContext();

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.security;
package org.springframework.integration.security.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -26,6 +26,7 @@ import org.junit.Test;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.message.MessageHeader;
import org.springframework.integration.message.StringMessage;
import org.springframework.integration.security.SecurityContextUtils;
import org.springframework.security.Authentication;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.context.SecurityContext;
@@ -65,9 +66,8 @@ public class SecurityContextPropagatingChannelInterceptorTests {
message = (StringMessage) channel.receive(0);
MessageHeader header = message.getHeader();
assertTrue("No security context attribute found in header.",
header.getAttributeNames().contains(SecurityContextPropagatingChannelInterceptor.SECURITY_CONTEXT_HEADER_ATTRIBUTE));
SecurityContext contextFromHeader = (SecurityContext) header.getAttribute(
SecurityContextPropagatingChannelInterceptor.SECURITY_CONTEXT_HEADER_ATTRIBUTE);
header.getAttributeNames().contains(SecurityContextUtils.SECURITY_CONTEXT_HEADER_ATTRIBUTE));
SecurityContext contextFromHeader = SecurityContextUtils.getSecurityContextFromHeader(message);
assertEquals("Incorrect security context in message header.", securityContext, contextFromHeader);
}
@@ -78,7 +78,7 @@ public class SecurityContextPropagatingChannelInterceptorTests {
message = (StringMessage) channel.receive(0);
MessageHeader header = message.getHeader();
assertFalse("Security context header found when no security context existed.",
header.getAttributeNames().contains(SecurityContextPropagatingChannelInterceptor.SECURITY_CONTEXT_HEADER_ATTRIBUTE));
header.getAttributeNames().contains(SecurityContextUtils.SECURITY_CONTEXT_HEADER_ATTRIBUTE));
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.security;
package org.springframework.integration.security.channel;
import static org.junit.Assert.assertEquals;
@@ -24,6 +24,7 @@ import org.junit.Test;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.message.StringMessage;
import org.springframework.integration.security.channel.SecurityEnforcingChannelInterceptor;
import org.springframework.security.AccessDecisionManager;
import org.springframework.security.AccessDeniedException;
import org.springframework.security.Authentication;
@@ -124,9 +125,8 @@ public class SecurityEnforcingChannelInterceptorTests {
private void registerInterceptor(AccessDecisionManager accessDecisionManager) {
securityChannelInterceptor = new SecurityEnforcingChannelInterceptor(
accessDecisionManager, channel);
securityChannelInterceptor = new SecurityEnforcingChannelInterceptor(accessDecisionManager);
channel.addInterceptor(securityChannelInterceptor);
}

View File

@@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<beans:import resource="commonSecurityConfiguration.xml"/>
<message-bus/>
<channel id="propagationDefault"/>
<channel id="excludedFromPropagation">
<secured propagate="false"/>
</channel>
</beans:beans>

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:si-security="http://www.springframework.org/schema/integration-security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration-security http://www.springframework.org/schema/integration/spring-integration-security-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<beans:import resource="commonSecurityConfiguration.xml"/>
<si-security:secured-channels send-access="ROLE_ADMIN" propagate="false">
<si-security:channel-name-pattern>adminRequiredForSend</si-security:channel-name-pattern>
</si-security:secured-channels>
<si-security:secured-channels send-access="ROLE_ADMIN, ROLE_USER" propagate="false">
<si-security:channel-name-pattern>adminOrUserRequiredForSend</si-security:channel-name-pattern>
</si-security:secured-channels>
<si-security:secured-channels receive-access="ROLE_ADMIN" propagate="false">
<si-security:channel-name-pattern>adminRequiredForReceive</si-security:channel-name-pattern>
</si-security:secured-channels>
<si-security:secured-channels receive-access="ROLE_ADMIN, ROLE_USER" propagate="false">
<si-security:channel-name-pattern>adminOrUserRequiredForReceive</si-security:channel-name-pattern>
</si-security:secured-channels>
<si-security:secured-channels receive-access="ROLE_ADMIN" send-access="ROLE_ADMIN" propagate="false">
<si-security:channel-name-pattern>adminForSendAndReceive</si-security:channel-name-pattern>
</si-security:secured-channels>
</beans:beans>

View File

@@ -0,0 +1,140 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.config;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.ChannelInterceptor;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.selector.MessageSelector;
import org.springframework.integration.security.channel.SecurityEnforcingChannelInterceptor;
import org.springframework.security.ConfigAttribute;
import org.springframework.security.ConfigAttributeDefinition;
import org.springframework.security.SecurityConfig;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* @author Jonas Partner
*/
@ContextConfiguration
public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests{
TestMessageChannel messageChannel ;
@Before
public void setUp(){
messageChannel = new TestMessageChannel();
}
@Test
public void testAdminRequiredForSend(){
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminRequiredForSend");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0);
assertTrue("ROLE_ADMIN not found as send attribute", interceptor.getSendSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN")));
assertNull("Receive security attribute were not null", interceptor.getReceiveSecurityAttributes());
}
@Test
public void testAdminOrUserRequiredForSend(){
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminOrUserRequiredForSend");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0);
assertTrue("ROLE_ADMIN not found as send attribute", interceptor.getSendSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN")));
assertTrue("ROLE_USER not found as send attribute", interceptor.getSendSecurityAttributes().contains(new SecurityConfig("ROLE_USER")));
assertNull("Receive security attribute were not null", interceptor.getReceiveSecurityAttributes());
}
@Test
public void testAdminRequiredForReceive(){
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminRequiredForReceive");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0);
assertTrue("ROLE_ADMIN not found as receive attribute", interceptor.getReceiveSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN")));
assertNull("Send security attribute were not null", interceptor.getSendSecurityAttributes());
}
@Test
public void testAdminOrUserRequiredForReceive(){
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminOrUserRequiredForReceive");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0);
assertTrue("ROLE_ADMIN not found as receive attribute", interceptor.getReceiveSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN")));
assertTrue("ROLE_USER not found as receive attribute", interceptor.getReceiveSecurityAttributes().contains(new SecurityConfig("ROLE_USER")));
assertNull("Send security attribute were not null", interceptor.getSendSecurityAttributes());
}
@Test
public void testAdminRequiredForSendAndReceive(){
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminForSendAndReceive");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0);
assertTrue("ROLE_ADMIN not found as receive attribute", interceptor.getReceiveSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN")));
assertTrue("ROLE_USER not found as send attribute", interceptor.getSendSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN")));
}
static class TestMessageChannel extends AbstractMessageChannel {
List<ChannelInterceptor> interceptors = new ArrayList<ChannelInterceptor>();
public TestMessageChannel() {
super(null);
}
@Override
protected Message<?> doReceive(long timeout) {
// TODO Auto-generated method stub
return null;
}
@Override
protected boolean doSend(Message<?> message, long timeout) {
// TODO Auto-generated method stub
return false;
}
public List<Message<?>> clear() {
// TODO Auto-generated method stub
return null;
}
public List<Message<?>> purge(MessageSelector selector) {
// TODO Auto-generated method stub
return null;
}
@Override
public void addInterceptor(ChannelInterceptor interceptor) {
interceptors.add(interceptor);
}
}
}

View File

@@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<beans:import resource="commonSecurityConfiguration.xml"/>
<message-bus/>
<channel id="unsecured" />
<channel id="adminRequiredForSend" >
<secured send-access="ROLE_ADMIN" />
</channel>
<channel id="adminRequiredForReceive" >
<secured receive-access="ROLE_ADMIN" />
</channel>
<channel id="adminRequiredForSendAndReceive">
<secured send-access="ROLE_ADMIN" receive-access="ROLE_ADMIN" />
</channel>
</beans:beans>

View File

@@ -1,136 +0,0 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.config;
import static org.junit.Assert.assertNotNull;
import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.message.StringMessage;
import org.springframework.security.AccessDeniedException;
import org.springframework.security.context.SecurityContext;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.security.context.SecurityContextImpl;
import org.springframework.security.providers.AuthenticationProvider;
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
* @author Jonas Partner
*/
@ContextConfiguration
public class SecuredParserTests extends AbstractJUnit4SpringContextTests{
@Autowired
private AuthenticationProvider provider;
@Autowired
@Qualifier("unsecured")
public MessageChannel unsecuredChannel;
@Autowired
@Qualifier("adminRequiredForSend")
public MessageChannel adminRequiredForSend;
@Autowired
@Qualifier("adminRequiredForReceive")
public MessageChannel adminRequiredForReceive;
@Autowired
@Qualifier("adminRequiredForSendAndReceive")
public MessageChannel adminRequiredForSendAndReceive;
@After
public void tearDown() {
SecurityContextHolder.clearContext();
}
@Test
public void testNoSecurityRestrictionsOnChannel() {
unsecuredChannel.send(new StringMessage("testUnsecured"));
assertNotNull("Message not received ", unsecuredChannel.receive(0));
}
@Test
public void testAdminRequiredForSendWithAccessGranted() {
login("jimi", "jimispassword");
adminRequiredForSend.send(new StringMessage("testmessage"));
assertNotNull("Message not received", adminRequiredForSend.receive(0));
}
@Test(expected=AccessDeniedException.class)
public void testAdminRequiredForSendWithAccessDenied() {
login("bob", "bobspassword");
adminRequiredForSend.send(new StringMessage("testmessage"));
}
@Test
public void testAdminRequiredForReceiveWithAccessGranted(){
adminRequiredForReceive.send(new StringMessage("testmessage"));
login("jimi", "jimispassword");
assertNotNull("Message not received", adminRequiredForReceive.receive(0));
}
@Test(expected=AccessDeniedException.class)
public void testAdminRequiredForReceiveWithAccessDenied() {
adminRequiredForReceive.send(new StringMessage("testmessage"));
login("bob", "bobspassword");
adminRequiredForReceive.receive(0);
}
@Test
public void testAdminRequiredForSendAndReceiveWithSendAccessGranted() {
login("jimi", "jimispassword");
adminRequiredForSendAndReceive.send(new StringMessage("test"));
}
@Test(expected=AccessDeniedException.class)
public void testAdminRequiredForSendAndReceiveWithSendAccessDenied() {
login("bob", "bobspassword");
adminRequiredForSendAndReceive.send(new StringMessage("test"));
}
@Test
public void testAdminRequiredForSendAndReceiveWithReceiveAccessGranted() {
login("jimi", "jimispassword");
adminRequiredForSendAndReceive.send(new StringMessage("test"));
assertNotNull("Message not received", adminRequiredForSendAndReceive.receive(0));
}
@Test(expected=AccessDeniedException.class)
public void testAdminRequiredForSendAndReceiveWithReceiveAccessDenied() {
login("bob","bobspassword");
adminRequiredForSendAndReceive.receive(0);
}
private void login(String username, String password) {
UsernamePasswordAuthenticationToken authToken = (UsernamePasswordAuthenticationToken)
provider.authenticate(new UsernamePasswordAuthenticationToken(username, password));
SecurityContext context = new SecurityContextImpl();
context.setAuthentication(authToken);
SecurityContextHolder.setContext(context);
}
}

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:si-security="http://www.springframework.org/schema/integration-security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
@@ -7,22 +8,26 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration-security http://www.springframework.org/schema/integration/spring-integration-security-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<beans:import resource="commonSecurityConfiguration.xml"/>
<message-bus/>
<secure-channels propagate="true"/>
<channel id="propagationDefault"/>
<channel id="excludedFromPropagation">
<secured propagate="false"/>
</channel>
<si-security:secured-channels send-access="ROLE_ADMIN" >
<si-security:channel-name-pattern>adminRequiredForSend</si-security:channel-name-pattern>
</si-security:secured-channels>
<channel id="includedInProaogation">
<secured propagate="true"/>
</channel>
<si-security:secured-channels propagate="false">
<si-security:channel-name-pattern>excludedFromPropagation</si-security:channel-name-pattern>
</si-security:secured-channels>
<channel id="excludedFromPropagation"/>
</beans:beans>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:si-security="http://www.springframework.org/schema/integration-security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/integration-security http://www.springframework.org/schema/integration/spring-integration-security-1.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<beans:import resource="commonSecurityConfiguration.xml"/>
<message-bus/>
<si-security:security-propagating-channels propagate="true"/>
<channel id="propagationDefault"/>
<channel id="excludedFromPropagation" />
<si-security:secured-channels propagate="false">
<si-security:channel-name-pattern>excludedFromPropagation</si-security:channel-name-pattern>
</si-security:secured-channels>
<channel id="includedInPropagation" />
<si-security:secured-channels propagate="true">
<si-security:channel-name-pattern>includedInPropagation</si-security:channel-name-pattern>
</si-security:secured-channels>
<security:authentication-provider user-service-ref="userDetailsService"/>
<security:user-service id="userDetailsService">
<security:user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN"/>
<security:user name="bob" password="bobspassword" authorities="ROLE_USER"/>
</security:user-service>
</beans:beans>

View File

@@ -36,7 +36,7 @@ import org.springframework.security.providers.UsernamePasswordAuthenticationToke
/**
* @author Jonas Partner
*/
public class SecureChannelsParserTests {
public class SecurityPropagatingChannelsParserTests {
private ClassPathXmlApplicationContext applicationContext;

View File

@@ -0,0 +1,46 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.config;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.GrantedAuthorityImpl;
import org.springframework.security.context.SecurityContext;
import org.springframework.security.context.SecurityContextImpl;
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
/**
*
* @author Jonas Partner
*
*/
public class SecurityTestUtil {
public static SecurityContext createContext(String username, String password, String... roles){
SecurityContextImpl ctxImpl = new SecurityContextImpl();
UsernamePasswordAuthenticationToken authToken;
if(roles != null && roles.length > 0){
GrantedAuthority[] authorities = new GrantedAuthority[roles.length];
for (int i =0; i < roles.length; i++) {
authorities[i] = new GrantedAuthorityImpl(roles[i]);
}
authToken = new UsernamePasswordAuthenticationToken(username,password,authorities);
} else {
authToken = new UsernamePasswordAuthenticationToken(username, password);
}
ctxImpl.setAuthentication(authToken);
return ctxImpl;
}
}