001package org.apache.archiva.redback.rest.api.model; 002 003import org.apache.archiva.redback.integration.util.DateUtils; 004 005import javax.xml.bind.annotation.XmlRootElement; 006import java.io.Serializable; 007import java.util.List; 008 009/* 010 * Licensed to the Apache Software Foundation (ASF) under one 011 * or more contributor license agreements. See the NOTICE file 012 * distributed with this work for additional information 013 * regarding copyright ownership. The ASF licenses this file 014 * to you under the Apache License, Version 2.0 (the 015 * "License"); you may not use this file except in compliance 016 * with the License. You may obtain a copy of the License at 017 * 018 * http://www.apache.org/licenses/LICENSE-2.0 019 * 020 * Unless required by applicable law or agreed to in writing, 021 * software distributed under the License is distributed on an 022 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 023 * KIND, either express or implied. See the License for the 024 * specific language governing permissions and limitations 025 * under the License. 026 */ 027 028@XmlRootElement( name = "user" ) 029public class User 030 implements Serializable 031{ 032 private String username; 033 034 private String fullName; 035 036 private String email; 037 038 private boolean validated; 039 040 private boolean locked; 041 042 private String password; 043 044 private boolean passwordChangeRequired; 045 046 private boolean permanent; 047 048 private String confirmPassword; 049 050 // Display Only Fields. 051 private String timestampAccountCreation; 052 053 private String timestampLastLogin; 054 055 private String timestampLastPasswordChange; 056 057 /** 058 * for password change only 059 * 060 * @since 1.4 061 */ 062 private String previousPassword; 063 064 /** 065 * for roles update only <b>not return on user read</b> 066 * 067 * @since 2.0 068 */ 069 private List<String> assignedRoles; 070 071 /** 072 * with some userManagerImpl it's not possible to edit users; 073 * @since 2.1 074 */ 075 private boolean readOnly; 076 077 /** 078 * as we can user multiple userManagers implementation we must track from which one this one comes. 079 * @since 2.1 080 */ 081 private String userManagerId; 082 083 /** 084 * for request validation 085 * 086 * @since 2.2 087 */ 088 private String validationToken; 089 090 091 public User() 092 { 093 // no op 094 } 095 096 public User( String username, String fullName, String email, boolean validated, boolean locked ) 097 { 098 this.username = username; 099 this.fullName = fullName; 100 this.email = email; 101 this.validated = validated; 102 this.locked = locked; 103 } 104 105 public User( org.apache.archiva.redback.users.User user ) 106 { 107 setUsername( user.getUsername() ); 108 this.setEmail( user.getEmail() ); 109 this.setFullName( user.getFullName() ); 110 this.setLocked( user.isLocked() ); 111 this.setPassword( user.getPassword() ); 112 this.setValidated( user.isValidated() ); 113 this.setPasswordChangeRequired( user.isPasswordChangeRequired() ); 114 this.setPermanent( user.isPermanent() ); 115 this.setUserManagerId( user.getUserManagerId() ); 116 117 setTimestampAccountCreation( DateUtils.formatWithAge( user.getAccountCreationDate(), "ago" ) ); 118 setTimestampLastLogin( DateUtils.formatWithAge( user.getLastLoginDate(), "ago" ) ); 119 setTimestampLastPasswordChange( DateUtils.formatWithAge( user.getLastPasswordChange(), "ago" ) ); 120 } 121 122 123 public String getUsername() 124 { 125 return username; 126 } 127 128 public void setUsername( String username ) 129 { 130 this.username = username; 131 } 132 133 public String getFullName() 134 { 135 return fullName; 136 } 137 138 public void setFullName( String fullName ) 139 { 140 this.fullName = fullName; 141 } 142 143 public String getEmail() 144 { 145 return email; 146 } 147 148 public void setEmail( String email ) 149 { 150 this.email = email; 151 } 152 153 public boolean isValidated() 154 { 155 return validated; 156 } 157 158 public void setValidated( boolean validated ) 159 { 160 this.validated = validated; 161 } 162 163 public boolean isLocked() 164 { 165 return locked; 166 } 167 168 public void setLocked( boolean isLocked ) 169 { 170 this.locked = isLocked; 171 } 172 173 public String getPassword() 174 { 175 return password; 176 } 177 178 public void setPassword( String password ) 179 { 180 this.password = password; 181 } 182 183 public boolean isPasswordChangeRequired() 184 { 185 return passwordChangeRequired; 186 } 187 188 public void setPasswordChangeRequired( boolean passwordChangeRequired ) 189 { 190 this.passwordChangeRequired = passwordChangeRequired; 191 } 192 193 public boolean isPermanent() 194 { 195 return permanent; 196 } 197 198 public void setPermanent( boolean permanent ) 199 { 200 this.permanent = permanent; 201 } 202 203 public String getConfirmPassword() 204 { 205 return confirmPassword; 206 } 207 208 public void setConfirmPassword( String confirmPassword ) 209 { 210 this.confirmPassword = confirmPassword; 211 } 212 213 public String getTimestampAccountCreation() 214 { 215 return timestampAccountCreation; 216 } 217 218 public void setTimestampAccountCreation( String timestampAccountCreation ) 219 { 220 this.timestampAccountCreation = timestampAccountCreation; 221 } 222 223 public String getTimestampLastLogin() 224 { 225 return timestampLastLogin; 226 } 227 228 public void setTimestampLastLogin( String timestampLastLogin ) 229 { 230 this.timestampLastLogin = timestampLastLogin; 231 } 232 233 public String getTimestampLastPasswordChange() 234 { 235 return timestampLastPasswordChange; 236 } 237 238 public void setTimestampLastPasswordChange( String timestampLastPasswordChange ) 239 { 240 this.timestampLastPasswordChange = timestampLastPasswordChange; 241 } 242 243 public String getPreviousPassword() 244 { 245 return previousPassword; 246 } 247 248 public void setPreviousPassword( String previousPassword ) 249 { 250 this.previousPassword = previousPassword; 251 } 252 253 public List<String> getAssignedRoles() 254 { 255 return assignedRoles; 256 } 257 258 public void setAssignedRoles( List<String> assignedRoles ) 259 { 260 this.assignedRoles = assignedRoles; 261 } 262 263 public boolean isReadOnly() 264 { 265 return readOnly; 266 } 267 268 public void setReadOnly( boolean readOnly ) 269 { 270 this.readOnly = readOnly; 271 } 272 273 public String getUserManagerId() 274 { 275 return userManagerId; 276 } 277 278 public void setUserManagerId( String userManagerId ) 279 { 280 this.userManagerId = userManagerId; 281 } 282 283 public String getValidationToken() { 284 return validationToken; 285 } 286 287 public void setValidationToken(String validationToken) { 288 this.validationToken = validationToken; 289 } 290 291 @Override 292 public String toString() 293 { 294 return "User{" + 295 "username='" + username + '\'' + 296 ", fullName='" + fullName + '\'' + 297 ", email='" + email + '\'' + 298 ", validated=" + validated + 299 ", locked=" + locked + 300 //", password='" + password + '\'' + 301 ", passwordChangeRequired=" + passwordChangeRequired + 302 ", permanent=" + permanent + 303 ", confirmPassword='" + confirmPassword + '\'' + 304 ", timestampAccountCreation='" + timestampAccountCreation + '\'' + 305 ", timestampLastLogin='" + timestampLastLogin + '\'' + 306 ", timestampLastPasswordChange='" + timestampLastPasswordChange + '\'' + 307 ", previousPassword='" + previousPassword + '\'' + 308 ", assignedRoles=" + assignedRoles + 309 ", readOnly=" + readOnly + 310 ", userManagerId='" + userManagerId + '\'' + 311 ", validationToken='" + validationToken + '\'' + 312 '}'; 313 } 314 315 @Override 316 public boolean equals( Object o ) 317 { 318 if ( this == o ) 319 { 320 return true; 321 } 322 if ( !( o instanceof User ) ) 323 { 324 return false; 325 } 326 327 User user = (User) o; 328 329 if ( !username.equals( user.username ) ) 330 { 331 return false; 332 } 333 334 return true; 335 } 336 337 @Override 338 public int hashCode() 339 { 340 return username.hashCode(); 341 } 342}