Class User.UserBuilder
java.lang.Object
org.springframework.security.core.userdetails.User.UserBuilder
- Enclosing class:
- User
Builds the user to be added. At minimum the username, password, and authorities
should provided. The remaining attributes have reasonable defaults.
-
Method Summary
Modifier and TypeMethodDescriptionaccountExpired(boolean accountExpired) Defines if the account is expired or not.accountLocked(boolean accountLocked) Defines if the account is locked or not.authorities(String... authorities) Populates the authorities.authorities(Collection<? extends GrantedAuthority> authorities) Populates the authorities.authorities(GrantedAuthority... authorities) Populates the authorities.build()credentialsExpired(boolean credentialsExpired) Defines if the credentials are expired or not.disabled(boolean disabled) Defines if the account is disabled or not.Populates the password.passwordEncoder(Function<String, String> encoder) Encodes the current password (if non-null) and any future passwords supplied topassword(String).Populates the roles.Populates the username.
-
Method Details
-
username
Populates the username. This attribute is required.- Parameters:
username- the username. Cannot be null.- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user)
-
password
Populates the password. This attribute is required.- Parameters:
password- the password. Cannot be null.- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user)
-
passwordEncoder
Encodes the current password (if non-null) and any future passwords supplied topassword(String).- Parameters:
encoder- the encoder to use- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user)
-
roles
Populates the roles. This method is a shortcut for callingauthorities(String...), but automatically prefixes each entry with "ROLE_". This means the following:builder.roles("USER","ADMIN");is equivalent tobuilder.authorities("ROLE_USER","ROLE_ADMIN");This attribute is required, but can also be populated with
authorities(String...).- Parameters:
roles- the roles for this user (i.e. USER, ADMIN, etc). Cannot be null, contain null values or start with "ROLE_"- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user)
-
authorities
Populates the authorities. This attribute is required.- Parameters:
authorities- the authorities for this user. Cannot be null, or contain null values- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user) - See Also:
-
authorities
Populates the authorities. This attribute is required.- Parameters:
authorities- the authorities for this user. Cannot be null, or contain null values- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user) - See Also:
-
authorities
Populates the authorities. This attribute is required.- Parameters:
authorities- the authorities for this user (i.e. ROLE_USER, ROLE_ADMIN, etc). Cannot be null, or contain null values- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user) - See Also:
-
accountExpired
Defines if the account is expired or not. Default is false.- Parameters:
accountExpired- true if the account is expired, false otherwise- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user)
-
accountLocked
Defines if the account is locked or not. Default is false.- Parameters:
accountLocked- true if the account is locked, false otherwise- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user)
-
credentialsExpired
Defines if the credentials are expired or not. Default is false.- Parameters:
credentialsExpired- true if the credentials are expired, false otherwise- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user)
-
disabled
Defines if the account is disabled or not. Default is false.- Parameters:
disabled- true if the account is disabled, false otherwise- Returns:
- the
User.UserBuilderfor method chaining (i.e. to populate additional attributes for this user)
-
build
-