Skip to content

Commit 05725af

Browse files
Steve Riesenbergsjohnr
authored andcommitted
Remove references to WebSecurityConfigurerAdapter in EnableWebSecurity
Closes gh-11277
1 parent 4fbbfd2 commit 05725af

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

config/src/main/java/org/springframework/security/config/annotation/web/configuration/EnableWebSecurity.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,48 +26,56 @@
2626
import org.springframework.context.annotation.Import;
2727
import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication;
2828
import org.springframework.security.config.annotation.web.WebSecurityConfigurer;
29+
import org.springframework.security.web.SecurityFilterChain;
2930

3031
/**
3132
* Add this annotation to an {@code @Configuration} class to have the Spring Security
32-
* configuration defined in any {@link WebSecurityConfigurer} or more likely by extending
33-
* the {@link WebSecurityConfigurerAdapter} base class and overriding individual methods:
33+
* configuration defined in any {@link WebSecurityConfigurer} or more likely by exposing a
34+
* {@link SecurityFilterChain} bean:
3435
*
3536
* <pre class="code">
3637
* &#064;Configuration
3738
* &#064;EnableWebSecurity
38-
* public class MyWebSecurityConfiguration extends WebSecurityConfigurerAdapter {
39+
* public class MyWebSecurityConfiguration {
3940
*
40-
* &#064;Override
41-
* public void configure(WebSecurity web) throws Exception {
42-
* web.ignoring()
41+
* &#064;Bean
42+
* public WebSecurityCustomizer webSecurityCustomizer() {
43+
* return (web) -> web.ignoring()
4344
* // Spring Security should completely ignore URLs starting with /resources/
4445
* .antMatchers(&quot;/resources/**&quot;);
4546
* }
4647
*
47-
* &#064;Override
48-
* protected void configure(HttpSecurity http) throws Exception {
48+
* &#064;Bean
49+
* public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
4950
* http.authorizeRequests().antMatchers(&quot;/public/**&quot;).permitAll().anyRequest()
5051
* .hasRole(&quot;USER&quot;).and()
5152
* // Possibly more configuration ...
5253
* .formLogin() // enable form based log in
5354
* // set permitAll for all URLs associated with Form Login
5455
* .permitAll();
56+
* return http.build();
5557
* }
5658
*
57-
* &#064;Override
58-
* protected void configure(AuthenticationManagerBuilder auth) throws Exception {
59-
* auth
60-
* // enable in memory based authentication with a user named &quot;user&quot; and &quot;admin&quot;
61-
* .inMemoryAuthentication().withUser(&quot;user&quot;).password(&quot;password&quot;).roles(&quot;USER&quot;)
62-
* .and().withUser(&quot;admin&quot;).password(&quot;password&quot;).roles(&quot;USER&quot;, &quot;ADMIN&quot;);
59+
* &#064;Bean
60+
* public UserDetailsService userDetailsService() {
61+
* UserDetails user = User.withDefaultPasswordEncoder()
62+
* .username(&quot;user&quot;)
63+
* .password(&quot;password&quot;)
64+
* .roles(&quot;USER&quot;)
65+
* .build();
66+
* UserDetails admin = User.withDefaultPasswordEncoder()
67+
* .username(&quot;admin&quot;)
68+
* .password(&quot;password&quot;)
69+
* .roles(&quot;ADMIN&quot;, &quot;USER&quot;)
70+
* .build();
71+
* return new InMemoryUserDetailsManager(user, admin);
6372
* }
6473
*
65-
* // Possibly more overridden methods ...
74+
* // Possibly more bean methods ...
6675
* }
6776
* </pre>
6877
*
6978
* @see WebSecurityConfigurer
70-
* @see WebSecurityConfigurerAdapter
7179
*
7280
* @author Rob Winch
7381
* @since 3.2

0 commit comments

Comments
 (0)