Class AnnotationParameterNameDiscoverer
- java.lang.Object
-
- org.springframework.security.core.parameters.AnnotationParameterNameDiscoverer
-
- All Implemented Interfaces:
org.springframework.core.ParameterNameDiscoverer
public class AnnotationParameterNameDiscoverer extends java.lang.Object implements org.springframework.core.ParameterNameDiscoverer
Allows finding parameter names using the value attribute of any number ofAnnotation
instances. This is useful when needing to discover the parameter names of interfaces with Spring Security's method level security. For example, consider the following:import org.springframework.security.access.method.P;
We can make this possible using the following@PostAuthorize("#to == returnObject.to")
public Message findMessageByTo(@P("to") String to);AnnotationParameterNameDiscoverer
:ParameterAnnotationsNameDiscoverer discoverer = new ParameterAnnotationsNameDiscoverer( "org.springframework.security.access.method.P");
It is common for users to use
AnnotationParameterNameDiscoverer
in conjunction withPrioritizedParameterNameDiscoverer
. In fact, Spring Security'sDefaultSecurityParameterNameDiscoverer
(which is used by default with method level security) extendsPrioritizedParameterNameDiscoverer
and will automatically support bothP
and Spring Data's Param annotation if it is found on the classpath.It is important to note that if a single parameter name has a supported annotation on it then all methods are resolved using
AnnotationParameterNameDiscoverer
. For example, consider the following:import org.springframework.security.access.method.P;
@PostAuthorize("#to == returnObject.to")
public Message findMessageByToAndFrom(@P("to") User to, User from);The result of finding parameters on the previous sample will be
new String[] { "to", null}
since only a single parameter contains an annotation. This is mostly due to the fact that the fallbacks forPrioritizedParameterNameDiscoverer
are an all or nothing operation.- Since:
- 3.2
- See Also:
DefaultSecurityParameterNameDiscoverer
-
-
Constructor Summary
Constructors Constructor Description AnnotationParameterNameDiscoverer(java.lang.String... annotationClassToUse)
AnnotationParameterNameDiscoverer(java.util.Set<java.lang.String> annotationClassesToUse)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]
getParameterNames(java.lang.reflect.Constructor<?> constructor)
java.lang.String[]
getParameterNames(java.lang.reflect.Method method)
-
-
-
Method Detail
-
getParameterNames
public java.lang.String[] getParameterNames(java.lang.reflect.Method method)
- Specified by:
getParameterNames
in interfaceorg.springframework.core.ParameterNameDiscoverer
-
getParameterNames
public java.lang.String[] getParameterNames(java.lang.reflect.Constructor<?> constructor)
- Specified by:
getParameterNames
in interfaceorg.springframework.core.ParameterNameDiscoverer
-
-