INT-1408 fixed the issue with ConfigAttributes related to upgrading to Spring Security 3
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.integration.security.channel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
import org.springframework.security.access.SecurityConfig;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -30,9 +34,9 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class ChannelAccessPolicy {
|
||||
|
||||
private final ConfigAttribute configAttributeDefinitionForSend;
|
||||
private final Collection<ConfigAttribute> configAttributeDefinitionForSend;
|
||||
|
||||
private final ConfigAttribute configAttributeDefinitionForReceive;
|
||||
private final Collection<ConfigAttribute> configAttributeDefinitionForReceive;
|
||||
|
||||
|
||||
/**
|
||||
@@ -41,21 +45,39 @@ public class ChannelAccessPolicy {
|
||||
* will be trimmed. A <code>null</code> value indicates that the policy does not
|
||||
* apply for either send or receive access type. At most one of the values may be null.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessPolicy(String sendAccess, String receiveAccess) {
|
||||
Assert.isTrue(sendAccess != null || receiveAccess != null,
|
||||
boolean sendAccessDefined = StringUtils.hasText(sendAccess);
|
||||
boolean recieveAccessDefined = StringUtils.hasText(receiveAccess);
|
||||
Assert.isTrue(sendAccessDefined || recieveAccessDefined,
|
||||
"At least one of 'sendAccess' and 'receiveAccess' must not be null.");
|
||||
this.configAttributeDefinitionForSend = (StringUtils.hasText(sendAccess))
|
||||
? new SecurityConfig(sendAccess) : null;
|
||||
this.configAttributeDefinitionForReceive = (StringUtils.hasText(receiveAccess))
|
||||
? new SecurityConfig(receiveAccess) : null;
|
||||
|
||||
if (sendAccessDefined){
|
||||
String[] sendAccessValues = StringUtils.commaDelimitedListToStringArray(sendAccess);
|
||||
configAttributeDefinitionForSend = new HashSet<ConfigAttribute>();
|
||||
for (String sendAccessValue : sendAccessValues) {
|
||||
configAttributeDefinitionForSend.add(new SecurityConfig(StringUtils.trimAllWhitespace(sendAccessValue)));
|
||||
}
|
||||
} else {
|
||||
configAttributeDefinitionForSend = Collections.EMPTY_SET;
|
||||
}
|
||||
if (recieveAccessDefined){
|
||||
String[] receiveAccessValues = StringUtils.commaDelimitedListToStringArray(receiveAccess);
|
||||
configAttributeDefinitionForReceive = new HashSet<ConfigAttribute>();
|
||||
for (String receiveAccessValue : receiveAccessValues) {
|
||||
configAttributeDefinitionForReceive.add(new SecurityConfig(StringUtils.trimAllWhitespace(receiveAccessValue)));
|
||||
}
|
||||
} else {
|
||||
configAttributeDefinitionForReceive = Collections.EMPTY_SET;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ConfigAttribute getConfigAttributeDefinitionForSend() {
|
||||
public Collection<ConfigAttribute> getConfigAttributeDefinitionForSend() {
|
||||
return this.configAttributeDefinitionForSend;
|
||||
}
|
||||
|
||||
public ConfigAttribute getConfigAttributeDefinitionForReceive() {
|
||||
public Collection<ConfigAttribute> getConfigAttributeDefinitionForReceive() {
|
||||
return this.configAttributeDefinitionForReceive;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,15 +72,15 @@ public class ChannelInvocationDefinitionSource implements SecurityMetadataSource
|
||||
ChannelAccessPolicy accessPolicy = mapping.getValue();
|
||||
if (pattern.matcher(channelName).matches()) {
|
||||
if (invocation.isSend()) {
|
||||
ConfigAttribute definition = accessPolicy.getConfigAttributeDefinitionForSend();
|
||||
Collection<ConfigAttribute> definition = accessPolicy.getConfigAttributeDefinitionForSend();
|
||||
if (definition != null) {
|
||||
attributes.add(definition);
|
||||
attributes.addAll(definition);
|
||||
}
|
||||
}
|
||||
else if (invocation.isReceive()) {
|
||||
ConfigAttribute definition = accessPolicy.getConfigAttributeDefinitionForReceive();
|
||||
Collection<ConfigAttribute> definition = accessPolicy.getConfigAttributeDefinitionForReceive();
|
||||
if (definition != null) {
|
||||
attributes.add(definition);
|
||||
attributes.addAll(definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,14 +92,10 @@ public class ChannelInvocationDefinitionSource implements SecurityMetadataSource
|
||||
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);
|
||||
}
|
||||
Collection<ConfigAttribute> receiveAttributes = policy.getConfigAttributeDefinitionForReceive();
|
||||
allAttributes.addAll(receiveAttributes);
|
||||
Collection<ConfigAttribute> sendAttributes = policy.getConfigAttributeDefinitionForSend();
|
||||
allAttributes.addAll(sendAttributes);
|
||||
}
|
||||
|
||||
return allAttributes;
|
||||
|
||||
Reference in New Issue
Block a user