Package com.patreonshout.config
Class SecurityConfiguration
java.lang.Object
com.patreonshout.config.SecurityConfiguration
@Configuration
public class SecurityConfiguration
extends java.lang.Object
Spring Security Configuration
-
Field Summary
Fields Modifier and Type Field Description (package private) org.passay.PasswordValidator
passwordValidator
Set of requirements a password must meet to be considered validjava.lang.String
pepper
Pepper value for WebAccount passwords -- used as a constant value included in every password(package private) java.security.SecureRandom
secureRandom
-
Constructor Summary
Constructors Constructor Description SecurityConfiguration()
-
Method Summary
Modifier and Type Method Description java.lang.String
createSalt()
Generates a pseudo-random salt of 124 bytes utilizingSecureRandom
java.lang.String
encodePassword(java.lang.String rawPassword, java.lang.String salt)
Encodes given passwords withBCryptPasswordEncoder
The password is encrypted in the following form: (pepper + rawPassword + salt) where the "pepper" constant is assigned in the Spring application propertiesboolean
passwordIsValid(java.lang.String rawPassword)
Checks if the given raw password fits our password requirements.
Requirements At least one uppercase character At least one lowercase character At least one digit At least one symbol (special character) No spacesboolean
passwordMatches(java.lang.String rawPassword, java.lang.String salt, java.lang.String encodedPassword)
Checks if a given password and salt combine to the given encoded password.java.lang.String
SHA1Encoder(java.lang.String text)
SHA1 encodes textMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
secureRandom
java.security.SecureRandom secureRandom -
passwordValidator
org.passay.PasswordValidator passwordValidatorSet of requirements a password must meet to be considered valid -
pepper
@Value("${patreonshout.db.webaccount.pepper}") public java.lang.String pepperPepper value for WebAccount passwords -- used as a constant value included in every password
-
-
Constructor Details
-
SecurityConfiguration
public SecurityConfiguration()
-
-
Method Details
-
SHA1Encoder
public java.lang.String SHA1Encoder(java.lang.String text)SHA1 encodes text- Parameters:
text
- text to encode- Returns:
- SHA1 encoded text
-
encodePassword
public java.lang.String encodePassword(java.lang.String rawPassword, java.lang.String salt)Encodes given passwords withBCryptPasswordEncoder
The password is encrypted in the following form: (pepper + rawPassword + salt) where the "pepper" constant is assigned in the Spring application properties- Returns:
PasswordEncoderFactories
object that defaults to BCrypt encoding
-
passwordMatches
public boolean passwordMatches(java.lang.String rawPassword, java.lang.String salt, java.lang.String encodedPassword)Checks if a given password and salt combine to the given encoded password. This function utilizes the "pepper" constant that is assigned in the application properties.- Parameters:
rawPassword
-String
raw password retrieved from user inputencodedPassword
-String
Encoded password retrieved from aWebAccountFunctions
in the database- Returns:
Boolean
true if password matches, false otherwise
-
createSalt
public java.lang.String createSalt()Generates a pseudo-random salt of 124 bytes utilizingSecureRandom
- Returns:
- 124 bytes
-
passwordIsValid
public boolean passwordIsValid(java.lang.String rawPassword)Checks if the given raw password fits our password requirements.
Requirements- At least one uppercase character
- At least one lowercase character
- At least one digit
- At least one symbol (special character)
- No spaces
- Parameters:
rawPassword
- password to check- Returns:
Boolean.TRUE
if password meets our password requirements,Boolean.FALSE
otherwise
-