Skip to content

Remove EnableWebMvcSecurity #17311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,6 @@
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;

/**
* The {@link EnableGlobalAuthentication} annotation signals that the annotated class can
Expand Down Expand Up @@ -87,14 +86,12 @@
*
* <ul>
* <li>{@link EnableWebSecurity}</li>
* <li>{@link EnableWebMvcSecurity}</li>
* <li>{@link EnableGlobalMethodSecurity}</li>
* </ul>
*
* Configuring {@link AuthenticationManagerBuilder} in a class without the
* {@link EnableGlobalAuthentication} annotation has unpredictable results.
*
* @see EnableWebMvcSecurity
* @see EnableWebSecurity
* @see EnableGlobalMethodSecurity
* @author Rob Winch
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,6 @@
import org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
import org.springframework.security.config.test.SpringTestContext;
import org.springframework.security.config.test.SpringTestContextExtension;
import org.springframework.security.config.users.AuthenticationTestConfiguration;
Expand Down Expand Up @@ -110,17 +109,6 @@ public void orderingAutowiredOnEnableWebSecurity() {
this.service.run();
}

@Test
public void orderingAutowiredOnEnableWebMvcSecurity() {
this.spring
.register(AuthenticationTestConfiguration.class, WebMvcSecurityConfig.class,
GlobalMethodSecurityAutowiredConfig.class, ServicesConfig.class)
.autowire();
SecurityContextHolder.getContext()
.setAuthentication(new TestingAuthenticationToken("user", "password", "ROLE_USER"));
this.service.run();
}

@Test
public void getAuthenticationManagerWhenNoAuthenticationThenNull() throws Exception {
this.spring.register(AuthenticationConfiguration.class, ObjectPostProcessorConfiguration.class).autowire();
Expand Down Expand Up @@ -358,12 +346,6 @@ static class WebSecurityConfig {

}

@Configuration
@EnableWebMvcSecurity
static class WebMvcSecurityConfig {

}

@Configuration
static class NoOpGlobalAuthenticationConfigurerAdapter extends GlobalAuthenticationConfigurerAdapter {

Expand Down
10 changes: 2 additions & 8 deletions docs/modules/ROOT/pages/servlet/integrations/mvc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
Spring Security provides a number of optional integrations with Spring MVC.
This section covers the integration in further detail.

[[mvc-enablewebmvcsecurity]]
== @EnableWebMvcSecurity

[NOTE]
====
As of Spring Security 4.0, `@EnableWebMvcSecurity` is deprecated.
The replacement is `@EnableWebSecurity`, which adds the Spring MVC features, based upon the classpath.
====
[[mvc-enablewebsecurity]]
== @EnableWebSecurity

To enable Spring Security integration with Spring MVC, add the `@EnableWebSecurity` annotation to your configuration.

Expand Down