Namespace support for endpoint interceptor security
This commit is contained in:
@@ -16,23 +16,16 @@
|
||||
|
||||
package org.springframework.integration.security.channel.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.security.config.IncludeExcludePattern;
|
||||
import org.springframework.integration.security.config.IncludeExcludePatternParser;
|
||||
import org.springframework.integration.security.config.OrderedIncludeExcludeList;
|
||||
import org.springframework.security.context.SecurityContext;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Interprets the <secure-channels> element which controls default
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.security.config;
|
||||
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
import org.springframework.integration.security.channel.config.SecuredChannelsParser;
|
||||
import org.springframework.integration.security.channel.config.SecurityPropagatingChannelsParser;
|
||||
import org.springframework.integration.security.endpoint.config.SecurityEndpointInterceptorParser;
|
||||
|
||||
/**
|
||||
* Namespace handler for the security namespace.
|
||||
@@ -30,6 +31,7 @@ public class IntegrationSecurityNamespaceHandler extends NamespaceHandlerSupport
|
||||
public void init() {
|
||||
registerBeanDefinitionParser("secured-channels", new SecuredChannelsParser());
|
||||
registerBeanDefinitionParser("security-propagating-channels", new SecurityPropagatingChannelsParser());
|
||||
registerBeanDefinitionParser("endpoint-security-policy", new SecurityEndpointInterceptorParser());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</xsd:element>
|
||||
|
||||
|
||||
<xsd:element name="secured-targets">
|
||||
<xsd:element name="endpoint-security-policy">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
@@ -36,10 +36,7 @@
|
||||
Targets
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="targetNamePattern" type="xsd:string" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="access" type="xsd:string" />
|
||||
<xsd:attribute name="access" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="access-decision-manager"
|
||||
type="xsd:string" default="accessDecisionManager" />
|
||||
|
||||
@@ -48,7 +45,6 @@
|
||||
|
||||
<xsd:element name="security-propagating-channels">
|
||||
<xsd:complexType>
|
||||
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
Defines a bean post processor which propagates the
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.integration.security.endpoint;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.integration.endpoint.interceptor.EndpointInterceptorAdapter;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.security.SecurityContextUtils;
|
||||
@@ -35,7 +34,6 @@ public class SecurityEndpointInterceptor extends EndpointInterceptorAdapter {
|
||||
|
||||
private final AccessDecisionManager accessDecisionManager;
|
||||
|
||||
|
||||
public SecurityEndpointInterceptor(ConfigAttributeDefinition endpointSecurityAttributes,
|
||||
AccessDecisionManager accessDecisionManager) {
|
||||
super();
|
||||
@@ -43,7 +41,6 @@ public class SecurityEndpointInterceptor extends EndpointInterceptorAdapter {
|
||||
this.accessDecisionManager = accessDecisionManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean aroundInvoke(MethodInvocation invocation) throws Throwable {
|
||||
Message<?> message = (Message<?>) invocation.getArguments()[0];
|
||||
@@ -54,8 +51,8 @@ public class SecurityEndpointInterceptor extends EndpointInterceptorAdapter {
|
||||
if (securityContext != null) {
|
||||
try {
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
this.accessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(),
|
||||
invocation.getThis(), this.targetSecurityAttributes);
|
||||
this.accessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(), invocation
|
||||
.getThis(), this.targetSecurityAttributes);
|
||||
return (Boolean) invocation.proceed();
|
||||
}
|
||||
finally {
|
||||
@@ -63,8 +60,8 @@ public class SecurityEndpointInterceptor extends EndpointInterceptorAdapter {
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.accessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(),
|
||||
invocation.getThis(), this.targetSecurityAttributes);
|
||||
this.accessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(), invocation
|
||||
.getThis(), this.targetSecurityAttributes);
|
||||
return (Boolean) invocation.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.endpoint.config;
|
||||
|
||||
import org.springframework.beans.BeanMetadataAttribute;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.security.endpoint.SecurityEndpointInterceptor;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class SecurityEndpointInterceptorParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
public SecurityEndpointInterceptorParser() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateIdAsFallback() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String access = element.getAttribute("access");
|
||||
Assert.hasText(access, "Access attribute is required for element endpoint-security-policy");
|
||||
|
||||
String accessDecisionManager = element.getAttribute("access-decision-manager");
|
||||
Assert.hasText(accessDecisionManager, "A non null value for the access-decision-manager is required");
|
||||
|
||||
ConfigAttributeDefinition accessDefintion = new ConfigAttributeDefinition(StringUtils.tokenizeToStringArray(
|
||||
access, ","));
|
||||
builder.getBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(
|
||||
new ValueHolder(accessDefintion));
|
||||
builder.getBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(
|
||||
new RuntimeBeanReference(accessDecisionManager));
|
||||
|
||||
builder.getBeanDefinition().setBeanClass(SecurityEndpointInterceptor.class);
|
||||
String beanName = BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(),
|
||||
parserContext.getRegistry());
|
||||
builder.getBeanDefinition().addMetadataAttribute(new BeanMetadataAttribute("interceptorName", beanName));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user