001package org.apache.archiva.redback.users; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.Serializable; 023import java.util.Date; 024import java.util.List; 025 026/** 027 * The User Object. 028 * 029 * @author Jason van Zyl 030 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> 031 */ 032public interface User 033 extends Serializable 034{ 035 036 // -------------------------------------------------------------------- 037 // Standard User Requirements. 038 // -------------------------------------------------------------------- 039 040 /** 041 * This should return a global user id. Global user ids are built 042 * <code>MANAGER_ID:USER_IDENTIFIER</code> 043 * User identifier must not be the username but must be unique, e.g. for LDAP it may be the DN. 044 * @return 045 */ 046 default String getId() { 047 return getUserManagerId( ) + ":" + getUsername( ); 048 } 049 050 051 /** 052 * Gets the User Name for this user. 053 * 054 * This field is required, and should never be empty. 055 * 056 * @return the user name. 057 */ 058 String getUsername(); 059 060 /** 061 * Sets the User Name for this user. 062 * 063 * This field is required, and should never be empty. 064 * 065 * @param name the user name. 066 */ 067 void setUsername( String name ); 068 069 /** 070 * Gets the Full Name for this user. 071 * 072 * This field is required, and should never be empty. 073 * 074 * @return the full name. 075 */ 076 String getFullName(); 077 078 /** 079 * Sets the Full Name for this user. 080 * 081 * This field is required, and should never be empty. 082 * 083 * @param name the full name. 084 */ 085 void setFullName( String name ); 086 087 /** 088 * Gets the email address for this user. 089 * 090 * This field is required, and should never be empty. 091 * 092 * @return the email address. 093 */ 094 String getEmail(); 095 096 /** 097 * Sets the email address for this user. 098 * 099 * This field is required, and should never be empty. 100 * 101 * @param address the email address. 102 */ 103 void setEmail( String address ); 104 105 // -------------------------------------------------------------------- 106 // Password Requirements. 107 // -------------------------------------------------------------------- 108 109 /** 110 * Gets the Raw (unencoded) Password. 111 * Used only on password change requests. 112 * 113 * <p> 114 * <b>Notes for User Providers</b> 115 * </p> 116 * <ol> 117 * <li> 118 * Providers need to look for a value in here to indicate if the user is 119 * intending to change their password. 120 * </li> 121 * <li> 122 * The providers of this interface need to use this field, encode the password, place it's value 123 * into the encodedPassword field, and clear out the raw unencoded password field. 124 * </li> 125 * <li> 126 * This field should never be stored on disk. 127 * </li> 128 * </ol> 129 * 130 * @return the raw encoded password. 131 */ 132 String getPassword(); 133 134 /** 135 * Sets the raw (unencoded) password for this user. 136 * 137 * @param rawPassword the raw unencoded password for this user. 138 * @see #getPassword() 139 */ 140 void setPassword( String rawPassword ); 141 142 /** 143 * Gets the Encoded Password. 144 * 145 * @return the encoded password. 146 */ 147 String getEncodedPassword(); 148 149 /** 150 * Sets the Encoded Password. 151 * 152 * This field is populated by the {@link UserManager} process. 153 * 154 * @param encodedPassword 155 */ 156 void setEncodedPassword( String encodedPassword ); 157 158 /** 159 * Gets the Date of the Last Password Change. 160 * 161 * Used by password management policies to enforce password expiration rules. 162 * 163 * @return the date of the last password change. 164 */ 165 Date getLastPasswordChange(); 166 167 /** 168 * Sets the Last Password Change Date. 169 * 170 * This field is populated by the {@link UserManager} process. 171 * 172 * @param passwordChangeDate the date that the last password change occured. 173 */ 174 void setLastPasswordChange( Date passwordChangeDate ); 175 176 /** 177 * Gets the list of previous password (in encoded format). 178 * 179 * Used by password management policies to enforce password reuse rules. 180 * 181 * @return the list of {@link String} objects. Represents previous passwords (in encoded format). 182 */ 183 List<String> getPreviousEncodedPasswords(); 184 185 /** 186 * Sets the list of previous passwords (in encoded format) 187 * 188 * @param encodedPasswordList (list of {@link String} objects.) the previously passwords in encoded format. 189 */ 190 void setPreviousEncodedPasswords( List<String> encodedPasswordList ); 191 192 /** 193 * Add encoded password to previously passwords in encoded format. 194 * 195 * @param encodedPassword the encoded password to add. 196 */ 197 void addPreviousEncodedPassword( String encodedPassword ); 198 199 // -------------------------------------------------------------------- 200 // State 201 // -------------------------------------------------------------------- 202 203 /** 204 * Gets the flag indicating if this user is a permanent user or not. 205 * 206 * Usually Root / Admin / Guest users are flagged as such. 207 */ 208 boolean isPermanent(); 209 210 /** 211 * Sets the permanent flag for this user. 212 * 213 * Users such as Root / Admin / Guest are typically flagged as permanent. 214 * 215 * @param permanent true if permanent. 216 */ 217 void setPermanent( boolean permanent ); 218 219 /** 220 * Determines if this user account is locked from use or not. 221 * 222 * This state is set from an administrative point of view, or due to 223 * excessive failed login attempts. 224 * 225 * @return true if account is locked. 226 */ 227 boolean isLocked(); 228 229 /** 230 * Sets the locked state of this account. 231 * 232 * @param locked true if account is to be locked. 233 */ 234 void setLocked( boolean locked ); 235 236 /** 237 * Determines if this user account must change their password on next login. 238 * 239 * @return true if user must change password on next login. 240 */ 241 boolean isPasswordChangeRequired(); 242 243 /** 244 * Sets the flag to indicate if this user must change their password on next login. 245 * 246 * @param changeRequired true if user must change password on next login. 247 */ 248 void setPasswordChangeRequired( boolean changeRequired ); 249 250 /** 251 * Gets the flag indicating if this user has been validated (or not) 252 * 253 * @return true if validated. 254 */ 255 boolean isValidated(); 256 257 /** 258 * Sets the flag indicating if this user has been validated (or not) 259 * 260 * @param valid true if validated. 261 */ 262 void setValidated( boolean valid ); 263 264 // -------------------------------------------------------------------- 265 // Statistics 266 // -------------------------------------------------------------------- 267 268 /** 269 * Get Count of Failed Login Attempts. 270 * 271 * @return the count of failed login attempts. 272 */ 273 int getCountFailedLoginAttempts(); 274 275 /** 276 * Set the count of failed login attempts. 277 * 278 * @param count the count of failed login attempts. 279 */ 280 void setCountFailedLoginAttempts( int count ); 281 282 /** 283 * Get the Creation Date for this account. 284 * 285 * @return the date of creation for this account. 286 */ 287 Date getAccountCreationDate(); 288 289 /** 290 * Set the Creation Date for this account. 291 */ 292 void setAccountCreationDate( Date date ); 293 294 /** 295 * Get the Last Successful Login Date for this account. 296 * 297 * @return the date of the last successful login 298 */ 299 Date getLastLoginDate(); 300 301 /** 302 * Sets the Last Successful Login Date for this account. 303 */ 304 void setLastLoginDate( Date date ); 305 306 /** 307 * as we can user multiple userManagers implementation we must track from which one this one comes. 308 * @since 2.1 309 * @return userManager id 310 */ 311 String getUserManagerId(); 312 313 314}