Skip to content

Commit 32e34e5

Browse files
JAVA-14888 Update apache-shiro module under security-modules to remove usage of deprecated WebSecurityConfigurerAdapter (#13059)
1 parent e14ea66 commit 32e34e5

File tree

1 file changed

+24
-18
lines changed
  • security-modules/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/config

1 file changed

+24
-18
lines changed

security-modules/apache-shiro/src/main/java/com/baeldung/comparison/springsecurity/config/SecurityConfig.java

+24-18
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
11
package com.baeldung.comparison.springsecurity.config;
22

33
import org.springframework.context.annotation.Bean;
4-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
54
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
65
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
7-
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
6+
import org.springframework.security.core.userdetails.User;
7+
import org.springframework.security.core.userdetails.UserDetails;
88
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
99
import org.springframework.security.crypto.password.PasswordEncoder;
10+
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
11+
import org.springframework.security.web.SecurityFilterChain;
1012

1113
@EnableWebSecurity
12-
public class SecurityConfig extends WebSecurityConfigurerAdapter {
14+
public class SecurityConfig {
1315

14-
@Override
15-
protected void configure(HttpSecurity http) throws Exception {
16-
http.csrf().disable().authorizeRequests(authorize -> authorize.antMatchers("/index", "/login")
17-
.permitAll()
18-
.antMatchers("/home", "/logout")
19-
.authenticated()
20-
.antMatchers("/admin/**")
21-
.hasRole("ADMIN"))
16+
@Bean
17+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
18+
http.csrf()
19+
.disable()
20+
.authorizeRequests(authorize -> authorize.antMatchers("/index", "/login")
21+
.permitAll()
22+
.antMatchers("/home", "/logout")
23+
.authenticated()
24+
.antMatchers("/admin/**")
25+
.hasRole("ADMIN"))
2226
.formLogin(formLogin -> formLogin.loginPage("/login")
2327
.failureUrl("/login-error"));
28+
return http.build();
2429
}
2530

26-
@Override
27-
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
28-
auth.inMemoryAuthentication()
29-
.withUser("Jerry")
31+
@Bean
32+
public InMemoryUserDetailsManager userDetailsService() throws Exception {
33+
UserDetails jerry = User.withUsername("Jerry")
3034
.password(passwordEncoder().encode("password"))
3135
.authorities("READ", "WRITE")
3236
.roles("ADMIN")
33-
.and()
34-
.withUser("Tom")
37+
.build();
38+
UserDetails tom = User.withUsername("Tom")
3539
.password(passwordEncoder().encode("password"))
3640
.authorities("READ")
37-
.roles("USER");
41+
.roles("USER")
42+
.build();
43+
return new InMemoryUserDetailsManager(jerry, tom);
3844
}
3945

4046
@Bean

0 commit comments

Comments
 (0)