Reputation: 4538
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?Upvotes: 49
Views: 31521
Reputation: 3738
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.
Upvotes: 56
Reputation: 9480
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.
Upvotes: 42