|
|
|
@ -26,24 +26,24 @@ import org.springframework.security.core.GrantedAuthority; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Models core user information retieved by an {@link UserDetailsService}.<p>Implemented with value object |
|
|
|
* Models core user information retrieved by a {@link UserDetailsService}. |
|
|
|
* semantics (immutable after construction, like a <code>String</code>). Developers may use this class directly, |
|
|
|
* <p> |
|
|
|
* subclass it, or write their own {@link UserDetails} implementation from scratch.</p> |
|
|
|
* Implemented with value object semantics (immutable after construction, like a <code>String</code>). |
|
|
|
|
|
|
|
* Developers may use this class directly, subclass it, or write their own {@link UserDetails} implementation from |
|
|
|
|
|
|
|
* scratch. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Ben Alex |
|
|
|
* @author Ben Alex |
|
|
|
* @version $Id$ |
|
|
|
* @version $Id$ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class User implements UserDetails { |
|
|
|
public class User implements UserDetails { |
|
|
|
//~ Instance fields ================================================================================================
|
|
|
|
//~ Instance fields ================================================================================================
|
|
|
|
|
|
|
|
private final String password; |
|
|
|
private static final long serialVersionUID = 1L; |
|
|
|
private final String username; |
|
|
|
private String password; |
|
|
|
private final List<GrantedAuthority> authorities; |
|
|
|
private String username; |
|
|
|
private final boolean accountNonExpired; |
|
|
|
private List<GrantedAuthority> authorities; |
|
|
|
private final boolean accountNonLocked; |
|
|
|
private boolean accountNonExpired; |
|
|
|
private final boolean credentialsNonExpired; |
|
|
|
private boolean accountNonLocked; |
|
|
|
private final boolean enabled; |
|
|
|
private boolean credentialsNonExpired; |
|
|
|
|
|
|
|
private boolean enabled; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//~ Constructors ===================================================================================================
|
|
|
|
//~ Constructors ===================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
@ -92,7 +92,7 @@ public class User implements UserDetails { |
|
|
|
this.accountNonExpired = accountNonExpired; |
|
|
|
this.accountNonExpired = accountNonExpired; |
|
|
|
this.credentialsNonExpired = credentialsNonExpired; |
|
|
|
this.credentialsNonExpired = credentialsNonExpired; |
|
|
|
this.accountNonLocked = accountNonLocked; |
|
|
|
this.accountNonLocked = accountNonLocked; |
|
|
|
setAuthorities(authorities); |
|
|
|
this.authorities = Collections.unmodifiableList(sortAuthorities(authorities)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//~ Methods ========================================================================================================
|
|
|
|
//~ Methods ========================================================================================================
|
|
|
|
@ -182,7 +182,7 @@ public class User implements UserDetails { |
|
|
|
return enabled; |
|
|
|
return enabled; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void setAuthorities(List<GrantedAuthority> authorities) { |
|
|
|
private static List<GrantedAuthority> sortAuthorities(List<GrantedAuthority> authorities) { |
|
|
|
Assert.notNull(authorities, "Cannot pass a null GrantedAuthority array"); |
|
|
|
Assert.notNull(authorities, "Cannot pass a null GrantedAuthority array"); |
|
|
|
// Ensure array iteration order is predictable (as per UserDetails.getAuthorities() contract and SEC-xxx)
|
|
|
|
// Ensure array iteration order is predictable (as per UserDetails.getAuthorities() contract and SEC-xxx)
|
|
|
|
SortedSet<GrantedAuthority> sorter = new TreeSet<GrantedAuthority>(); |
|
|
|
SortedSet<GrantedAuthority> sorter = new TreeSet<GrantedAuthority>(); |
|
|
|
@ -195,7 +195,7 @@ public class User implements UserDetails { |
|
|
|
List<GrantedAuthority> sortedAuthorities = new ArrayList<GrantedAuthority>(sorter.size()); |
|
|
|
List<GrantedAuthority> sortedAuthorities = new ArrayList<GrantedAuthority>(sorter.size()); |
|
|
|
sortedAuthorities.addAll(sorter); |
|
|
|
sortedAuthorities.addAll(sorter); |
|
|
|
|
|
|
|
|
|
|
|
this.authorities = Collections.unmodifiableList(sortedAuthorities); |
|
|
|
return sortedAuthorities; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
|