Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ExampleUserDetails extends SocialUser {
- private Long id;
- private String firstName;
- private String lastName;
- private Role role;
- private SocialMediaService socialSignInProvider;
- public ExampleUserDetails(String username, String password, Collection<? extends GrantedAuthority> authorities) {
- super(username, password, authorities);
- }
- //Getters are omitted for the sake of clarity.
- public static class Builder {
- private Long id;
- private String username;
- private String firstName;
- private String lastName;
- private String password;
- private Role role;
- private SocialMediaService socialSignInProvider;
- private Set<GrantedAuthority> authorities;
- public Builder() {
- this.authorities = new HashSet<>();
- }
- public Builder firstName(String firstName) {
- this.firstName = firstName;
- return this;
- }
- public Builder id(Long id) {
- this.id = id;
- return this;
- }
- public Builder lastName(String lastName) {
- this.lastName = lastName;
- return this;
- }
- public Builder password(String password) {
- if (password == null) {
- password = "SocialUser";
- }
- this.password = password;
- return this;
- }
- public Builder role(Role role) {
- this.role = role;
- SimpleGrantedAuthority authority = new SimpleGrantedAuthority(role.toString());
- this.authorities.add(authority);
- return this;
- }
- public Builder socialSignInProvider(SocialMediaService socialSignInProvider) {
- this.socialSignInProvider = socialSignInProvider;
- return this;
- }
- public Builder username(String username) {
- this.username = username;
- return this;
- }
- public ExampleUserDetails build() {
- ExampleUserDetails user = new ExampleUserDetails(username, password, authorities);
- user.id = id;
- user.firstName = firstName;
- user.lastName = lastName;
- user.role = role;
- user.socialSignInProvider = socialSignInProvider;
- return user;
- }
- }
- ExampleUserDetails principal = ExampleUserDetails.getBuilder()
- .firstName(user.getFirstName())
- .id(user.getId())
- .lastName(user.getLastName())
- .password(user.getPassword())
- .role(user.getRole())
- .socialSignInProvider(user.getSignInProvider())
- .username(user.getEmail())
- .build();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement