SEC-1257: APIs using List<ConfigAttribute> should use a Collection instead. Converted.
This commit is contained in:
@@ -17,6 +17,7 @@ package org.springframework.security.access.annotation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -59,12 +60,12 @@ public class MethodDefinitionSourceEditorTigerTests {
|
||||
MapBasedMethodSecurityMetadataSource map = (MapBasedMethodSecurityMetadataSource) editor.getValue();
|
||||
assertEquals(3, map.getMethodMapSize());
|
||||
|
||||
List<? extends ConfigAttribute> returnedMakeLower = map.getAttributes(makeLower);
|
||||
List<? extends ConfigAttribute> expectedMakeLower = SecurityConfig.createList("ROLE_FROM_INTERFACE");
|
||||
Collection<ConfigAttribute> returnedMakeLower = map.getAttributes(makeLower);
|
||||
List<ConfigAttribute> expectedMakeLower = SecurityConfig.createList("ROLE_FROM_INTERFACE");
|
||||
assertEquals(expectedMakeLower, returnedMakeLower);
|
||||
|
||||
List<? extends ConfigAttribute> returnedMakeUpper = map.getAttributes(makeUpper);
|
||||
List<? extends ConfigAttribute> expectedMakeUpper = SecurityConfig.createList(new String[]{"ROLE_FROM_IMPLEMENTATION"});
|
||||
Collection<ConfigAttribute> returnedMakeUpper = map.getAttributes(makeUpper);
|
||||
List<ConfigAttribute> expectedMakeUpper = SecurityConfig.createList(new String[]{"ROLE_FROM_IMPLEMENTATION"});
|
||||
assertEquals(expectedMakeUpper, returnedMakeUpper);
|
||||
}
|
||||
|
||||
@@ -79,8 +80,8 @@ public class MethodDefinitionSourceEditorTigerTests {
|
||||
MapBasedMethodSecurityMetadataSource map = (MapBasedMethodSecurityMetadataSource) editor.getValue();
|
||||
assertEquals(3, map.getMethodMapSize());
|
||||
|
||||
List<? extends ConfigAttribute> returnedMakeUpper = map.getAttributes(makeUpper);
|
||||
List<? extends ConfigAttribute> expectedMakeUpper = SecurityConfig.createList("ROLE_FROM_PSI");
|
||||
Collection<ConfigAttribute> returnedMakeUpper = map.getAttributes(makeUpper);
|
||||
List<ConfigAttribute> expectedMakeUpper = SecurityConfig.createList("ROLE_FROM_PSI");
|
||||
assertEquals(expectedMakeUpper, returnedMakeUpper);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,11 +43,11 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
|
||||
@Test
|
||||
public void classLevelPreAnnotationIsPickedUpWhenNoMethodLevelExists() throws Exception {
|
||||
List<ConfigAttribute> attrs = mds.getAttributes(voidImpl1);
|
||||
ConfigAttribute[] attrs = mds.getAttributes(voidImpl1).toArray(new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.size());
|
||||
assertTrue(attrs.get(0) instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs.get(0);
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
assertNotNull(pre.getAuthorizeExpression());
|
||||
assertEquals("someExpression", pre.getAuthorizeExpression().getExpressionString());
|
||||
assertNull(pre.getFilterExpression());
|
||||
@@ -55,11 +55,11 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
|
||||
@Test
|
||||
public void mixedClassAndMethodPreAnnotationsAreBothIncluded() {
|
||||
List<ConfigAttribute> attrs = mds.getAttributes(voidImpl2);
|
||||
ConfigAttribute[] attrs = mds.getAttributes(voidImpl2).toArray(new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.size());
|
||||
assertTrue(attrs.get(0) instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute)attrs.get(0);
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
assertEquals("someExpression", pre.getAuthorizeExpression().getExpressionString());
|
||||
assertNotNull(pre.getFilterExpression());
|
||||
assertEquals("somePreFilterExpression", pre.getFilterExpression().getExpressionString());
|
||||
@@ -67,11 +67,11 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
|
||||
@Test
|
||||
public void methodWithPreFilterOnlyIsAllowed() {
|
||||
List<ConfigAttribute> attrs = mds.getAttributes(voidImpl3);
|
||||
ConfigAttribute[] attrs = mds.getAttributes(voidImpl3).toArray(new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.size());
|
||||
assertTrue(attrs.get(0) instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute)attrs.get(0);
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
assertEquals("permitAll", pre.getAuthorizeExpression().getExpressionString());
|
||||
assertNotNull(pre.getFilterExpression());
|
||||
assertEquals("somePreFilterExpression", pre.getFilterExpression().getExpressionString());
|
||||
@@ -79,13 +79,13 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
|
||||
@Test
|
||||
public void methodWithPostFilterOnlyIsAllowed() {
|
||||
List<ConfigAttribute> attrs = mds.getAttributes(listImpl1);
|
||||
ConfigAttribute[] attrs = mds.getAttributes(listImpl1).toArray(new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(2, attrs.size());
|
||||
assertTrue(attrs.get(0) instanceof PreInvocationExpressionAttribute);
|
||||
assertTrue(attrs.get(1) instanceof PostInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute)attrs.get(0);
|
||||
PostInvocationExpressionAttribute post = (PostInvocationExpressionAttribute)attrs.get(1);
|
||||
assertEquals(2, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
assertTrue(attrs[1] instanceof PostInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0];
|
||||
PostInvocationExpressionAttribute post = (PostInvocationExpressionAttribute) attrs[1];
|
||||
assertEquals("permitAll", pre.getAuthorizeExpression().getExpressionString());
|
||||
assertNotNull(post.getFilterExpression());
|
||||
assertEquals("somePostFilterExpression", post.getFilterExpression().getExpressionString());
|
||||
@@ -93,11 +93,11 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
|
||||
@Test
|
||||
public void interfaceAttributesAreIncluded() {
|
||||
List<ConfigAttribute> attrs = mds.getAttributes(notherListImpl1);
|
||||
ConfigAttribute[] attrs = mds.getAttributes(notherListImpl1).toArray(new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.size());
|
||||
assertTrue(attrs.get(0) instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute)attrs.get(0);
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute)attrs[0];
|
||||
assertNotNull(pre.getFilterExpression());
|
||||
assertNotNull(pre.getAuthorizeExpression());
|
||||
assertEquals("interfaceMethodAuthzExpression", pre.getAuthorizeExpression().getExpressionString());
|
||||
@@ -106,11 +106,11 @@ public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
|
||||
@Test
|
||||
public void classAttributesTakesPrecedeceOverInterfaceAttributes() {
|
||||
List<ConfigAttribute> attrs = mds.getAttributes(notherListImpl2);
|
||||
ConfigAttribute[] attrs = mds.getAttributes(notherListImpl2).toArray(new ConfigAttribute[0]);
|
||||
|
||||
assertEquals(1, attrs.size());
|
||||
assertTrue(attrs.get(0) instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute)attrs.get(0);
|
||||
assertEquals(1, attrs.length);
|
||||
assertTrue(attrs[0] instanceof PreInvocationExpressionAttribute);
|
||||
PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute)attrs[0];
|
||||
assertNotNull(pre.getFilterExpression());
|
||||
assertNotNull(pre.getAuthorizeExpression());
|
||||
assertEquals("interfaceMethodAuthzExpression", pre.getAuthorizeExpression().getExpressionString());
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
package org.springframework.security.access.intercept;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -151,7 +152,7 @@ public class AfterInvocationProviderManagerTests extends TestCase {
|
||||
this.configAttribute = configAttribute;
|
||||
}
|
||||
|
||||
public Object decide(Authentication authentication, Object object, List<ConfigAttribute> config,
|
||||
public Object decide(Authentication authentication, Object object, Collection<ConfigAttribute> config,
|
||||
Object returnedObject) throws AccessDeniedException {
|
||||
if (config.contains(configAttribute)) {
|
||||
return forceReturnObject;
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.security.access.intercept.method;
|
||||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -56,9 +57,9 @@ public class MethodSecurityMetadataSourceEditorTests extends TestCase {
|
||||
Method method = clazz.getMethod("countLength", new Class[] {String.class});
|
||||
MockJoinPoint joinPoint = new MockJoinPoint(new TargetObject(), method);
|
||||
|
||||
List<? extends ConfigAttribute> returnedCountLength = map.getAttributes(joinPoint);
|
||||
Collection<ConfigAttribute> returnedCountLength = map.getAttributes(joinPoint);
|
||||
|
||||
List<? extends ConfigAttribute> expectedCountLength = SecurityConfig.createList("ROLE_ONE", "ROLE_TWO", "RUN_AS_ENTRY");
|
||||
List<ConfigAttribute> expectedCountLength = SecurityConfig.createList("ROLE_ONE", "ROLE_TWO", "RUN_AS_ENTRY");
|
||||
assertEquals(expectedCountLength, returnedCountLength);
|
||||
}
|
||||
|
||||
@@ -108,16 +109,16 @@ public class MethodSecurityMetadataSourceEditorTests extends TestCase {
|
||||
MapBasedMethodSecurityMetadataSource map = (MapBasedMethodSecurityMetadataSource) editor.getValue();
|
||||
assertEquals(6, map.getMethodMapSize());
|
||||
|
||||
List<? extends ConfigAttribute> returnedMakeLower = map.getAttributes(new MockMethodInvocation(ITargetObject.class, "makeLowerCase", new Class[] {String.class}, new OtherTargetObject()));
|
||||
List<? extends ConfigAttribute> expectedMakeLower = SecurityConfig.createList("ROLE_FROM_INTERFACE");
|
||||
Collection<ConfigAttribute> returnedMakeLower = map.getAttributes(new MockMethodInvocation(ITargetObject.class, "makeLowerCase", new Class[] {String.class}, new OtherTargetObject()));
|
||||
List<ConfigAttribute> expectedMakeLower = SecurityConfig.createList("ROLE_FROM_INTERFACE");
|
||||
assertEquals(expectedMakeLower, returnedMakeLower);
|
||||
|
||||
List<? extends ConfigAttribute> returnedMakeUpper = map.getAttributes(new MockMethodInvocation(ITargetObject.class, "makeUpperCase", new Class[] {String.class}, new OtherTargetObject()));
|
||||
List<? extends ConfigAttribute> expectedMakeUpper = SecurityConfig.createList("ROLE_FROM_IMPLEMENTATION");
|
||||
Collection<ConfigAttribute> returnedMakeUpper = map.getAttributes(new MockMethodInvocation(ITargetObject.class, "makeUpperCase", new Class[] {String.class}, new OtherTargetObject()));
|
||||
List<ConfigAttribute> expectedMakeUpper = SecurityConfig.createList("ROLE_FROM_IMPLEMENTATION");
|
||||
assertEquals(expectedMakeUpper, returnedMakeUpper);
|
||||
|
||||
List<? extends ConfigAttribute> returnedComputeHashCode = map.getAttributes(new MockMethodInvocation(ITargetObject.class, "computeHashCode", new Class[] {String.class}, new OtherTargetObject()));
|
||||
List<? extends ConfigAttribute> expectedComputeHashCode = SecurityConfig.createList("ROLE_FROM_OTO");
|
||||
Collection<ConfigAttribute> returnedComputeHashCode = map.getAttributes(new MockMethodInvocation(ITargetObject.class, "computeHashCode", new Class[] {String.class}, new OtherTargetObject()));
|
||||
List<ConfigAttribute> expectedComputeHashCode = SecurityConfig.createList("ROLE_FROM_OTO");
|
||||
assertEquals(expectedComputeHashCode, returnedComputeHashCode);
|
||||
|
||||
returnedComputeHashCode = map.getAttributes(new MockMethodInvocation(ITargetObject.class, "computeHashCode", new Class[] {String.class}, new TargetObject()));
|
||||
@@ -160,19 +161,19 @@ public class MethodSecurityMetadataSourceEditorTests extends TestCase {
|
||||
MapBasedMethodSecurityMetadataSource map = (MapBasedMethodSecurityMetadataSource) editor.getValue();
|
||||
assertEquals(14, map.getMethodMapSize());
|
||||
|
||||
List<? extends ConfigAttribute> returnedMakeLower = map.getAttributes(new MockMethodInvocation(ITargetObject.class,
|
||||
Collection<ConfigAttribute> returnedMakeLower = map.getAttributes(new MockMethodInvocation(ITargetObject.class,
|
||||
"makeLowerCase", new Class[] {String.class}, new TargetObject()));
|
||||
List<? extends ConfigAttribute> expectedMakeLower = SecurityConfig.createList("ROLE_LOWER");
|
||||
List<ConfigAttribute> expectedMakeLower = SecurityConfig.createList("ROLE_LOWER");
|
||||
assertEquals(expectedMakeLower, returnedMakeLower);
|
||||
|
||||
List<? extends ConfigAttribute> returnedMakeUpper = map.getAttributes(new MockMethodInvocation(ITargetObject.class,
|
||||
Collection<ConfigAttribute> returnedMakeUpper = map.getAttributes(new MockMethodInvocation(ITargetObject.class,
|
||||
"makeUpperCase", new Class[] {String.class}, new TargetObject()));
|
||||
List<? extends ConfigAttribute> expectedMakeUpper = SecurityConfig.createList("ROLE_UPPER");
|
||||
List<ConfigAttribute> expectedMakeUpper = SecurityConfig.createList("ROLE_UPPER");
|
||||
assertEquals(expectedMakeUpper, returnedMakeUpper);
|
||||
|
||||
List<? extends ConfigAttribute> returnedCountLength = map.getAttributes(new MockMethodInvocation(ITargetObject.class,
|
||||
Collection<ConfigAttribute> returnedCountLength = map.getAttributes(new MockMethodInvocation(ITargetObject.class,
|
||||
"countLength", new Class[] {String.class}, new TargetObject()));
|
||||
List<? extends ConfigAttribute> expectedCountLength = SecurityConfig.createList("ROLE_GENERAL");
|
||||
List<ConfigAttribute> expectedCountLength = SecurityConfig.createList("ROLE_GENERAL");
|
||||
assertEquals(expectedCountLength, returnedCountLength);
|
||||
}
|
||||
|
||||
@@ -182,7 +183,7 @@ public class MethodSecurityMetadataSourceEditorTests extends TestCase {
|
||||
|
||||
MapBasedMethodSecurityMetadataSource map = (MapBasedMethodSecurityMetadataSource) editor.getValue();
|
||||
|
||||
List<? extends ConfigAttribute> configAttributeDefinition = map.getAttributes(new MockMethodInvocation(
|
||||
Collection<ConfigAttribute> configAttributeDefinition = map.getAttributes(new MockMethodInvocation(
|
||||
ITargetObject.class, "makeLowerCase", new Class[] {String.class}, new TargetObject()));
|
||||
assertNull(configAttributeDefinition);
|
||||
}
|
||||
@@ -201,7 +202,7 @@ public class MethodSecurityMetadataSourceEditorTests extends TestCase {
|
||||
|
||||
MapBasedMethodSecurityMetadataSource map = (MapBasedMethodSecurityMetadataSource) editor.getValue();
|
||||
|
||||
List<? extends ConfigAttribute> returnedCountLength = map.getAttributes(new MockMethodInvocation(ITargetObject.class,
|
||||
Collection<ConfigAttribute> returnedCountLength = map.getAttributes(new MockMethodInvocation(ITargetObject.class,
|
||||
"countLength", new Class[] {String.class}, new TargetObject()));
|
||||
assertEquals(SecurityConfig.createList("ROLE_ONE", "ROLE_TWO", "RUN_AS_ENTRY"), returnedCountLength);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class MockMethodSecurityMetadataSource implements MethodSecurityMetadataS
|
||||
}
|
||||
}
|
||||
|
||||
public List<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
|
||||
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.springframework.security.access.vote.AbstractAccessDecisionManager;
|
||||
import org.springframework.security.access.vote.RoleVoter;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -148,7 +149,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockDecisionManagerImpl extends AbstractAccessDecisionManager {
|
||||
public void decide(Authentication authentication, Object object, List<ConfigAttribute> configAttributes)
|
||||
public void decide(Authentication authentication, Object object, Collection<ConfigAttribute> configAttributes)
|
||||
throws AccessDeniedException {
|
||||
return;
|
||||
}
|
||||
@@ -167,7 +168,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
public int vote(Authentication authentication, Object object, List<ConfigAttribute> attributes) {
|
||||
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
@@ -25,7 +25,7 @@ public class AbstractAclVoterTests {
|
||||
public boolean supports(ConfigAttribute attribute) {
|
||||
return false;
|
||||
}
|
||||
public int vote(Authentication authentication, Object object, List<ConfigAttribute> attributes) {
|
||||
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,8 +19,8 @@ import org.springframework.security.access.AccessDecisionVoter;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of an {@link AccessDecisionVoter} for unit testing.
|
||||
@@ -50,7 +50,7 @@ public class DenyAgainVoter implements AccessDecisionVoter {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int vote(Authentication authentication, Object object, List<ConfigAttribute> attributes) {
|
||||
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
|
||||
Iterator<ConfigAttribute> iter = attributes.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
||||
@@ -19,8 +19,8 @@ import org.springframework.security.access.AccessDecisionVoter;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
import org.springframework.security.core.Authentication;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ public class DenyVoter implements AccessDecisionVoter {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int vote(Authentication authentication, Object object, List<ConfigAttribute> attributes) {
|
||||
public int vote(Authentication authentication, Object object, Collection<ConfigAttribute> attributes) {
|
||||
Iterator<ConfigAttribute> iter = attributes.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
||||
Reference in New Issue
Block a user