SecurityEndpointInterceptor no longer uses a temporary version of the EndpointInterceptor.
This commit is contained in:
@@ -17,20 +17,25 @@
|
||||
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;
|
||||
import org.springframework.security.AccessDecisionManager;
|
||||
import org.springframework.security.ConfigAttributeDefinition;
|
||||
import org.springframework.security.context.SecurityContext;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.temp.endpoint.EndpointInterceptor;
|
||||
|
||||
public class SecurityEndpointInterceptor implements EndpointInterceptor {
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class SecurityEndpointInterceptor extends EndpointInterceptorAdapter {
|
||||
|
||||
private final ConfigAttributeDefinition targetSecurityAttributes;
|
||||
|
||||
private final AccessDecisionManager accessDecisionManager;
|
||||
|
||||
|
||||
public SecurityEndpointInterceptor(ConfigAttributeDefinition endpointSecurityAttributes,
|
||||
AccessDecisionManager accessDecisionManager) {
|
||||
super();
|
||||
@@ -38,38 +43,30 @@ public class SecurityEndpointInterceptor implements EndpointInterceptor {
|
||||
this.accessDecisionManager = accessDecisionManager;
|
||||
}
|
||||
|
||||
public void aroundInvoke(MethodInvocation invocation) throws Throwable {
|
||||
|
||||
@Override
|
||||
public boolean aroundInvoke(MethodInvocation invocation) throws Throwable {
|
||||
Message<?> message = (Message<?>) invocation.getArguments()[0];
|
||||
|
||||
SecurityContext securityCtx = null;
|
||||
|
||||
if(message != null){
|
||||
securityCtx = SecurityContextUtils.getSecurityContextFromHeader(message);
|
||||
SecurityContext securityContext = null;
|
||||
if (message != null) {
|
||||
securityContext = SecurityContextUtils.getSecurityContextFromHeader(message);
|
||||
}
|
||||
if (securityCtx != null) {
|
||||
if (securityContext != null) {
|
||||
try {
|
||||
SecurityContextHolder.setContext(securityCtx);
|
||||
accessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(), invocation
|
||||
.getThis(), targetSecurityAttributes);
|
||||
invocation.proceed();
|
||||
SecurityContextHolder.setContext(securityContext);
|
||||
this.accessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(),
|
||||
invocation.getThis(), this.targetSecurityAttributes);
|
||||
return (Boolean) invocation.proceed();
|
||||
}
|
||||
finally {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
}
|
||||
else {
|
||||
accessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(), invocation.getThis(),
|
||||
targetSecurityAttributes);
|
||||
invocation.proceed();
|
||||
this.accessDecisionManager.decide(SecurityContextHolder.getContext().getAuthentication(),
|
||||
invocation.getThis(), this.targetSecurityAttributes);
|
||||
return (Boolean) invocation.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
public void postInvoke(Message message) {
|
||||
|
||||
}
|
||||
|
||||
public void preInvoke(Message message) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +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.temp.endpoint;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
public interface EndpointInterceptor {
|
||||
|
||||
void preInvoke(Message message);
|
||||
|
||||
void aroundInvoke(MethodInvocation invocation) throws Throwable;
|
||||
|
||||
void postInvoke(Message message);
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.security.SecurityContextUtils;
|
||||
@@ -32,9 +33,7 @@ import org.springframework.security.context.SecurityContext;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*
|
||||
*/
|
||||
public class SecurityEndpointInterceptorTests {
|
||||
|
||||
@@ -93,7 +92,7 @@ public class SecurityEndpointInterceptorTests {
|
||||
SecurityContext context = SecurityTestUtil.createContext("bob", "bobspassword",
|
||||
new String[] { "ROLE_ADMIN" });
|
||||
MethodInvocation invocation = createTestMethodInvocation(target, context);
|
||||
expect(invocation.proceed()).andReturn(null);
|
||||
expect(invocation.proceed()).andReturn(Boolean.TRUE);
|
||||
replay(invocation);
|
||||
|
||||
ConfigAttributeDefinition attDefintion = new ConfigAttributeDefinition("ROLE_ADMIN");
|
||||
|
||||
Reference in New Issue
Block a user