-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding SpringUserAdapter and making it implement UserDetails. User cl…
…ass is now free of Spring, Adapter takes care about that.
- Loading branch information
1 parent
9fdbd23
commit 5230203
Showing
5 changed files
with
71 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.webcalc.user; | ||
|
||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
|
||
import java.util.Collection; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
public class SpringUserAdapter implements UserDetails { | ||
|
||
private final User user; | ||
|
||
public SpringUserAdapter(User user) { | ||
this.user = user; | ||
} | ||
|
||
public User getUser() { | ||
return user; | ||
} | ||
|
||
@Override | ||
public Collection<? extends GrantedAuthority> getAuthorities() { | ||
return emptyList(); | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return user.getPassword(); | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return user.getUsername(); | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonExpired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonLocked() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isCredentialsNonExpired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,24 @@ | ||
package com.webcalc.user; | ||
|
||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
|
||
import java.util.Collection; | ||
import java.util.UUID; | ||
|
||
public class User implements UserDetails { | ||
public class User { | ||
|
||
public final UUID id; | ||
|
||
private final UserDetails springSecUser; | ||
private final String username; | ||
private final String password; | ||
|
||
public User(UUID id, String username, String password) { | ||
this.id = id; | ||
springSecUser = org.springframework.security.core.userdetails.User.builder() | ||
.username(username) | ||
.password(password) | ||
.roles() | ||
.build(); | ||
} | ||
|
||
@Override | ||
public Collection<? extends GrantedAuthority> getAuthorities() { | ||
return springSecUser.getAuthorities(); | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return springSecUser.getPassword(); | ||
this.username = username; | ||
this.password = password; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return springSecUser.getUsername(); | ||
return username; | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonExpired() { | ||
return springSecUser.isAccountNonExpired(); | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonLocked() { | ||
return springSecUser.isAccountNonLocked(); | ||
} | ||
|
||
@Override | ||
public boolean isCredentialsNonExpired() { | ||
return springSecUser.isCredentialsNonExpired(); | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return springSecUser.isEnabled(); | ||
public String getPassword() { | ||
return password; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters