Last active
December 15, 2015 07:49
-
-
Save joshlong/5226079 to your computer and use it in GitHub Desktop.
implementation of the details objects
This file contains hidden or 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
| public static class CrmUserDetails implements UserDetails { | |
| public static final String SCOPE_READ = "read"; | |
| public static final String SCOPE_WRITE = "write"; | |
| public static final String ROLE_USER = "ROLE_USER"; | |
| private Collection<String> roles; | |
| private Collection<GrantedAuthority> grantedAuthorities; | |
| private User user; | |
| public CrmUserDetails(User user) { | |
| assert user != null : "the provided user reference can't be null"; | |
| this.user = user; | |
| this.roles = Arrays.asList(ROLE_USER, SCOPE_READ, SCOPE_WRITE); | |
| this.grantedAuthorities = Collections2.transform(this.roles, new Function<String, GrantedAuthority>() { | |
| @Override | |
| public GrantedAuthority apply(String input) { | |
| return new SimpleGrantedAuthority(input); | |
| } | |
| }); | |
| } | |
| @Override | |
| public Collection<? extends GrantedAuthority> getAuthorities() { | |
| return this.grantedAuthorities; | |
| } | |
| @Override | |
| public String getPassword() { | |
| return this.user.getPassword(); | |
| } | |
| @Override | |
| public String getUsername() { | |
| return this.user.getUsername(); | |
| } | |
| @Override | |
| public boolean isAccountNonExpired() { | |
| return isEnabled(); | |
| } | |
| @Override | |
| public boolean isAccountNonLocked() { | |
| return isEnabled(); | |
| } | |
| @Override | |
| public boolean isCredentialsNonExpired() { | |
| return isEnabled(); | |
| } | |
| @Override | |
| public boolean isEnabled() { | |
| return user.isEnabled(); | |
| } | |
| public User getUser() { | |
| return this.user; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment