001package org.apache.archiva.redback.common.ldap.user; 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 org.apache.archiva.redback.users.User; 023 024import javax.naming.directory.Attributes; 025import java.io.Serializable; 026import java.util.ArrayList; 027import java.util.Date; 028import java.util.List; 029 030// TODO this class should be able to be replaced with a model 031public class LdapUser 032 implements User, Serializable 033{ 034 private String dn; 035 036 private String username; 037 038 private String fullName; 039 040 private String email; 041 042 private String encodedPassword; 043 044 private List<String> previousEncodedPasswords; 045 046 private boolean locked = false; 047 048 private boolean requiresPasswordChange = false; 049 050 private boolean permanent = true; 051 052 private boolean valid = true; 053 054 private Date creationDate = null; 055 056 private int failedLoginAttempts; 057 058 private Date lastLoginDate = null; 059 060 private Date lastPasswordChange = null; 061 062 // DO NOT STORE AS SUCH!!! 063 private String newPassword; 064 065 private Attributes originalAttributes; 066 067 /** 068 * @since 2.1 069 */ 070 private String userManagerId = "ldap"; 071 072 public LdapUser( String username ) 073 { 074 this.username = username; 075 this.previousEncodedPasswords = new ArrayList<String>( 0 ); 076 this.failedLoginAttempts = 0; 077 } 078 079 public LdapUser( String username, String fullName, String email ) 080 { 081 this( username ); 082 this.fullName = fullName; 083 this.email = email; 084 } 085 086 public LdapUser() 087 { 088 previousEncodedPasswords = new ArrayList<String>( 0 ); 089 failedLoginAttempts = Integer.MIN_VALUE; 090 } 091 092 public void addPreviousEncodedPassword( String encodedPassword ) 093 { 094 previousEncodedPasswords.add( encodedPassword ); 095 } 096 097 public Date getAccountCreationDate() 098 { 099 return creationDate; 100 } 101 102 public int getCountFailedLoginAttempts() 103 { 104 return failedLoginAttempts; 105 } 106 107 public String getEmail() 108 { 109 return email; 110 } 111 112 public String getEncodedPassword() 113 { 114 return encodedPassword; 115 } 116 117 public String getFullName() 118 { 119 return fullName; 120 } 121 122 public Date getLastLoginDate() 123 { 124 return lastLoginDate; 125 } 126 127 public Date getLastPasswordChange() 128 { 129 return lastPasswordChange; 130 } 131 132 public String getPassword() 133 { 134 return newPassword; 135 } 136 137 public List<String> getPreviousEncodedPasswords() 138 { 139 return previousEncodedPasswords; 140 } 141 142 143 public String getUsername() 144 { 145 return username; 146 } 147 148 public boolean isLocked() 149 { 150 return locked; 151 } 152 153 public boolean isPasswordChangeRequired() 154 { 155 return requiresPasswordChange; 156 } 157 158 public boolean isPermanent() 159 { 160 return permanent; 161 } 162 163 public boolean isValidated() 164 { 165 return valid; 166 } 167 168 public void setCountFailedLoginAttempts( int count ) 169 { 170 failedLoginAttempts = count; 171 } 172 173 public void setEmail( String address ) 174 { 175 email = address; 176 } 177 178 public void setEncodedPassword( String encodedPassword ) 179 { 180 this.encodedPassword = encodedPassword; 181 } 182 183 public void setFullName( String name ) 184 { 185 fullName = name; 186 } 187 188 public void setAccountCreationDate( Date date ) 189 { 190 creationDate = date; 191 } 192 193 public void setLastLoginDate( Date date ) 194 { 195 lastLoginDate = date; 196 } 197 198 public void setLastPasswordChange( Date passwordChangeDate ) 199 { 200 lastPasswordChange = passwordChangeDate; 201 } 202 203 public void setLocked( boolean locked ) 204 { 205 this.locked = locked; 206 } 207 208 public void setPassword( String rawPassword ) 209 { 210 newPassword = rawPassword; 211 } 212 213 public void setPasswordChangeRequired( boolean changeRequired ) 214 { 215 requiresPasswordChange = changeRequired; 216 } 217 218 public void setPermanent( boolean permanent ) 219 { 220 this.permanent = permanent; 221 } 222 223 public void setPreviousEncodedPasswords( List<String> encodedPasswordList ) 224 { 225 previousEncodedPasswords = new ArrayList<String>( encodedPasswordList ); 226 } 227 228 public void setUsername( String name ) 229 { 230 username = name; 231 } 232 233 public void setValidated( boolean valid ) 234 { 235 this.valid = valid; 236 } 237 238 public Attributes getOriginalAttributes() 239 { 240 return originalAttributes; 241 } 242 243 public void setOriginalAttributes( Attributes originalAttributes ) 244 { 245 this.originalAttributes = originalAttributes; 246 } 247 248 public String getUserManagerId() 249 { 250 return userManagerId; 251 } 252 253 public String getDn( ) 254 { 255 return dn; 256 } 257 258 public void setDn( String dn ) 259 { 260 this.dn = dn; 261 } 262 263 @Override 264 public String getId( ) 265 { 266 return userManagerId + ":" + dn; 267 } 268}