Make UserBuilder.username public

This allows for reusing a UserBuilder to create multiple UserDetails with
similar attributes but different usernames.

Fixes gh-4453
This commit is contained in:
Rob Winch 2017-07-12 13:54:52 -05:00
parent acd9de6fad
commit 0b481cf4b6
1 changed files with 17 additions and 2 deletions

View File

@ -244,8 +244,23 @@ public class User implements UserDetails, CredentialsContainer {
return sb.toString();
}
/**
* Creates a UserBuilder with a specified user name
*
* @param username the username to use
* @return the UserBuilder
*/
public static UserBuilder withUsername(String username) {
return new UserBuilder().username(username);
return builder().username(username);
}
/**
* Creates a UserBuilder
*
* @return the UserBuilder
*/
public static UserBuilder builder() {
return new UserBuilder();
}
public static UserBuilder withUserDetails(UserDetails userDetails) {
@ -284,7 +299,7 @@ public class User implements UserDetails, CredentialsContainer {
* @return the {@link UserBuilder} for method chaining (i.e. to populate
* additional attributes for this user)
*/
private UserBuilder username(String username) {
public UserBuilder username(String username) {
Assert.notNull(username, "username cannot be null");
this.username = username;
return this;