Skip to content

Commit 4f0848e

Browse files
committed
Updated to Spring Security 5.7.3 - resolved deprecated code
1 parent ce72304 commit 4f0848e

File tree

3 files changed

+48
-44
lines changed

3 files changed

+48
-44
lines changed

07-spring-security-5/solution-code-spring-security-demo-09-jdbc-bcrypt/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>com.luv2code</groupId>
6-
<artifactId>spring-security-demo</artifactId>
6+
<artifactId>spring-security-demo-09-jdbc-bcrypt</artifactId>
77
<version>1.0</version>
88
<packaging>war</packaging>
99

10-
<name>spring-security-demo</name>
10+
<name>spring-security-demo-09-jdbc-bcrypt</name>
1111

1212
<properties>
13-
<springframework.version>5.0.17.RELEASE</springframework.version>
14-
<springsecurity.version>5.0.0.RELEASE</springsecurity.version>
13+
<springframework.version>5.3.22</springframework.version>
14+
<springsecurity.version>5.7.3</springsecurity.version>
1515

1616
<maven.compiler.source>1.8</maven.compiler.source>
1717
<maven.compiler.target>1.8</maven.compiler.target>

07-spring-security-5/solution-code-spring-security-demo-09-jdbc-bcrypt/src/main/java/com/luv2code/springsecurity/demo/config/DemoSecurityConfig.java

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,58 @@
33
import javax.sql.DataSource;
44

55
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.context.annotation.Bean;
67
import org.springframework.context.annotation.Configuration;
7-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
88
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
99
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
10-
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10+
import org.springframework.security.provisioning.JdbcUserDetailsManager;
11+
import org.springframework.security.provisioning.UserDetailsManager;
12+
import org.springframework.security.web.SecurityFilterChain;
1113

1214
@Configuration
1315
@EnableWebSecurity
14-
public class DemoSecurityConfig extends WebSecurityConfigurerAdapter {
16+
public class DemoSecurityConfig {
1517

1618
// add a reference to our security data source
17-
18-
@Autowired
19+
1920
private DataSource securityDataSource;
2021

21-
22-
@Override
23-
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
24-
25-
// use jdbc authentication ... oh yeah!!!
26-
27-
auth.jdbcAuthentication().dataSource(securityDataSource);
28-
29-
}
30-
31-
@Override
32-
protected void configure(HttpSecurity http) throws Exception {
33-
34-
http.authorizeRequests()
35-
.antMatchers("/").hasRole("EMPLOYEE")
36-
.antMatchers("/leaders/**").hasRole("MANAGER")
37-
.antMatchers("/systems/**").hasRole("ADMIN")
38-
.and()
39-
.formLogin()
40-
.loginPage("/showMyLoginPage")
41-
.loginProcessingUrl("/authenticateTheUser")
42-
.permitAll()
43-
.and()
44-
.logout().permitAll()
45-
.and()
46-
.exceptionHandling().accessDeniedPage("/access-denied");
47-
22+
@Autowired
23+
public DemoSecurityConfig(DataSource theSecurityDataSource) {
24+
securityDataSource = theSecurityDataSource;
4825
}
26+
27+
@Bean
28+
public UserDetailsManager userDetailsService() {
29+
return new JdbcUserDetailsManager(securityDataSource);
30+
}
31+
32+
@Bean
33+
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
34+
35+
return http
36+
.authorizeRequests(configurer ->
37+
configurer
38+
.antMatchers("/").hasRole("EMPLOYEE")
39+
.antMatchers("/leaders/**").hasRole("MANAGER")
40+
.antMatchers("/systems/**").hasRole("ADMIN"))
41+
42+
.formLogin(configurer ->
43+
configurer
44+
.loginPage("/showMyLoginPage")
45+
.loginProcessingUrl("/authenticateTheUser")
46+
.permitAll())
47+
48+
.logout(configurer ->
49+
configurer
50+
.permitAll())
51+
52+
.exceptionHandling(configurer ->
53+
configurer
54+
.accessDeniedPage("/access-denied"))
55+
56+
.build();
57+
58+
}
4959

50-
}
51-
52-
53-
54-
55-
56-
60+
}

07-spring-security-5/solution-code-spring-security-demo-09-jdbc-bcrypt/src/main/resources/persistence-mysql.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# JDBC connection properties
33
#
4-
jdbc.driver=com.mysql.jdbc.Driver
4+
jdbc.driver=com.mysql.cj.jdbc.Driver
55
jdbc.url=jdbc:mysql://localhost:3306/spring_security_demo_bcrypt?useSSL=false&serverTimezone=UTC
66
jdbc.user=springstudent
77
jdbc.password=springstudent

0 commit comments

Comments
 (0)