SEC-1257: Some additional API changes to use Collection instead of List...

This commit is contained in:
Luke Taylor
2009-10-07 21:08:20 +00:00
parent 9bece3bc9a
commit 4dcb9de67a
11 changed files with 48 additions and 46 deletions

View File

@@ -39,11 +39,11 @@ import org.springframework.security.access.method.AbstractFallbackMethodSecurity
*/
public class Jsr250MethodSecurityMetadataSource extends AbstractFallbackMethodSecurityMetadataSource {
protected List<ConfigAttribute> findAttributes(Class<?> clazz) {
protected Collection<ConfigAttribute> findAttributes(Class<?> clazz) {
return processAnnotations(clazz.getAnnotations());
}
protected List<ConfigAttribute> findAttributes(Method method, Class<?> targetClass) {
protected Collection<ConfigAttribute> findAttributes(Method method, Class<?> targetClass) {
return processAnnotations(AnnotationUtils.getAnnotations(method));
}

View File

@@ -35,11 +35,11 @@ import org.springframework.security.access.method.AbstractFallbackMethodSecurity
*/
public class SecuredAnnotationSecurityMetadataSource extends AbstractFallbackMethodSecurityMetadataSource {
protected List<ConfigAttribute> findAttributes(Class<?> clazz) {
protected Collection<ConfigAttribute> findAttributes(Class<?> clazz) {
return processAnnotation(clazz.getAnnotation(Secured.class));
}
protected List<ConfigAttribute> findAttributes(Method method, Class<?> targetClass) {
protected Collection<ConfigAttribute> findAttributes(Method method, Class<?> targetClass) {
return processAnnotation(AnnotationUtils.findAnnotation(method, Secured.class));
}

View File

@@ -1,7 +1,7 @@
package org.springframework.security.access.method;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Collection;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.util.ClassUtils;
@@ -27,12 +27,12 @@ import org.springframework.util.ClassUtils;
*/
public abstract class AbstractFallbackMethodSecurityMetadataSource extends AbstractMethodSecurityMetadataSource {
public List<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
public Collection<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
// The method may be on an interface, but we need attributes from the target class.
// If the target class is null, the method will be unchanged.
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
// First try is the method in the target class.
List<ConfigAttribute> attr = findAttributes(specificMethod, targetClass);
Collection<ConfigAttribute> attr = findAttributes(specificMethod, targetClass);
if (attr != null) {
return attr;
}
@@ -68,7 +68,7 @@ public abstract class AbstractFallbackMethodSecurityMetadataSource extends Abstr
* @param targetClass the target class for the invocation (may be <code>null</code>)
* @return the security metadata (or null if no metadata applies)
*/
protected abstract List<ConfigAttribute> findAttributes(Method method, Class<?> targetClass);
protected abstract Collection<ConfigAttribute> findAttributes(Method method, Class<?> targetClass);
/**
* Obtains the security metadata registered against the specified class.
@@ -82,7 +82,7 @@ public abstract class AbstractFallbackMethodSecurityMetadataSource extends Abstr
* @param clazz the target class for the invocation (never <code>null</code>)
* @return the security metadata (or null if no metadata applies)
*/
protected abstract List<ConfigAttribute> findAttributes(Class<?> clazz);
protected abstract Collection<ConfigAttribute> findAttributes(Class<?> clazz);
}

View File

@@ -26,8 +26,8 @@ public final class DelegatingMethodSecurityMetadataSource extends AbstractMethod
private final static List<ConfigAttribute> NULL_CONFIG_ATTRIBUTE = Collections.emptyList();
private List<MethodSecurityMetadataSource> methodSecurityMetadataSources;
private final Map<DefaultCacheKey, List<ConfigAttribute>> attributeCache =
new HashMap<DefaultCacheKey, List<ConfigAttribute>>();
private final Map<DefaultCacheKey, Collection<ConfigAttribute>> attributeCache =
new HashMap<DefaultCacheKey, Collection<ConfigAttribute>>();
//~ Methods ========================================================================================================
@@ -35,10 +35,10 @@ public final class DelegatingMethodSecurityMetadataSource extends AbstractMethod
Assert.notNull(methodSecurityMetadataSources, "A list of MethodSecurityMetadataSources is required");
}
public List<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
public Collection<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
DefaultCacheKey cacheKey = new DefaultCacheKey(method, targetClass);
synchronized (attributeCache) {
List<ConfigAttribute> cached = attributeCache.get(cacheKey);
Collection<ConfigAttribute> cached = attributeCache.get(cacheKey);
// Check for canonical value indicating there is no config attribute,
if (cached == NULL_CONFIG_ATTRIBUTE) {
return null;
@@ -49,7 +49,7 @@ public final class DelegatingMethodSecurityMetadataSource extends AbstractMethod
}
// No cached value, so query the sources to find a result
List<ConfigAttribute> attributes = null;
Collection<ConfigAttribute> attributes = null;
for (MethodSecurityMetadataSource s : methodSecurityMetadataSources) {
attributes = s.getAttributes(method, targetClass);
if (attributes != null) {

View File

@@ -72,14 +72,14 @@ public class MapBasedMethodSecurityMetadataSource extends AbstractFallbackMethod
/**
* Implementation does not support class-level attributes.
*/
protected List<ConfigAttribute> findAttributes(Class<?> clazz) {
protected Collection<ConfigAttribute> findAttributes(Class<?> clazz) {
return null;
}
/**
* Will walk the method inheritance tree to find the most specific declaration applicable.
*/
protected List<ConfigAttribute> findAttributes(Method method, Class<?> targetClass) {
protected Collection<ConfigAttribute> findAttributes(Method method, Class<?> targetClass) {
if (targetClass == null) {
return null;
}

View File

@@ -16,7 +16,7 @@
package org.springframework.security.access.method;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Collection;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityMetadataSource;
@@ -30,5 +30,5 @@ import org.springframework.security.access.SecurityMetadataSource;
* @version $Id$
*/
public interface MethodSecurityMetadataSource extends SecurityMetadataSource {
public List<ConfigAttribute> getAttributes(Method method, Class<?> targetClass);
public Collection<ConfigAttribute> getAttributes(Method method, Class<?> targetClass);
}

View File

@@ -4,7 +4,6 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.security.access.ConfigAttribute;
@@ -38,7 +37,7 @@ public class PrePostAnnotationSecurityMetadataSource extends AbstractMethodSecur
this.attributeFactory = attributeFactory;
}
public List<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
public Collection<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) {
if (method.getDeclaringClass() == Object.class) {
return null;
}