1 19 20 package com.sslexplorer.security; 21 22 import java.io.Serializable ; 23 import java.util.Arrays ; 24 import java.util.Date ; 25 26 import com.sslexplorer.realms.Realm; 27 28 33 public class DefaultUser implements User, Serializable { 34 protected String principalName; 35 protected String email; 36 protected String fullname; 37 protected Date lastPasswordChange; 38 protected Role[] roles; 39 private final Realm realm; 40 41 48 public DefaultUser(String principalName, String email, String fullname, Date lastPasswordChange, Realm realm) { 49 this.principalName = principalName; 50 this.email = email; 51 this.fullname = fullname; 52 this.lastPasswordChange = lastPasswordChange; 53 this.realm = realm; 54 } 55 56 60 public Date getLastPasswordChange() { 61 return lastPasswordChange; 62 } 63 64 public boolean requiresPasswordChange() { 65 return lastPasswordChange == null; 66 } 67 68 72 public String getPrincipalName() { 73 return principalName; 74 } 75 76 80 public String getEmail() { 81 return email; 82 } 83 84 88 public String getFullname() { 89 return fullname; 90 } 91 92 96 public String getHomeNetworkPlaceUri() { 97 return null; 98 } 99 100 106 public boolean containsRole(String rolename) { 107 if (roles == null) { 108 return false; 109 } 110 111 for (int i = 0; i < roles.length; i++) { 112 if (roles[i].getPrincipalName().equals(rolename)) 113 return true; 114 } 115 116 return false; 117 } 118 119 123 public Role[] getRoles() { 124 return roles; 125 } 126 127 131 public void setRoles(Role[] roles) { 132 this.roles = roles; 133 } 134 135 139 public void setPrincipalName(String principalName) { 140 this.principalName = principalName; 141 } 142 143 147 public void setEmail(String email) { 148 this.email = email; 149 } 150 151 155 public void setFullname(String fullname) { 156 this.fullname = fullname; 157 158 } 159 160 164 public void setLastPasswordChange(Date lastPasswordChange) { 165 this.lastPasswordChange = lastPasswordChange; 166 } 167 168 171 public boolean equals(Object o) { 172 return o instanceof User && ((User)o).getPrincipalName().equals(getPrincipalName()) 173 && ((User)o).getRealm().equals(getRealm()); 174 } 175 176 179 @Override 180 public int hashCode() { 181 return ( getRealm().getResourceId() + "_" + getPrincipalName() ).hashCode(); 182 } 183 184 187 public int compareTo(Object o) { 188 return o instanceof User ? (getPrincipalName().compareTo(((User)o).getPrincipalName())) : 1; 189 } 190 191 194 public Realm getRealm() { 195 return this.realm; 196 } 197 198 @Override 199 public String toString() { 200 StringBuffer buffer = new StringBuffer (super.toString()); 201 buffer.append("["); 202 buffer.append("principalName='").append(principalName).append("' "); 203 buffer.append("email='").append(email).append("' "); 204 buffer.append("fullname='").append(fullname).append("' "); 205 buffer.append("lastPasswordChange='").append(lastPasswordChange).append("' "); 206 buffer.append("roles='").append(roles == null ? "" : Arrays.asList(roles)).append("' "); 207 buffer.append("realm='").append(realm).append("'"); 208 buffer.append("']"); 209 return buffer.toString(); 210 } 211 } | Popular Tags |