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