Skip to content

Commit 30eeb09

Browse files
Merge pull request eugenp#3916 from steinhauer-software/BAEL-1489
BAEL-1489: Password storage in Spring Security 5
2 parents 8db0635 + 75a6a41 commit 30eeb09

2 files changed

Lines changed: 92 additions & 90 deletions

File tree

‎spring-5-security/pom.xml‎

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung</groupId>
5-
<artifactId>spring-5-security</artifactId>
6-
<version>0.0.1-SNAPSHOT</version>
7-
<packaging>jar</packaging>
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>spring-5-security</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>jar</packaging>
88

9-
<name>spring-5-security</name>
10-
<description>spring 5 security sample project</description>
9+
<name>spring-5-security</name>
10+
<description>spring 5 security sample project</description>
1111

12-
<parent>
13-
<groupId>org.springframework.boot</groupId>
14-
<artifactId>spring-boot-starter-parent</artifactId>
15-
<version>2.0.0.RC2</version>
16-
<relativePath /> <!-- lookup parent from repository -->
17-
</parent>
12+
<parent>
13+
<groupId>org.springframework.boot</groupId>
14+
<artifactId>spring-boot-starter-parent</artifactId>
15+
<version>2.0.0.RELEASE</version>
16+
<relativePath/> <!-- lookup parent from repository -->
17+
</parent>
1818

19-
<dependencies>
19+
<dependencies>
2020

2121
<dependency>
2222
<groupId>org.springframework.boot</groupId>
@@ -35,80 +35,80 @@
3535
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
3636
</dependency>
3737

38-
<!-- oauth2 -->
39-
<dependency>
40-
<groupId>org.springframework.security</groupId>
41-
<artifactId>spring-security-oauth2-client</artifactId>
42-
</dependency>
43-
<dependency>
44-
<groupId>org.springframework.security</groupId>
45-
<artifactId>spring-security-oauth2-jose</artifactId>
46-
</dependency>
38+
<!-- oauth2 -->
39+
<dependency>
40+
<groupId>org.springframework.security</groupId>
41+
<artifactId>spring-security-oauth2-client</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.security</groupId>
45+
<artifactId>spring-security-oauth2-jose</artifactId>
46+
</dependency>
4747

48-
<dependency>
49-
<groupId>org.springframework</groupId>
50-
<artifactId>spring-test</artifactId>
51-
</dependency>
52-
<dependency>
53-
<groupId>org.springframework.boot</groupId>
54-
<artifactId>spring-boot-starter-test</artifactId>
55-
<scope>test</scope>
56-
</dependency>
57-
<dependency>
58-
<groupId>org.springframework.security</groupId>
59-
<artifactId>spring-security-test</artifactId>
60-
<scope>test</scope>
61-
</dependency>
62-
</dependencies>
48+
<dependency>
49+
<groupId>org.springframework</groupId>
50+
<artifactId>spring-test</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-test</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.springframework.security</groupId>
59+
<artifactId>spring-security-test</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-maven-plugin</artifactId>
69+
</plugin>
6370

64-
<build>
65-
<plugins>
66-
<plugin>
67-
<groupId>org.springframework.boot</groupId>
68-
<artifactId>spring-boot-maven-plugin</artifactId>
69-
</plugin>
71+
<plugin>
72+
<groupId>org.apache.maven.plugins</groupId>
73+
<artifactId>maven-surefire-plugin</artifactId>
74+
<configuration>
75+
<forkCount>3</forkCount>
76+
<reuseForks>true</reuseForks>
77+
<parallel>methods</parallel>
78+
<useUnlimitedThreads>true</useUnlimitedThreads>
79+
<excludes>
80+
<exclude>**/*IntegrationTest.java</exclude>
81+
<exclude>**/*LiveTest.java</exclude>
82+
</excludes>
83+
</configuration>
84+
</plugin>
85+
</plugins>
86+
</build>
7087

71-
<plugin>
72-
<groupId>org.apache.maven.plugins</groupId>
73-
<artifactId>maven-surefire-plugin</artifactId>
74-
<configuration>
75-
<forkCount>3</forkCount>
76-
<reuseForks>true</reuseForks>
77-
<parallel>methods</parallel>
78-
<useUnlimitedThreads>true</useUnlimitedThreads>
79-
<excludes>
80-
<exclude>**/*IntegrationTest.java</exclude>
81-
<exclude>**/*LiveTest.java</exclude>
82-
</excludes>
83-
</configuration>
84-
</plugin>
85-
</plugins>
86-
</build>
87-
88-
<repositories>
89-
<repository>
90-
<id>spring-milestones</id>
91-
<name>Spring Milestones</name>
92-
<url>https://repo.spring.io/milestone</url>
93-
<snapshots>
94-
<enabled>false</enabled>
95-
</snapshots>
96-
</repository>
97-
</repositories>
98-
<pluginRepositories>
99-
<pluginRepository>
100-
<id>spring-milestones</id>
101-
<name>Spring Milestones</name>
102-
<url>https://repo.spring.io/milestone</url>
103-
<snapshots>
104-
<enabled>false</enabled>
105-
</snapshots>
106-
</pluginRepository>
107-
</pluginRepositories>
88+
<repositories>
89+
<repository>
90+
<id>spring-milestones</id>
91+
<name>Spring Milestones</name>
92+
<url>https://repo.spring.io/milestone</url>
93+
<snapshots>
94+
<enabled>false</enabled>
95+
</snapshots>
96+
</repository>
97+
</repositories>
98+
<pluginRepositories>
99+
<pluginRepository>
100+
<id>spring-milestones</id>
101+
<name>Spring Milestones</name>
102+
<url>https://repo.spring.io/milestone</url>
103+
<snapshots>
104+
<enabled>false</enabled>
105+
</snapshots>
106+
</pluginRepository>
107+
</pluginRepositories>
108108

109-
<properties>
110-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
111-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
112-
<java.version>1.8</java.version>
113-
</properties>
109+
<properties>
110+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
111+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
112+
<java.version>1.8</java.version>
113+
</properties>
114114
</project>

‎spring-5-security/src/main/java/com/baeldung/passwordstorage/PasswordStorageWebSecurityConfigurer.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
@Configuration
2222
public class PasswordStorageWebSecurityConfigurer extends WebSecurityConfigurerAdapter {
2323

24-
2524
@Override
2625
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
2726
auth.eraseCredentials(false) // 4
@@ -31,8 +30,11 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {
3130

3231
@Bean
3332
public UserDetailsService getUserDefaultDetailsService() {
34-
User testUser = new User("baeldung", "{noop}SpringSecurity5", Collections.emptyList());
35-
return new InMemoryUserDetailsManager(testUser);
33+
return new InMemoryUserDetailsManager(User
34+
.withUsername("baeldung")
35+
.password("{noop}SpringSecurity5")
36+
.authorities(Collections.emptyList())
37+
.build());
3638
}
3739

3840
@Bean

0 commit comments

Comments
 (0)