INT-1115 upgraded si-security module to use Spring Security 3.0.2

This commit is contained in:
Oleg Zhurakousky
2010-07-20 21:12:01 +00:00
parent 8c2b9184a5
commit aed4b3bc26
13 changed files with 171 additions and 98 deletions

View File

@@ -16,7 +16,8 @@
package org.springframework.integration.security.channel;
import org.springframework.security.ConfigAttributeDefinition;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -25,12 +26,13 @@ import org.springframework.util.StringUtils;
* send and receive operations based on simple String values.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public class ChannelAccessPolicy {
private final ConfigAttributeDefinition configAttributeDefinitionForSend;
private final ConfigAttribute configAttributeDefinitionForSend;
private final ConfigAttributeDefinition configAttributeDefinitionForReceive;
private final ConfigAttribute configAttributeDefinitionForReceive;
/**
@@ -42,22 +44,18 @@ public class ChannelAccessPolicy {
public ChannelAccessPolicy(String sendAccess, String receiveAccess) {
Assert.isTrue(sendAccess != null || receiveAccess != null,
"At least one of 'sendAccess' and 'receiveAccess' must not be null.");
String[] sendValues = StringUtils.trimArrayElements(
StringUtils.commaDelimitedListToStringArray(sendAccess));
String[] receiveValues = StringUtils.trimArrayElements(
StringUtils.commaDelimitedListToStringArray(receiveAccess));
this.configAttributeDefinitionForSend = (sendValues.length > 0)
? new ConfigAttributeDefinition(sendValues) : null;
this.configAttributeDefinitionForReceive = (receiveValues.length > 0)
? new ConfigAttributeDefinition(receiveValues) : null;
this.configAttributeDefinitionForSend = (StringUtils.hasText(sendAccess))
? new SecurityConfig(sendAccess) : null;
this.configAttributeDefinitionForReceive = (StringUtils.hasText(receiveAccess))
? new SecurityConfig(receiveAccess) : null;
}
public ConfigAttributeDefinition getConfigAttributeDefinitionForSend() {
public ConfigAttribute getConfigAttributeDefinitionForSend() {
return this.configAttributeDefinitionForSend;
}
public ConfigAttributeDefinition getConfigAttributeDefinitionForReceive() {
public ConfigAttribute getConfigAttributeDefinitionForReceive() {
return this.configAttributeDefinitionForReceive;
}

View File

@@ -27,17 +27,17 @@ import java.util.regex.Pattern;
import org.springframework.integration.context.NamedComponent;
import org.springframework.integration.core.MessageChannel;
import org.springframework.security.ConfigAttribute;
import org.springframework.security.ConfigAttributeDefinition;
import org.springframework.security.intercept.ObjectDefinitionSource;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityMetadataSource;
import org.springframework.util.Assert;
/**
* The {@link ObjectDefinitionSource} implementation for secured {@link MessageChannel}s.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public class ChannelInvocationDefinitionSource implements ObjectDefinitionSource {
public class ChannelInvocationDefinitionSource implements SecurityMetadataSource {
private final Map<Pattern, ChannelAccessPolicy> patternMappings;
@@ -60,13 +60,7 @@ public class ChannelInvocationDefinitionSource implements ObjectDefinitionSource
return this.patternMappings.keySet();
}
@SuppressWarnings("unchecked")
public boolean supports(Class clazz) {
return ChannelInvocation.class.isAssignableFrom(clazz);
}
@SuppressWarnings("unchecked")
public ConfigAttributeDefinition getAttributes(Object object) throws IllegalArgumentException {
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
Assert.isAssignable(ChannelInvocation.class, object.getClass());
ChannelInvocation invocation = (ChannelInvocation) object;
MessageChannel channel = invocation.getChannel();
@@ -78,35 +72,40 @@ public class ChannelInvocationDefinitionSource implements ObjectDefinitionSource
ChannelAccessPolicy accessPolicy = mapping.getValue();
if (pattern.matcher(channelName).matches()) {
if (invocation.isSend()) {
ConfigAttributeDefinition definition = accessPolicy.getConfigAttributeDefinitionForSend();
ConfigAttribute definition = accessPolicy.getConfigAttributeDefinitionForSend();
if (definition != null) {
attributes.addAll(definition.getConfigAttributes());
attributes.add(definition);
}
}
else if (invocation.isReceive()) {
ConfigAttributeDefinition definition = accessPolicy.getConfigAttributeDefinitionForReceive();
ConfigAttribute definition = accessPolicy.getConfigAttributeDefinitionForReceive();
if (definition != null) {
attributes.addAll(definition.getConfigAttributes());
attributes.add(definition);
}
}
}
}
return new ConfigAttributeDefinition(attributes);
return attributes;
}
public Collection<?> getConfigAttributeDefinitions() {
Set<ConfigAttributeDefinition> definitions = new HashSet<ConfigAttributeDefinition>();
for (ChannelAccessPolicy accessPolicy : this.patternMappings.values()) {
ConfigAttributeDefinition sendDefinition = accessPolicy.getConfigAttributeDefinitionForSend();
if (sendDefinition != null) {
definitions.add(sendDefinition);
}
ConfigAttributeDefinition receiveDefinition = accessPolicy.getConfigAttributeDefinitionForReceive();
if (receiveDefinition != null) {
definitions.add(receiveDefinition);
}
}
return definitions;
public Collection<ConfigAttribute> getAllConfigAttributes() {
Set<ConfigAttribute> allAttributes = new HashSet<ConfigAttribute>();
for (ChannelAccessPolicy policy : patternMappings.values()) {
ConfigAttribute attribute = policy.getConfigAttributeDefinitionForReceive();
if (attribute != null){
allAttributes.add(attribute);
}
attribute = policy.getConfigAttributeDefinitionForSend();
if (attribute != null){
allAttributes.add(attribute);
}
}
return allAttributes;
}
public boolean supports(Class<?> clazz) {
return ChannelInvocation.class.isAssignableFrom(clazz);
}
}

View File

@@ -20,16 +20,16 @@ import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.security.intercept.AbstractSecurityInterceptor;
import org.springframework.security.intercept.InterceptorStatusToken;
import org.springframework.security.intercept.ObjectDefinitionSource;
import org.springframework.security.access.SecurityMetadataSource;
import org.springframework.security.access.intercept.AbstractSecurityInterceptor;
import org.springframework.security.access.intercept.InterceptorStatusToken;
import org.springframework.util.Assert;
/**
* An AOP interceptor that enforces authorization for MessageChannel send and/or receive calls.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public class ChannelSecurityInterceptor extends AbstractSecurityInterceptor implements MethodInterceptor {
@@ -47,10 +47,6 @@ public class ChannelSecurityInterceptor extends AbstractSecurityInterceptor impl
return ChannelInvocation.class;
}
@Override
public ObjectDefinitionSource obtainObjectDefinitionSource() {
return this.objectDefinitionSource;
}
public Object invoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
@@ -72,4 +68,10 @@ public class ChannelSecurityInterceptor extends AbstractSecurityInterceptor impl
return returnValue;
}
@Override
public SecurityMetadataSource obtainSecurityMetadataSource() {
return this.objectDefinitionSource;
}
}

View File

@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
* A {@link BeanPostProcessor} that proxies {@link MessageChannel}s to apply a {@link ChannelSecurityInterceptor}.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*/
public class ChannelSecurityInterceptorBeanPostProcessor implements BeanPostProcessor {
@@ -50,7 +51,7 @@ public class ChannelSecurityInterceptorBeanPostProcessor implements BeanPostProc
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof MessageChannel && shouldProxy(beanName, (MessageChannel) bean,
(ChannelInvocationDefinitionSource) this.interceptor.obtainObjectDefinitionSource())) {
(ChannelInvocationDefinitionSource) this.interceptor.obtainSecurityMetadataSource())) {
ProxyFactory proxyFactory = new ProxyFactory(bean);
proxyFactory.addAdvisor(new DefaultPointcutAdvisor(this.interceptor));
return proxyFactory.getProxy();
@@ -59,7 +60,7 @@ public class ChannelSecurityInterceptorBeanPostProcessor implements BeanPostProc
}
private boolean shouldProxy(String beanName, MessageChannel channel, ChannelInvocationDefinitionSource definitionSource) {
Set<Pattern> patterns = ((ChannelInvocationDefinitionSource) this.interceptor.obtainObjectDefinitionSource()).getPatterns();
Set<Pattern> patterns = ((ChannelInvocationDefinitionSource) this.interceptor.obtainSecurityMetadataSource()).getPatterns();
for (Pattern pattern : patterns) {
if (pattern.matcher(beanName).matches()) {
return true;