make classes package private, apply google-java-formatter

This commit is contained in:
akuksin
2020-02-27 22:17:40 +01:00
parent ab5143cb2f
commit bfd004b73a
19 changed files with 299 additions and 296 deletions

View File

@@ -16,8 +16,7 @@ import java.util.Set;
@Table(name = "users")
public class UserCredentials {
@Id
private String username;
@Id private String username;
private String password;

View File

@@ -5,7 +5,7 @@ import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
@Component
public class UserDetailsMapper {
class UserDetailsMapper {
UserDetails toUserDetails(UserCredentials userCredentials) {

View File

@@ -57,8 +57,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(daoAuthenticationProvider())
.eraseCredentials(false);
auth.authenticationProvider(daoAuthenticationProvider()).eraseCredentials(false);
}
@Bean
@@ -66,22 +65,30 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
// we must user deprecated encoder to support their encoding
String encodingId = "bcrypt";
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("MD4", new org.springframework.security.crypto.password.Md4PasswordEncoder());
encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));
encoders.put("noop", org.springframework.security.crypto.password.NoOpPasswordEncoder.getInstance());
encoders.put(
"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("scrypt", new SCryptPasswordEncoder());
encoders.put("SHA-1", 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(
"SHA-1",
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());
return new DelegatingPasswordEncoder(encodingId, encoders);
}
public AuthenticationProvider daoAuthenticationProvider() {
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());

View File

@@ -2,7 +2,7 @@ package io.reflectoring.passwordencoding.encoder;
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
public class Argon2Example {
class Argon2Example {
public String encode(String plainPassword) {
int saltLength = 16; // salt length in bytes

View File

@@ -4,7 +4,7 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import java.security.SecureRandom;
public class BCryptExample {
class BCryptExample {
public String encode(String plainPassword) {
int strength = 10;

View File

@@ -2,7 +2,7 @@ package io.reflectoring.passwordencoding.encoder;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
public class Pbkdf2Example {
class Pbkdf2Example {
public String encode(String plainPassword) {

View File

@@ -2,7 +2,7 @@ package io.reflectoring.passwordencoding.encoder;
import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
public class SCryptExample {
class SCryptExample {
public String encode(String plainPassword) {
int cpuCost = (int) Math.pow(2, 14); // factor to increase CPU costs

View File

@@ -11,7 +11,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
@Component
public class PasswordMigration {
class PasswordMigration {
@Bean
public ApplicationListener<AuthenticationSuccessEvent> authenticationSuccessListener(

View File

@@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
public class Car {
class Car {
private String name;
private String color;

View File

@@ -6,12 +6,10 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Set;
@RestController
public class CarResources {
class CarResources {
@GetMapping("/cars")
public Set<Car> cars() {
return Set.of(
new Car("vw", "black"),
new Car("bmw", "white"));
return Set.of(new Car("vw", "black"), new Car("bmw", "white"));
}
}

View File

@@ -9,8 +9,7 @@ import lombok.NoArgsConstructor;
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserCredentialsDto {
class UserCredentialsDto {
private String username;
private String password;
}

View File

@@ -14,7 +14,7 @@ import java.util.Set;
@RestController
@Transactional
public class UserResources {
class UserResources {
private final UserRepository userRepository;
private final PasswordEncoder passwordEncoder;

View File

@@ -5,7 +5,7 @@ import lombok.Data;
@Data
@AllArgsConstructor
public class BcryptWorkFactor {
class BcryptWorkFactor {
private int strength;
private long duration;

View File

@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
@Component
public class Pbkdf2WorkFactorService {
class Pbkdf2WorkFactorService {
private static final String TEST_PASSWORD = "my password";
private static final String NO_ADDITIONAL_SECRET = "";