public interface User
Encapsulates a username and password.
Factory for
User instances.
Note that a User instance is mutable as the password can be cleared.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PropertyValue<Integer> Specifies the maximum allowed password length.static final PropertyValue<Integer> Specifies the maximum allowed username length. -
Method Summary
-
Field Details
-
MAXIMUM_USERNAME_LENGTH
Specifies the maximum allowed username length.- Value type: Integer
- Default value: 256
-
MAXIMUM_PASSWORD_LENGTH
Specifies the maximum allowed password length.- Value type: Integer
- Default value: 1024
-
-
Method Details
-
username
String username()- Returns:
- the username
-
password
char[] password()- Returns:
- the password, an empty array in case of an empty password
-
clearPassword
User clearPassword()Clears the password- Returns:
- this User instance
-
copy
User copy()- Returns:
- a copy of this User
-
user
Creates a new User with an empty password.- Parameters:
username- the username- Returns:
- a new User
- Throws:
IllegalArgumentException- in case username is an empty string or exceedsMAXIMUM_USERNAME_LENGTH
-
user
Creates a new User.- Parameters:
username- the usernamepassword- the password- Returns:
- a new User
- Throws:
IllegalArgumentException- in case username is an empty string, username exceedsMAXIMUM_USERNAME_LENGTH, or password exceedsMAXIMUM_PASSWORD_LENGTH
-
parse
Parses a User from a string, containing a username and password with a single ':' as delimiter, i.e. "user:pass" or "user:" for en empty password. If no delimiter is found the whole string is assumed to be the username and the password empty. The username portion is trimmed. Any delimeters beyond the initial one are assumed to be part of the password.- Parameters:
userPassword- the username and password string- Returns:
- a User with the given username and password
- Throws:
IllegalArgumentException- in case the username portion is empty, username exceedsMAXIMUM_USERNAME_LENGTH, or password exceedsMAXIMUM_PASSWORD_LENGTH
-