#
Annotations in Java Spring Security
This tutorial explains some annotations used in Java Spring Security.
Info
Java annotations are metadata (data about data) provided to the compiler and JVM. An annotation could be on classes, interfaces, variables, methods, or fields level. Annotations do not impact the execution of the code.
Here are some well known annotations used in Java Spring Security:
#
@EnableWebSecurity
@EnableWebSecurity
- Enables web security
#
@EnableGlobalMethodSecurity
@EnableGlobalMethodSecurity
- Enables method security (further we can use @PreAuthorize, @PostAuthorize,
@PreFilter, @PostFilter annotation).
#
@PreAuthorize
@PreAuthorize
- Defines access-control expression using SpEL, which is evaluated before invoking a protected method.
Defines who can access a method.
#
@PostAuthorize
@PostAuthorize
- Defines access-control expression using SpEL, which is evaluated after invoking a protected method.
Defines who can receive information from a method.
#
@PreFilter
@PreFilter
- Filter the call parameters (collection or arrays) of the method.
#
@PostFilter
@PostFilter
- Filter the result of the call (collection or arrays).
#
@RolesAllowed
@RolesAllowed
- Specifies a list of security roles allowed to invoke protected method
#
@Secured
@Secured
- Do the same thing as @RolesAllowed, but it is Spring specific.