SEC-1012: Futher generification. Also changed method signature of ObjectDefinitionSource.getAllConfigAtributes to return a single collection
This commit is contained in:
@@ -54,7 +54,7 @@ public class MockRunAsManager implements RunAsManager {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.springframework.security.GrantedAuthorityImpl;
|
||||
*
|
||||
* @author Ruud Senden
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MapBasedAttributes2GrantedAuthoritiesMapperTest {
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package org.springframework.security.intercept.method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -18,8 +17,8 @@ import org.springframework.security.SecurityConfig;
|
||||
* @since 2.0.4
|
||||
*/
|
||||
public class MapBasedMethodDefinitionSourceTests {
|
||||
private final List<? extends ConfigAttribute> ROLE_A = Arrays.asList(new SecurityConfig("ROLE_A"));
|
||||
private final List<? extends ConfigAttribute> ROLE_B = Arrays.asList(new SecurityConfig("ROLE_B"));
|
||||
private final List<ConfigAttribute> ROLE_A = SecurityConfig.createList("ROLE_A");
|
||||
private final List<ConfigAttribute> ROLE_B = SecurityConfig.createList("ROLE_B");
|
||||
private MapBasedMethodDefinitionSource mds;
|
||||
private Method someMethodString;
|
||||
private Method someMethodInteger;
|
||||
|
||||
@@ -147,14 +147,8 @@ public class MethodDefinitionSourceEditorTests extends TestCase {
|
||||
|
||||
MapBasedMethodDefinitionSource map = (MapBasedMethodDefinitionSource) editor.getValue();
|
||||
Iterator iter = map.getAllConfigAttributes().iterator();
|
||||
int counter = 0;
|
||||
|
||||
while (iter.hasNext()) {
|
||||
iter.next();
|
||||
counter++;
|
||||
}
|
||||
|
||||
assertEquals(3, counter);
|
||||
assertEquals(5, map.getAllConfigAttributes().size());
|
||||
}
|
||||
|
||||
public void testMultiMethodParsing() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.security.intercept.method;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
@@ -34,35 +35,29 @@ import org.springframework.security.SecurityConfig;
|
||||
public class MockMethodDefinitionSource implements MethodDefinitionSource {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private List list;
|
||||
private List<ConfigAttribute> list;
|
||||
private boolean returnACollection;
|
||||
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public MockMethodDefinitionSource(boolean includeInvalidAttributes, boolean returnACollectionWhenRequested) {
|
||||
returnACollection = returnACollectionWhenRequested;
|
||||
list = new Vector();
|
||||
|
||||
List<? extends ConfigAttribute> def1 = SecurityConfig.createList("MOCK_LOWER");
|
||||
list.add(def1);
|
||||
list = new ArrayList<ConfigAttribute>();
|
||||
|
||||
if (includeInvalidAttributes) {
|
||||
List<? extends ConfigAttribute> def2 = SecurityConfig.createList("MOCK_LOWER","INVALID_ATTRIBUTE");
|
||||
list.add(def2);
|
||||
list.addAll(SecurityConfig.createList("MOCK_LOWER","INVALID_ATTRIBUTE"));
|
||||
}
|
||||
|
||||
List<? extends ConfigAttribute> def3 = SecurityConfig.createList("MOCK_UPPER", "RUN_AS_");
|
||||
list.add(def3);
|
||||
list.addAll(SecurityConfig.createList("MOCK_LOWER", "MOCK_UPPER", "RUN_AS_"));
|
||||
|
||||
if (includeInvalidAttributes) {
|
||||
List<? extends ConfigAttribute> def4 = SecurityConfig.createList("MOCK_SOMETHING", "ANOTHER_INVALID");
|
||||
list.add(def4);
|
||||
list.addAll(SecurityConfig.createList("MOCK_SOMETHING", "ANOTHER_INVALID"));
|
||||
}
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public Collection<List<? extends ConfigAttribute>> getAllConfigAttributes() {
|
||||
public Collection<ConfigAttribute> getAllConfigAttributes() {
|
||||
if (returnACollection) {
|
||||
return list;
|
||||
} else {
|
||||
@@ -74,11 +69,11 @@ public class MockMethodDefinitionSource implements MethodDefinitionSource {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
public List<ConfigAttribute> getAttributes(Method method, Class targetClass) {
|
||||
public List<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return (MethodInvocation.class.isAssignableFrom(clazz) || JoinPoint.class.isAssignableFrom(clazz));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.lang.reflect.Method;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MockMethodInvocation implements MethodInvocation {
|
||||
private Method method;
|
||||
private Object targetObject;
|
||||
|
||||
@@ -440,15 +440,15 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockObjectDefinitionSourceWhichOnlySupportsStrings implements MethodDefinitionSource {
|
||||
public Collection<List<? extends ConfigAttribute>> getAllConfigAttributes() {
|
||||
public Collection<ConfigAttribute> getAllConfigAttributes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ConfigAttribute> getAttributes(Method method, Class targetClass) {
|
||||
public List<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
if (String.class.isAssignableFrom(clazz)) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -466,7 +466,7 @@ public class MethodSecurityInterceptorTests extends TestCase {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
if (String.class.isAssignableFrom(clazz)) {
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -108,7 +108,7 @@ public class LdapAuthenticationProviderTests extends TestCase {
|
||||
assertEquals("ben", user.getUsername());
|
||||
assertEquals("ben", populator.getRequestedUsername());
|
||||
|
||||
ArrayList authorities = new ArrayList();
|
||||
ArrayList<String> authorities = new ArrayList<String>();
|
||||
authorities.add(user.getAuthorities().get(0).getAuthority());
|
||||
authorities.add(user.getAuthorities().get(1).getAuthority());
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class RunAsUserTokenTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testNoArgConstructorDoesntExist() {
|
||||
Class clazz = RunAsUserToken.class;
|
||||
Class<RunAsUserToken> clazz = RunAsUserToken.class;
|
||||
|
||||
try {
|
||||
clazz.getDeclaredConstructor((Class[]) null);
|
||||
|
||||
@@ -15,28 +15,24 @@
|
||||
|
||||
package org.springframework.security.securechannel;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
import org.springframework.security.intercept.web.FilterInvocationDefinitionSource;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.SecurityConfig;
|
||||
import org.springframework.security.intercept.web.FilterInvocation;
|
||||
import org.springframework.security.intercept.web.FilterInvocationDefinitionSource;
|
||||
|
||||
|
||||
/**
|
||||
* Tests {@link ChannelProcessingFilter}.
|
||||
@@ -266,18 +262,15 @@ public class ChannelProcessingFilterTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<List<? extends ConfigAttribute>> getAllConfigAttributes() {
|
||||
public Collection<ConfigAttribute> getAllConfigAttributes() {
|
||||
if (!provideIterator) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List list = new Vector();
|
||||
list.add(toReturn);
|
||||
|
||||
return list;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Testcases for {@link ThrowableAnalyzer}.
|
||||
* Test cases for {@link ThrowableAnalyzer}.
|
||||
*
|
||||
* @author Andreas Senft
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ThrowableAnalyzerTests extends TestCase {
|
||||
|
||||
/**
|
||||
@@ -101,27 +102,6 @@ public class ThrowableAnalyzerTests extends TestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
public void testRegisterExtractorWithInvalidClass() {
|
||||
try {
|
||||
new ThrowableAnalyzer() {
|
||||
|
||||
/**
|
||||
* @see org.springframework.security.util.ThrowableAnalyzer#initExtractorMap()
|
||||
*/
|
||||
@Override
|
||||
protected void initExtractorMap() {
|
||||
// Object is no subclass of Throwable
|
||||
super.registerExtractor(Object.class, DEFAULT_EXTRACTOR);
|
||||
}
|
||||
};
|
||||
|
||||
fail("IllegalArgumentExpected");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
public void testRegisterExtractorWithInvalidExtractor() {
|
||||
try {
|
||||
new ThrowableAnalyzer() {
|
||||
|
||||
@@ -152,7 +152,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockStringOnlyVoter implements AccessDecisionVoter {
|
||||
public boolean supports(Class<? extends Object> clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
if (String.class.isAssignableFrom(clazz)) {
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DenyAgainVoter implements AccessDecisionVoter {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supports(Class<? extends Object> clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DenyVoter implements AccessDecisionVoter {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supports(Class<? extends Object> clazz) {
|
||||
public boolean supports(Class<?> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user