diff --git a/core-tiger/src/main/java/org/springframework/security/annotation/SecurityAnnotationAttributes.java b/core-tiger/src/main/java/org/springframework/security/annotation/SecurityAnnotationAttributes.java index 41f56c3fe0..0d3ac04c07 100644 --- a/core-tiger/src/main/java/org/springframework/security/annotation/SecurityAnnotationAttributes.java +++ b/core-tiger/src/main/java/org/springframework/security/annotation/SecurityAnnotationAttributes.java @@ -18,7 +18,7 @@ import org.springframework.security.SecurityConfig; import org.springframework.metadata.Attributes; -import org.springframework.util.ClassUtils; +import org.springframework.core.annotation.AnnotationUtils; import java.lang.annotation.Annotation; import java.lang.reflect.Field; @@ -32,20 +32,27 @@ import java.util.Set; /** * Java 5 Annotation Attributes metadata implementation used for secure method interception.

This * Attributes implementation will return security configuration for classes described using the - * Secured Java 5 annotation.

- *

The SecurityAnnotationAttributes implementation can be used to configure a - * MethodDefinitionAttributes and MethodSecurityInterceptor bean definition (see below).

- *

For example:

<bean id="attributes"
- *     class="org.springframework.security.annotation.SecurityAnnotationAttributes"/><bean id="objectDefinitionSource"
- *     class="org.springframework.security.intercept.method.MethodDefinitionAttributes">    <property name="attributes">
- *         <ref local="attributes"/>    </property></bean><bean id="securityInterceptor"
- *     class="org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor">     . . .
- *      <property name="objectDefinitionSource">         <ref local="objectDefinitionSource"/>     </property>
- * </bean>

- *

These security annotations are similiar to the Commons Attributes approach, however they are using Java 5 - * language-level metadata support.

- *

This class should be used with Spring 2.0 or above, as it relies upon utility classes in Spring 2.0 for - * correct introspection of annotations on bridge methods.

+ * Secured Java 5 annotation. + *

+ * The SecurityAnnotationAttributes implementation can be used to configure a + * MethodDefinitionAttributes and MethodSecurityInterceptor bean definition (see below). + *

+ * For example: + *

+ * <bean id="attributes" class="org.springframework.security.annotation.SecurityAnnotationAttributes"/>
+ * <bean id="objectDefinitionSource"
+ *     class="org.springframework.security.intercept.method.MethodDefinitionAttributes">
+ *         <property name="attributes"><ref local="attributes"/></property>
+ * </bean>
+ * <bean id="securityInterceptor"
+ *     class="org.springframework.security.intercept.method.aopalliance.MethodSecurityInterceptor">
+ *      . . .
+ *      <property name="objectDefinitionSource"><ref local="objectDefinitionSource"/></property>
+ * </bean>
+ * 
+ *

+ * These security annotations are similiar to the Commons Attributes approach, however they are using Java 5 + * language-level metadata support. * * @author Mark St.Godard * @version $Id$ @@ -83,10 +90,6 @@ public class SecurityAnnotationAttributes implements Attributes { return attributes; } - public Collection getAttributes(Class clazz, Class filter) { - throw new UnsupportedOperationException("Unsupported operation"); - } - /** * Get the Secured attributes for a given target method. * @@ -98,18 +101,7 @@ public class SecurityAnnotationAttributes implements Attributes { */ public Collection getAttributes(Method method) { Set attributes = new HashSet(); - - Annotation[] annotations = null; - - // Use AnnotationUtils if in classpath (ie Spring 1.2.9+ deployment) - try { - Class clazz = ClassUtils.forName("org.springframework.core.annotation.AnnotationUtils"); - Method m = clazz.getMethod("getAnnotations", new Class[] {Method.class}); - annotations = (Annotation[]) m.invoke(null, new Object[] {method}); - } catch (Exception ex) { - // Fallback to manual retrieval if no AnnotationUtils available - annotations = method.getAnnotations(); - } + Annotation[] annotations = AnnotationUtils.getAnnotations(method); for (Annotation annotation : annotations) { // check for Secured annotations @@ -127,15 +119,19 @@ public class SecurityAnnotationAttributes implements Attributes { return attributes; } + public Collection getAttributes(Class clazz, Class filter) { + throw new UnsupportedOperationException(); + } + public Collection getAttributes(Method method, Class clazz) { - throw new UnsupportedOperationException("Unsupported operation"); + throw new UnsupportedOperationException(); } public Collection getAttributes(Field field) { - throw new UnsupportedOperationException("Unsupported operation"); + throw new UnsupportedOperationException(); } public Collection getAttributes(Field field, Class clazz) { - throw new UnsupportedOperationException("Unsupported operation"); + throw new UnsupportedOperationException(); } }