View Javadoc

1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.security.om.impl;
18  
19  import java.sql.Date;
20  import java.sql.Timestamp;
21  
22  import org.apache.jetspeed.security.om.InternalCredential;
23  
24  /***
25   * <p>{@link InternalCredential} interface implementation.</p>
26   * 
27   * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
28   * @version $Id: InternalCredentialImpl.java 516448 2007-03-09 16:25:47Z ate $
29   */
30  public class InternalCredentialImpl implements InternalCredential
31  {
32      /*** The serial version uid. */
33      private static final long serialVersionUID = -8064404995292602590L;
34  
35      /***
36       * <p>InternalCredential implementation default constructor.</p>
37       */
38      public InternalCredentialImpl()
39      {
40      }
41  
42      /***
43       * <p>InternalCredentialImpl constructor given a value, type and classname.</p>
44       * @param principalId The principal id.
45       * @param value The value.
46       * @param type The type.
47       * @param classname The classname.
48       */
49      public InternalCredentialImpl(long principalId, String value, int type, String classname)
50      {
51          this.principalId = principalId;
52          this.value = value;
53          this.type = type;
54          this.classname = classname;
55          this.creationDate = new Timestamp(new java.util.Date().getTime());
56          this.modifiedDate = this.creationDate;
57      }
58      
59      /***
60       * <p>InternalCredentialImpl copy constructor given another InternalCredential and overriding classname</p>
61       * @param credential The credential to copy from
62       * @param classname The classname for the new credential
63       */
64      public InternalCredentialImpl(InternalCredential credential, String classname)
65      {
66          this.authenticationFailures = credential.getAuthenticationFailures();
67          this.classname = classname;
68          this.creationDate = credential.getCreationDate();
69          this.enabled = credential.isEnabled();
70          this.encoded = credential.isEncoded();
71          this.expirationDate = credential.getExpirationDate();
72          this.expired = credential.isExpired();
73          this.previousAuthenticationDate = credential.getPreviousAuthenticationDate();
74          this.lastAuthenticationDate = credential.getLastAuthenticationDate();
75          this.modifiedDate = credential.getModifiedDate();
76          this.principalId = credential.getPrincipalId();
77          this.type = credential.getType();
78          this.updateRequired = credential.isUpdateRequired();
79          this.value = credential.getValue();
80      }
81  
82      private long credentialId;
83  
84      /***
85       * @see org.apache.jetspeed.security.om.InternalCredential#getCredentialId()
86       */
87      public long getCredentialId()
88      {
89          return this.credentialId;
90      }
91  
92      /***
93       * @see org.apache.jetspeed.security.om.InternalCredential#setCredentialId(long)
94       */
95      public void setCredentialId(long credentialId)
96      {
97          this.credentialId = credentialId;
98      }
99  
100     private long principalId;
101 
102     /***
103      * @see org.apache.jetspeed.security.om.InternalCredential#getPrincipalId()
104      */
105     public long getPrincipalId()
106     {
107         return this.principalId;
108     }
109 
110     /***
111      * @see org.apache.jetspeed.security.om.InternalCredential#setPrincipalId(long)
112      */
113     public void setPrincipalId(long principalId)
114     {
115         this.principalId = principalId;
116     }
117 
118     private String value;
119 
120     /***
121      * @see org.apache.jetspeed.security.om.InternalCredential#getValue()
122      */
123     public String getValue()
124     {
125         return this.value;
126     }
127 
128     /***
129      * @see org.apache.jetspeed.security.om.InternalCredential#setValue(java.lang.String)
130      */
131     public void setValue(String value)
132     {
133         this.value = value;
134     }
135     
136     private boolean updateRequired;
137     
138     /***
139      * @see org.apache.jetspeed.security.om.InternalCredential#isUpdateRequired()
140      */
141     public boolean isUpdateRequired()
142     {
143         return updateRequired;
144     }
145     
146     /*
147      * @see org.apache.jetspeed.security.om.InternalCredential#setUpdateRequired(boolean)
148      */
149     public void setUpdateRequired(boolean updateRequired)
150     {
151         this.updateRequired = updateRequired;
152     }
153     
154     private boolean encoded;
155     
156     /*** 
157      * @see org.apache.jetspeed.security.om.InternalCredential#isEncoded()
158      */
159     public boolean isEncoded()
160     {
161         return encoded;
162     }
163     
164     /*** 
165      * @see org.apache.jetspeed.security.om.InternalCredential#setEncoded(boolean)
166      */
167     public void setEncoded(boolean encoded)
168     {
169         this.encoded = encoded;
170     }
171     
172     private boolean enabled = true;
173     
174     /*** 
175      * @see org.apache.jetspeed.security.om.InternalCredential#isEnabled()
176      */
177     public boolean isEnabled()
178     {
179         return enabled;
180     }
181     
182     /*** 
183      * @see org.apache.jetspeed.security.om.InternalCredential#setEnabled(boolean)
184      */
185     public void setEnabled(boolean enabled)
186     {
187         this.enabled = enabled;
188     }
189     
190     private int authenticationFailures;
191     
192     /*** 
193      * @see org.apache.jetspeed.security.om.InternalCredential#getAuthenticationFailures()
194      */
195     public int getAuthenticationFailures()
196     {
197         return authenticationFailures;
198     }
199 
200     /***
201      * @see org.apache.jetspeed.security.om.InternalCredential#setAuthenticationFailures(int)
202      */
203     public void setAuthenticationFailures(int authenticationFailures)
204     {
205         this.authenticationFailures = authenticationFailures;
206     }
207 
208     private boolean expired;
209     
210     /***
211      * @see org.apache.jetspeed.security.om.InternalCredential#isExpired()
212      */
213     public boolean isExpired()
214     {
215         return expired;
216     }
217 
218     /***
219      * @see org.apache.jetspeed.security.om.InternalCredential#setExpired(boolean)
220      */
221     public void setExpired(boolean expired)
222     {
223         this.expired = expired;
224     }
225     
226     private Date expirationDate;
227     
228     /***
229      * @see org.apache.jetspeed.security.om.InternalCredential#getExpirationDate()
230      */
231     public Date getExpirationDate()
232     {
233         return expirationDate;
234     }
235 
236     /***
237      * @see org.apache.jetspeed.security.om.InternalCredential#setExpirationDate(java.sql.Date)
238      */
239     public void setExpirationDate(Date expirationDate)
240     {
241         this.expirationDate = expirationDate;
242     }
243     
244     private int type;
245 
246     /***
247      * @see org.apache.jetspeed.security.om.InternalCredential#getType()
248      */
249     public int getType()
250     {
251         return this.type;
252     }
253 
254     /***
255      * @see org.apache.jetspeed.security.om.InternalCredential#setType(int)
256      */
257     public void setType(int type)
258     {
259         this.type = type;
260     }
261 
262     private String classname;
263 
264     /***
265      * @see org.apache.jetspeed.security.om.InternalCredential#getClassname()
266      */
267     public String getClassname()
268     {
269         return this.classname;
270     }
271 
272     /***
273      * @see org.apache.jetspeed.security.om.InternalCredential#setClassname(java.lang.String)
274      */
275     public void setClassname(String classname)
276     {
277         this.classname = classname;
278     }
279 
280     private Timestamp creationDate;
281 
282     /***
283      * @see org.apache.jetspeed.security.om.InternalCredential#getCreationDate()
284      */
285     public Timestamp getCreationDate()
286     {
287         return this.creationDate;
288     }
289 
290     /***
291      * @see org.apache.jetspeed.security.om.InternalCredential#setCreationDate(java.sql.Timestamp)
292      */
293     public void setCreationDate(Timestamp creationDate)
294     {
295         this.creationDate = creationDate;
296     }
297 
298     private Timestamp modifiedDate;
299 
300     /***
301      * @see org.apache.jetspeed.security.om.InternalCredential#getModifiedDate()
302      */
303     public Timestamp getModifiedDate()
304     {
305         return this.modifiedDate;
306     }
307 
308     /***
309      * @see org.apache.jetspeed.security.om.InternalCredential#setModifiedDate(java.sql.Timestamp)
310      */
311     public void setModifiedDate(Timestamp modifiedDate)
312     {
313         this.modifiedDate = modifiedDate;
314     }
315 
316     private Timestamp previousAuthenticationDate;
317 
318     /***
319      * @see org.apache.jetspeed.security.om.InternalCredential#getPreviousAuthenticationDate()
320      */
321     public Timestamp getPreviousAuthenticationDate()
322     {
323         return previousAuthenticationDate;
324     }
325     
326     /***
327      * @see org.apache.jetspeed.security.om.InternalCredential#setPreviousAuthenticationDate(java.sql.Timestamp)
328      */
329     public void setPreviousAuthenticationDate(Timestamp previousAuthenticationDate)
330     {
331         this.previousAuthenticationDate = previousAuthenticationDate;
332     }
333 
334     private Timestamp lastAuthenticationDate;
335     
336     /***
337      * @see org.apache.jetspeed.security.om.InternalCredential#getLastAuthenticationDate()
338      */
339     public Timestamp getLastAuthenticationDate()
340     {
341         return lastAuthenticationDate;
342     }
343     
344     /***
345      * @see org.apache.jetspeed.security.om.InternalCredential#setLastAuthenticationDate(java.sql.Timestamp)
346      */
347     public void setLastAuthenticationDate(Timestamp lastAuthenticationDate)
348     {
349         this.lastAuthenticationDate = lastAuthenticationDate;
350     }
351     
352     /***
353      * <p>Compares this {@link InternalCredential} to the provided credential
354      * and check if they are equal.</p>
355      * return Whether the {@link InternalCredential} are equal.
356      */
357     public boolean equals(Object object)
358     {  
359         if (!(object instanceof InternalCredential))
360             return false;
361 
362         InternalCredential c = (InternalCredential) object;
363         boolean isEqual = (((null == c.getClassname()) || (c.getClassname().equals(this.getClassname()))) &&
364                             (c.getValue().equals(this.getValue())) && 
365                             (c.getType() == this.getType()));
366         return isEqual;
367     }
368 
369     /***
370      * <p>Convert <code>Node</code> to string.</p>
371      * @return The Node string value.
372      */
373     public String toString()
374     {
375         String toStringCredential = "[[principalId, " + this.principalId + "], "
376             + "[value, " + this.value + "], "
377             + "[updateRequired, " + this.updateRequired + "], "
378             + "[encoded, " + this.encoded + "], "
379             + "[enabled, " + this.enabled + "], "
380             + "[authenticationFailures, "+ this.authenticationFailures + "], "
381             + "[expired, "+ this.expired + "], "
382             + "[type, " + this.type + "], "
383             + "[classname, " + this.classname + "], "
384             + "[creationDate, " + this.creationDate + "], "
385             + "[modifiedDate, " + this.modifiedDate + "], "
386             + "[previousAuthenticationDate, " + this.previousAuthenticationDate + "]"
387             + "[lastAuthenticationDate, " + this.lastAuthenticationDate + "]"
388             + (expirationDate != null ? (", [expirationDate, "+ this.expirationDate + "]]") : "]");
389         return toStringCredential;
390     }    
391 }