From 6585c2b3917b668c1dd940637425e30387f5ef8d Mon Sep 17 00:00:00 2001
From: Ben Alex String
). Developers may use this class directly, subclass
* it, or write their own {@link UserDetails} implementation from scratch.
*
User
with the details required by {@link
* DaoAuthenticationProvider}.
@@ -129,61 +130,22 @@ public class User implements UserDetails {
boolean accountNonExpired, boolean credentialsNonExpired,
boolean accountNonLocked, GrantedAuthority[] authorities)
throws IllegalArgumentException {
- if (((username == null) || "".equals(username)) || (password == null)
- || (authorities == null)) {
+ if (((username == null) || "".equals(username)) || (password == null)) {
throw new IllegalArgumentException(
"Cannot pass null or empty values to constructor");
}
- for (int i = 0; i < authorities.length; i++) {
- Assert.notNull(authorities[i],
- "Granted authority element " + i
- + " is null - GrantedAuthority[] cannot contain any null elements");
- }
-
this.username = username;
this.password = password;
this.enabled = enabled;
- this.authorities = authorities;
this.accountNonExpired = accountNonExpired;
this.credentialsNonExpired = credentialsNonExpired;
this.accountNonLocked = accountNonLocked;
- }
-
- protected User() {
- throw new IllegalArgumentException("Cannot use default constructor");
+ setAuthorities(authorities);
}
//~ Methods ================================================================
- public boolean isAccountNonExpired() {
- return accountNonExpired;
- }
-
- public boolean isAccountNonLocked() {
- return this.accountNonLocked;
- }
-
- public GrantedAuthority[] getAuthorities() {
- return authorities;
- }
-
- public boolean isCredentialsNonExpired() {
- return credentialsNonExpired;
- }
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getUsername() {
- return username;
- }
-
public boolean equals(Object rhs) {
if (!(rhs instanceof User) || (rhs == null)) {
return false;
@@ -211,6 +173,46 @@ public class User implements UserDetails {
&& (this.isEnabled() == user.isEnabled()));
}
+ public GrantedAuthority[] getAuthorities() {
+ return authorities;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public boolean isAccountNonExpired() {
+ return accountNonExpired;
+ }
+
+ public boolean isAccountNonLocked() {
+ return this.accountNonLocked;
+ }
+
+ public boolean isCredentialsNonExpired() {
+ return credentialsNonExpired;
+ }
+
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ protected void setAuthorities(GrantedAuthority[] authorities) {
+ Assert.notNull(authorities, "Cannot pass a null GrantedAuthority array");
+
+ for (int i = 0; i < authorities.length; i++) {
+ Assert.notNull(authorities[i],
+ "Granted authority element " + i
+ + " is null - GrantedAuthority[] cannot contain any null elements");
+ }
+
+ this.authorities = authorities;
+ }
+
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(super.toString() + ": ");