The JavaDoc documentaion:
Add this annotation to an
@Configuration
class to have theSpring Security
configuration defined in anyWebSecurityConfigurer
or more likely by extending theWebSecurityConfigurerAdapter
base class and overriding individual methods.
The JavaDoc documentaion:
Add this annotation to an
@Configuration
class to have theSpring Security
configuration integrate withSpring MVC
.
CSRF Tokens
to Spring MVC
Forms, is this the only thing it adds?The @EnableWebSecurity is a marker annotation. It allows Spring to find (it's a @Configuration and, therefore, @Component ) and automatically apply the class to the global WebSecurity . If I don't annotate any of my class with @EnableWebSecurity still the application prompting for username and password.
WebSecurityConfigurerAdapter is a convenience class that allows customization to both WebSecurity and HttpSecurity. We can extend WebSecurityConfigurerAdapter multiple times (in distinct objects) to replicate the behavior of having multiple http elements.
AuthenticationEntryPoint is used in Spring Web Security to configure an application to perform certain actions whenever an unauthenticated client tries to access private resources.
EnableGlobalMethodSecurity provides AOP security on methods. Some of the annotations that it provides are PreAuthorize , PostAuthorize . It also has support for JSR-250. There are more parameters in the configuration for you.
As of Spring Security 4.0,
@EnableWebMvcSecurity
is deprecated. The replacement is@EnableWebSecurity
which will determine adding the Spring MVC features based upon the classpath.To enable Spring Security integration with Spring MVC add the
@EnableWebSecurity
annotation to your configuration.
source
If you take a look at those classes, @EnableWebMvcSecurity
actually adds the @EnableWebSecurity
annotation in WebMvcSecurityConfiguration
. Therefore, @EnableWebMvcSecurity
does everything that @EnableWebSecurity
does, and a bit more.
What more you ask?
If you look at WebMvcSecurityConfiguration
, you will see that it adds an AuthenticationPrincipalArgumentResolver
so that you can access the authentication principal by adding an annotation to a controller method argument. i.e.:
public String show(@AuthenticationPrincipal CustomUser customUser) { // do something with CustomUser return "view"; }
It also integrates with Spring Web MVC to add a CSRF token to forms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With