make classes package private, apply google-java-formatter
This commit is contained in:
@@ -16,8 +16,7 @@ import java.util.Set;
|
|||||||
@Table(name = "users")
|
@Table(name = "users")
|
||||||
public class UserCredentials {
|
public class UserCredentials {
|
||||||
|
|
||||||
@Id
|
@Id private String username;
|
||||||
private String username;
|
|
||||||
|
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class UserDetailsMapper {
|
class UserDetailsMapper {
|
||||||
|
|
||||||
UserDetails toUserDetails(UserCredentials userCredentials) {
|
UserDetails toUserDetails(UserCredentials userCredentials) {
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
|
||||||
auth.authenticationProvider(daoAuthenticationProvider())
|
auth.authenticationProvider(daoAuthenticationProvider()).eraseCredentials(false);
|
||||||
.eraseCredentials(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -66,22 +65,30 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
// we must user deprecated encoder to support their encoding
|
// we must user deprecated encoder to support their encoding
|
||||||
String encodingId = "bcrypt";
|
String encodingId = "bcrypt";
|
||||||
Map<String, PasswordEncoder> encoders = new HashMap<>();
|
Map<String, PasswordEncoder> encoders = new HashMap<>();
|
||||||
encoders.put(encodingId, new BCryptPasswordEncoder(bcCryptWorkFactorService.calculateStrength()));
|
encoders.put(
|
||||||
|
encodingId, new BCryptPasswordEncoder(bcCryptWorkFactorService.calculateStrength()));
|
||||||
encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder());
|
encoders.put("ldap", new org.springframework.security.crypto.password.LdapShaPasswordEncoder());
|
||||||
encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
|
encoders.put("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
|
||||||
encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
|
encoders.put(
|
||||||
encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
|
"MD5",
|
||||||
|
new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
|
||||||
|
encoders.put(
|
||||||
|
"noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
|
||||||
encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
|
encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
|
||||||
encoders.put("scrypt", new SCryptPasswordEncoder());
|
encoders.put("scrypt", new SCryptPasswordEncoder());
|
||||||
encoders.put("SHA-1", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"));
|
encoders.put(
|
||||||
encoders.put("SHA-256", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
|
"SHA-1",
|
||||||
encoders.put("sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder());
|
new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-1"));
|
||||||
|
encoders.put(
|
||||||
|
"SHA-256",
|
||||||
|
new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("SHA-256"));
|
||||||
|
encoders.put(
|
||||||
|
"sha256", new org.springframework.security.crypto.password.StandardPasswordEncoder());
|
||||||
encoders.put("argon2", new Argon2PasswordEncoder());
|
encoders.put("argon2", new Argon2PasswordEncoder());
|
||||||
|
|
||||||
return new DelegatingPasswordEncoder(encodingId, encoders);
|
return new DelegatingPasswordEncoder(encodingId, encoders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AuthenticationProvider daoAuthenticationProvider() {
|
public AuthenticationProvider daoAuthenticationProvider() {
|
||||||
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
|
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
|
||||||
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
|
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package io.reflectoring.passwordencoding.encoder;
|
|||||||
|
|
||||||
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
|
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
|
||||||
|
|
||||||
public class Argon2Example {
|
class Argon2Example {
|
||||||
|
|
||||||
public String encode(String plainPassword) {
|
public String encode(String plainPassword) {
|
||||||
int saltLength = 16; // salt length in bytes
|
int saltLength = 16; // salt length in bytes
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|||||||
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
public class BCryptExample {
|
class BCryptExample {
|
||||||
|
|
||||||
public String encode(String plainPassword) {
|
public String encode(String plainPassword) {
|
||||||
int strength = 10;
|
int strength = 10;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package io.reflectoring.passwordencoding.encoder;
|
|||||||
|
|
||||||
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
|
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
|
||||||
|
|
||||||
public class Pbkdf2Example {
|
class Pbkdf2Example {
|
||||||
|
|
||||||
public String encode(String plainPassword) {
|
public String encode(String plainPassword) {
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package io.reflectoring.passwordencoding.encoder;
|
|||||||
|
|
||||||
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
|
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
|
||||||
|
|
||||||
public class SCryptExample {
|
class SCryptExample {
|
||||||
|
|
||||||
public String encode(String plainPassword) {
|
public String encode(String plainPassword) {
|
||||||
int cpuCost = (int) Math.pow(2, 14); // factor to increase CPU costs
|
int cpuCost = (int) Math.pow(2, 14); // factor to increase CPU costs
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class PasswordMigration {
|
class PasswordMigration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ApplicationListener<AuthenticationSuccessEvent> authenticationSuccessListener(
|
public ApplicationListener<AuthenticationSuccessEvent> authenticationSuccessListener(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class Car {
|
class Car {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String color;
|
private String color;
|
||||||
|
|||||||
@@ -6,12 +6,10 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class CarResources {
|
class CarResources {
|
||||||
|
|
||||||
@GetMapping("/cars")
|
@GetMapping("/cars")
|
||||||
public Set<Car> cars() {
|
public Set<Car> cars() {
|
||||||
return Set.of(
|
return Set.of(new Car("vw", "black"), new Car("bmw", "white"));
|
||||||
new Car("vw", "black"),
|
|
||||||
new Car("bmw", "white"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class UserCredentialsDto {
|
class UserCredentialsDto {
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@Transactional
|
@Transactional
|
||||||
public class UserResources {
|
class UserResources {
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final PasswordEncoder passwordEncoder;
|
private final PasswordEncoder passwordEncoder;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import lombok.Data;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class BcryptWorkFactor {
|
class BcryptWorkFactor {
|
||||||
|
|
||||||
private int strength;
|
private int strength;
|
||||||
private long duration;
|
private long duration;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class Pbkdf2WorkFactorService {
|
class Pbkdf2WorkFactorService {
|
||||||
|
|
||||||
private static final String TEST_PASSWORD = "my password";
|
private static final String TEST_PASSWORD = "my password";
|
||||||
private static final String NO_ADDITIONAL_SECRET = "";
|
private static final String NO_ADDITIONAL_SECRET = "";
|
||||||
|
|||||||
Reference in New Issue
Block a user