Class User.UserBuilder
- java.lang.Object
-
- org.springframework.security.core.userdetails.User.UserBuilder
-
- Enclosing class:
- User
public static final class User.UserBuilder extends java.lang.ObjectBuilds the user to be added. At minimum the username, password, and authorities should provided. The remaining attributes have reasonable defaults.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description User.UserBuilderaccountExpired(boolean accountExpired)Defines if the account is expired or not.User.UserBuilderaccountLocked(boolean accountLocked)Defines if the account is locked or not.User.UserBuilderauthorities(java.lang.String... authorities)Populates the authorities.User.UserBuilderauthorities(java.util.Collection<? extends GrantedAuthority> authorities)Populates the authorities.User.UserBuilderauthorities(GrantedAuthority... authorities)Populates the authorities.UserDetailsbuild()User.UserBuildercredentialsExpired(boolean credentialsExpired)Defines if the credentials are expired or not.User.UserBuilderdisabled(boolean disabled)Defines if the account is disabled or not.User.UserBuilderpassword(java.lang.String password)Populates the password.User.UserBuilderpasswordEncoder(java.util.function.Function<java.lang.String,java.lang.String> encoder)Encodes the current password (if non-null) and any future passwords supplied topassword(String).User.UserBuilderroles(java.lang.String... roles)Populates the roles.User.UserBuilderusername(java.lang.String username)Populates the username.
-
-
-
Method Detail
-
username
public User.UserBuilder username(java.lang.String 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
public User.UserBuilder password(java.lang.String 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
public User.UserBuilder passwordEncoder(java.util.function.Function<java.lang.String,java.lang.String> encoder)
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
public User.UserBuilder roles(java.lang.String... 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
public User.UserBuilder authorities(GrantedAuthority... 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:
roles(String...)
-
authorities
public User.UserBuilder authorities(java.util.Collection<? extends GrantedAuthority> 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:
roles(String...)
-
authorities
public User.UserBuilder authorities(java.lang.String... 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:
roles(String...)
-
accountExpired
public User.UserBuilder accountExpired(boolean 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
public User.UserBuilder accountLocked(boolean 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
public User.UserBuilder credentialsExpired(boolean 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
public User.UserBuilder disabled(boolean 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
public UserDetails build()
-
-