001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security.om.impl;
018:
019: import java.sql.Date;
020: import java.sql.Timestamp;
021:
022: import org.apache.jetspeed.security.om.InternalCredential;
023:
024: /**
025: * <p>{@link InternalCredential} interface implementation.</p>
026: *
027: * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
028: * @version $Id: InternalCredentialImpl.java 516448 2007-03-09 16:25:47Z ate $
029: */
030: public class InternalCredentialImpl implements InternalCredential {
031: /** The serial version uid. */
032: private static final long serialVersionUID = -8064404995292602590L;
033:
034: /**
035: * <p>InternalCredential implementation default constructor.</p>
036: */
037: public InternalCredentialImpl() {
038: }
039:
040: /**
041: * <p>InternalCredentialImpl constructor given a value, type and classname.</p>
042: * @param principalId The principal id.
043: * @param value The value.
044: * @param type The type.
045: * @param classname The classname.
046: */
047: public InternalCredentialImpl(long principalId, String value,
048: int type, String classname) {
049: this .principalId = principalId;
050: this .value = value;
051: this .type = type;
052: this .classname = classname;
053: this .creationDate = new Timestamp(new java.util.Date()
054: .getTime());
055: this .modifiedDate = this .creationDate;
056: }
057:
058: /**
059: * <p>InternalCredentialImpl copy constructor given another InternalCredential and overriding classname</p>
060: * @param credential The credential to copy from
061: * @param classname The classname for the new credential
062: */
063: public InternalCredentialImpl(InternalCredential credential,
064: String classname) {
065: this .authenticationFailures = credential
066: .getAuthenticationFailures();
067: this .classname = classname;
068: this .creationDate = credential.getCreationDate();
069: this .enabled = credential.isEnabled();
070: this .encoded = credential.isEncoded();
071: this .expirationDate = credential.getExpirationDate();
072: this .expired = credential.isExpired();
073: this .previousAuthenticationDate = credential
074: .getPreviousAuthenticationDate();
075: this .lastAuthenticationDate = credential
076: .getLastAuthenticationDate();
077: this .modifiedDate = credential.getModifiedDate();
078: this .principalId = credential.getPrincipalId();
079: this .type = credential.getType();
080: this .updateRequired = credential.isUpdateRequired();
081: this .value = credential.getValue();
082: }
083:
084: private long credentialId;
085:
086: /**
087: * @see org.apache.jetspeed.security.om.InternalCredential#getCredentialId()
088: */
089: public long getCredentialId() {
090: return this .credentialId;
091: }
092:
093: /**
094: * @see org.apache.jetspeed.security.om.InternalCredential#setCredentialId(long)
095: */
096: public void setCredentialId(long credentialId) {
097: this .credentialId = credentialId;
098: }
099:
100: private long principalId;
101:
102: /**
103: * @see org.apache.jetspeed.security.om.InternalCredential#getPrincipalId()
104: */
105: public long getPrincipalId() {
106: return this .principalId;
107: }
108:
109: /**
110: * @see org.apache.jetspeed.security.om.InternalCredential#setPrincipalId(long)
111: */
112: public void setPrincipalId(long principalId) {
113: this .principalId = principalId;
114: }
115:
116: private String value;
117:
118: /**
119: * @see org.apache.jetspeed.security.om.InternalCredential#getValue()
120: */
121: public String getValue() {
122: return this .value;
123: }
124:
125: /**
126: * @see org.apache.jetspeed.security.om.InternalCredential#setValue(java.lang.String)
127: */
128: public void setValue(String value) {
129: this .value = value;
130: }
131:
132: private boolean updateRequired;
133:
134: /**
135: * @see org.apache.jetspeed.security.om.InternalCredential#isUpdateRequired()
136: */
137: public boolean isUpdateRequired() {
138: return updateRequired;
139: }
140:
141: /*
142: * @see org.apache.jetspeed.security.om.InternalCredential#setUpdateRequired(boolean)
143: */
144: public void setUpdateRequired(boolean updateRequired) {
145: this .updateRequired = updateRequired;
146: }
147:
148: private boolean encoded;
149:
150: /**
151: * @see org.apache.jetspeed.security.om.InternalCredential#isEncoded()
152: */
153: public boolean isEncoded() {
154: return encoded;
155: }
156:
157: /**
158: * @see org.apache.jetspeed.security.om.InternalCredential#setEncoded(boolean)
159: */
160: public void setEncoded(boolean encoded) {
161: this .encoded = encoded;
162: }
163:
164: private boolean enabled = true;
165:
166: /**
167: * @see org.apache.jetspeed.security.om.InternalCredential#isEnabled()
168: */
169: public boolean isEnabled() {
170: return enabled;
171: }
172:
173: /**
174: * @see org.apache.jetspeed.security.om.InternalCredential#setEnabled(boolean)
175: */
176: public void setEnabled(boolean enabled) {
177: this .enabled = enabled;
178: }
179:
180: private int authenticationFailures;
181:
182: /**
183: * @see org.apache.jetspeed.security.om.InternalCredential#getAuthenticationFailures()
184: */
185: public int getAuthenticationFailures() {
186: return authenticationFailures;
187: }
188:
189: /**
190: * @see org.apache.jetspeed.security.om.InternalCredential#setAuthenticationFailures(int)
191: */
192: public void setAuthenticationFailures(int authenticationFailures) {
193: this .authenticationFailures = authenticationFailures;
194: }
195:
196: private boolean expired;
197:
198: /**
199: * @see org.apache.jetspeed.security.om.InternalCredential#isExpired()
200: */
201: public boolean isExpired() {
202: return expired;
203: }
204:
205: /**
206: * @see org.apache.jetspeed.security.om.InternalCredential#setExpired(boolean)
207: */
208: public void setExpired(boolean expired) {
209: this .expired = expired;
210: }
211:
212: private Date expirationDate;
213:
214: /**
215: * @see org.apache.jetspeed.security.om.InternalCredential#getExpirationDate()
216: */
217: public Date getExpirationDate() {
218: return expirationDate;
219: }
220:
221: /**
222: * @see org.apache.jetspeed.security.om.InternalCredential#setExpirationDate(java.sql.Date)
223: */
224: public void setExpirationDate(Date expirationDate) {
225: this .expirationDate = expirationDate;
226: }
227:
228: private int type;
229:
230: /**
231: * @see org.apache.jetspeed.security.om.InternalCredential#getType()
232: */
233: public int getType() {
234: return this .type;
235: }
236:
237: /**
238: * @see org.apache.jetspeed.security.om.InternalCredential#setType(int)
239: */
240: public void setType(int type) {
241: this .type = type;
242: }
243:
244: private String classname;
245:
246: /**
247: * @see org.apache.jetspeed.security.om.InternalCredential#getClassname()
248: */
249: public String getClassname() {
250: return this .classname;
251: }
252:
253: /**
254: * @see org.apache.jetspeed.security.om.InternalCredential#setClassname(java.lang.String)
255: */
256: public void setClassname(String classname) {
257: this .classname = classname;
258: }
259:
260: private Timestamp creationDate;
261:
262: /**
263: * @see org.apache.jetspeed.security.om.InternalCredential#getCreationDate()
264: */
265: public Timestamp getCreationDate() {
266: return this .creationDate;
267: }
268:
269: /**
270: * @see org.apache.jetspeed.security.om.InternalCredential#setCreationDate(java.sql.Timestamp)
271: */
272: public void setCreationDate(Timestamp creationDate) {
273: this .creationDate = creationDate;
274: }
275:
276: private Timestamp modifiedDate;
277:
278: /**
279: * @see org.apache.jetspeed.security.om.InternalCredential#getModifiedDate()
280: */
281: public Timestamp getModifiedDate() {
282: return this .modifiedDate;
283: }
284:
285: /**
286: * @see org.apache.jetspeed.security.om.InternalCredential#setModifiedDate(java.sql.Timestamp)
287: */
288: public void setModifiedDate(Timestamp modifiedDate) {
289: this .modifiedDate = modifiedDate;
290: }
291:
292: private Timestamp previousAuthenticationDate;
293:
294: /**
295: * @see org.apache.jetspeed.security.om.InternalCredential#getPreviousAuthenticationDate()
296: */
297: public Timestamp getPreviousAuthenticationDate() {
298: return previousAuthenticationDate;
299: }
300:
301: /**
302: * @see org.apache.jetspeed.security.om.InternalCredential#setPreviousAuthenticationDate(java.sql.Timestamp)
303: */
304: public void setPreviousAuthenticationDate(
305: Timestamp previousAuthenticationDate) {
306: this .previousAuthenticationDate = previousAuthenticationDate;
307: }
308:
309: private Timestamp lastAuthenticationDate;
310:
311: /**
312: * @see org.apache.jetspeed.security.om.InternalCredential#getLastAuthenticationDate()
313: */
314: public Timestamp getLastAuthenticationDate() {
315: return lastAuthenticationDate;
316: }
317:
318: /**
319: * @see org.apache.jetspeed.security.om.InternalCredential#setLastAuthenticationDate(java.sql.Timestamp)
320: */
321: public void setLastAuthenticationDate(
322: Timestamp lastAuthenticationDate) {
323: this .lastAuthenticationDate = lastAuthenticationDate;
324: }
325:
326: /**
327: * <p>Compares this {@link InternalCredential} to the provided credential
328: * and check if they are equal.</p>
329: * return Whether the {@link InternalCredential} are equal.
330: */
331: public boolean equals(Object object) {
332: if (!(object instanceof InternalCredential))
333: return false;
334:
335: InternalCredential c = (InternalCredential) object;
336: boolean isEqual = (((null == c.getClassname()) || (c
337: .getClassname().equals(this .getClassname())))
338: && (c.getValue().equals(this .getValue())) && (c
339: .getType() == this .getType()));
340: return isEqual;
341: }
342:
343: /**
344: * <p>Convert <code>Node</code> to string.</p>
345: * @return The Node string value.
346: */
347: public String toString() {
348: String toStringCredential = "[[principalId, "
349: + this .principalId
350: + "], "
351: + "[value, "
352: + this .value
353: + "], "
354: + "[updateRequired, "
355: + this .updateRequired
356: + "], "
357: + "[encoded, "
358: + this .encoded
359: + "], "
360: + "[enabled, "
361: + this .enabled
362: + "], "
363: + "[authenticationFailures, "
364: + this .authenticationFailures
365: + "], "
366: + "[expired, "
367: + this .expired
368: + "], "
369: + "[type, "
370: + this .type
371: + "], "
372: + "[classname, "
373: + this .classname
374: + "], "
375: + "[creationDate, "
376: + this .creationDate
377: + "], "
378: + "[modifiedDate, "
379: + this .modifiedDate
380: + "], "
381: + "[previousAuthenticationDate, "
382: + this .previousAuthenticationDate
383: + "]"
384: + "[lastAuthenticationDate, "
385: + this .lastAuthenticationDate
386: + "]"
387: + (expirationDate != null ? (", [expirationDate, "
388: + this .expirationDate + "]]") : "]");
389: return toStringCredential;
390: }
391: }
|