Skip to content

Commit 8d007ea

Browse files
committed
encode in-memory auth password
1 parent e374516 commit 8d007ea

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/main/java/de/rwth/idsg/steve/SteveConfiguration.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import de.rwth.idsg.steve.utils.PropertiesFileLoader;
66
import lombok.Builder;
77
import lombok.Getter;
8+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
9+
import org.springframework.security.crypto.password.PasswordEncoder;
810

911
/**
1012
* @author Sevket Goekay <goekay@dbis.rwth-aachen.de>
@@ -66,9 +68,12 @@ public enum SteveConfiguration {
6668
.sqlLogging(p.getBoolean("db.sql.logging"))
6769
.build();
6870

71+
PasswordEncoder encoder = new BCryptPasswordEncoder();
72+
6973
auth = Auth.builder()
74+
.passwordEncoder(encoder)
7075
.userName(p.getString("auth.user"))
71-
.password(p.getString("auth.password"))
76+
.encodedPassword(encoder.encode(p.getString("auth.password")))
7277
.build();
7378

7479
ocpp = Ocpp.builder()
@@ -154,8 +159,9 @@ public static class DB {
154159
// Credentials for Web interface access
155160
@Builder @Getter
156161
public static class Auth {
162+
private final PasswordEncoder passwordEncoder;
157163
private final String userName;
158-
private final String password;
164+
private final String encodedPassword;
159165
}
160166

161167
// OCPP-related configuration

src/main/java/de/rwth/idsg/steve/config/SecurityConfiguration.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,16 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
2727
/**
2828
* Password encoding changed with spring-security 5.0.0. We either have to use a prefix before the password to
2929
* indicate which actual encoder {@link DelegatingPasswordEncoder} should use [1, 2] or specify the encoder as we do.
30-
* {@link NoOpPasswordEncoder} is deprecated because it is not secure since it is not a one way hash function and
31-
* uses plain text matching, but is good enough for our simple user management and login authorization case.
3230
*
3331
* [1] https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-format
3432
* [2] {@link PasswordEncoderFactories#createDelegatingPasswordEncoder()}
3533
*/
3634
@Autowired
3735
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
3836
auth.inMemoryAuthentication()
39-
.passwordEncoder(NoOpPasswordEncoder.getInstance())
37+
.passwordEncoder(CONFIG.getAuth().getPasswordEncoder())
4038
.withUser(CONFIG.getAuth().getUserName())
41-
.password(CONFIG.getAuth().getPassword())
39+
.password(CONFIG.getAuth().getEncodedPassword())
4240
.roles("ADMIN");
4341
}
4442

0 commit comments

Comments
 (0)