tidied up a few warnings

This commit is contained in:
Jonas Partner
2008-06-26 09:22:43 +00:00
parent c18ec83cbf
commit 6812c7eb2e
6 changed files with 61 additions and 52 deletions

View File

@@ -31,6 +31,7 @@ import org.springframework.security.AccessDecisionManager;
import org.springframework.security.ConfigAttributeDefinition; import org.springframework.security.ConfigAttributeDefinition;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@SuppressWarnings("serial")
public class TargetSecuringAdvisor extends AbstractPointcutAdvisor implements Pointcut { public class TargetSecuringAdvisor extends AbstractPointcutAdvisor implements Pointcut {
private ClassFilter classFilter; private ClassFilter classFilter;

View File

@@ -28,12 +28,14 @@ import org.springframework.integration.message.Message;
public class TargetSendMethodArgMatcher extends StaticMethodMatcher{ public class TargetSendMethodArgMatcher extends StaticMethodMatcher{
@SuppressWarnings("unchecked")
public boolean matches(Method method, Class targetClass) { public boolean matches(Method method, Class targetClass) {
return argsTypesMatch(method.getParameterTypes()); return argsTypesMatch(method.getParameterTypes());
} }
@SuppressWarnings("unchecked")
protected boolean argsTypesMatch(Class[] args){ protected boolean argsTypesMatch(Class[] args){
if(args.length > 2){ if(args.length > 2){
return false; return false;

View File

@@ -16,7 +16,6 @@
package org.springframework.integration.security.channel; package org.springframework.integration.security.channel;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.MessageChannel; import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter; import org.springframework.integration.channel.interceptor.ChannelInterceptorAdapter;
import org.springframework.integration.message.Message; import org.springframework.integration.message.Message;

View File

@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.easymock.EasyMock; import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.AbstractMessageChannel;

View File

@@ -43,11 +43,6 @@ public class TargetSecuringAdvisorTests {
} }
@Test
public void testTargetSendIntercpeted() {
TestTarget target = new TestTarget();
}
@Test(expected = AccessDeniedException.class) @Test(expected = AccessDeniedException.class)
public void testTargetSendAdvised() { public void testTargetSendAdvised() {
TargetSecuringAdvisor advisor = new TargetSecuringAdvisor(new AlwaysDenyAccessDecisionManager(), "ROLE_ADMIN"); TargetSecuringAdvisor advisor = new TargetSecuringAdvisor(new AlwaysDenyAccessDecisionManager(), "ROLE_ADMIN");
@@ -92,6 +87,7 @@ public class TargetSecuringAdvisorTests {
return true; return true;
} }
@SuppressWarnings("unchecked")
public boolean supports(Class clazz) { public boolean supports(Class clazz) {
return true; return true;
} }

View File

@@ -16,21 +16,20 @@
package org.springframework.integration.security.config; package org.springframework.integration.security.config;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.AbstractMessageChannel; import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.channel.ChannelInterceptor; import org.springframework.integration.channel.ChannelInterceptor;
import org.springframework.integration.message.Message; import org.springframework.integration.message.Message;
import org.springframework.integration.message.selector.MessageSelector; import org.springframework.integration.message.selector.MessageSelector;
import org.springframework.integration.security.channel.SecurityEnforcingChannelInterceptor; 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.security.SecurityConfig;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
@@ -39,71 +38,84 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
* @author Jonas Partner * @author Jonas Partner
*/ */
@ContextConfiguration @ContextConfiguration
public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests{ public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests {
TestMessageChannel messageChannel;
TestMessageChannel messageChannel ;
@Before @Before
public void setUp(){ public void setUp() {
messageChannel = new TestMessageChannel(); messageChannel = new TestMessageChannel();
} }
@Test @Test
public void testAdminRequiredForSend(){ public void testAdminRequiredForSend() {
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminRequiredForSend"); applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel,
"adminRequiredForSend");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size()); assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0); SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor) messageChannel.interceptors
assertTrue("ROLE_ADMIN not found as send attribute", interceptor.getSendSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN"))); .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()); assertNull("Receive security attribute were not null", interceptor.getReceiveSecurityAttributes());
} }
@Test @Test
public void testAdminOrUserRequiredForSend(){ public void testAdminOrUserRequiredForSend() {
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminOrUserRequiredForSend"); applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel,
"adminOrUserRequiredForSend");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size()); assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0); SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor) messageChannel.interceptors
assertTrue("ROLE_ADMIN not found as send attribute", interceptor.getSendSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN"))); .get(0);
assertTrue("ROLE_USER not found as send attribute", interceptor.getSendSecurityAttributes().contains(new SecurityConfig("ROLE_USER"))); 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()); assertNull("Receive security attribute were not null", interceptor.getReceiveSecurityAttributes());
} }
@Test @Test
public void testAdminRequiredForReceive(){ public void testAdminRequiredForReceive() {
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminRequiredForReceive"); applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel,
"adminRequiredForReceive");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size()); assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0); SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor) messageChannel.interceptors
assertTrue("ROLE_ADMIN not found as receive attribute", interceptor.getReceiveSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN"))); .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()); assertNull("Send security attribute were not null", interceptor.getSendSecurityAttributes());
} }
@Test @Test
public void testAdminOrUserRequiredForReceive(){ public void testAdminOrUserRequiredForReceive() {
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminOrUserRequiredForReceive"); applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel,
"adminOrUserRequiredForReceive");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size()); assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0); SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor) messageChannel.interceptors
assertTrue("ROLE_ADMIN not found as receive attribute", interceptor.getReceiveSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN"))); .get(0);
assertTrue("ROLE_USER not found as receive attribute", interceptor.getReceiveSecurityAttributes().contains(new SecurityConfig("ROLE_USER"))); 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()); assertNull("Send security attribute were not null", interceptor.getSendSecurityAttributes());
} }
@Test @Test
public void testAdminRequiredForSendAndReceive(){ public void testAdminRequiredForSendAndReceive() {
applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel, "adminForSendAndReceive"); applicationContext.getAutowireCapableBeanFactory().applyBeanPostProcessorsAfterInitialization(messageChannel,
"adminForSendAndReceive");
assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size()); assertEquals("Wrong count of interceptors ", 1, messageChannel.interceptors.size());
SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor)messageChannel.interceptors.get(0); SecurityEnforcingChannelInterceptor interceptor = (SecurityEnforcingChannelInterceptor) messageChannel.interceptors
assertTrue("ROLE_ADMIN not found as receive attribute", interceptor.getReceiveSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN"))); .get(0);
assertTrue("ROLE_USER not found as send attribute", interceptor.getSendSecurityAttributes().contains(new SecurityConfig("ROLE_ADMIN"))); 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 { static class TestMessageChannel extends AbstractMessageChannel {
List<ChannelInterceptor> interceptors = new ArrayList<ChannelInterceptor>(); List<ChannelInterceptor> interceptors = new ArrayList<ChannelInterceptor>();
public TestMessageChannel() { public TestMessageChannel() {
super(null); super(null);
} }
@@ -134,7 +146,7 @@ public class SecuredChannelsParserTests extends AbstractJUnit4SpringContextTests
public void addInterceptor(ChannelInterceptor interceptor) { public void addInterceptor(ChannelInterceptor interceptor) {
interceptors.add(interceptor); interceptors.add(interceptor);
} }
} }
} }