View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/server/src/java/org/astrogrid/community/server/security/data/PasswordData.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/06/18 13:45:20 $</cvs:date>
5    * <cvs:version>$Revision: 1.3 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: PasswordData.java,v $
9    *   Revision 1.3  2004/06/18 13:45:20  dave
10   *   Merged development branch, dave-dev-200406081614, into HEAD
11   *
12   *   Revision 1.2.54.1  2004/06/17 13:38:59  dave
13   *   Tidied up old CVS log entries
14   *
15   * </cvs:log>
16   *
17   */
18  package org.astrogrid.community.server.security.data ;
19  
20  public class PasswordData
21      {
22      /***
23       * No encryption, clear text password.
24       * This is the default at the moment.
25       *
26       */
27      public static final String NO_ENCRYPTION = "CLEAR_TEXT" ;
28  
29      /***
30       * Public constructor.
31       *
32       */
33      public PasswordData()
34          {
35          this(null, null) ;
36          }
37  
38      /***
39       * Public constructor.
40       *
41       */
42      public PasswordData(String account, String password)
43          {
44          this.setAccount(account) ;
45          this.setPassword(password) ;
46          this.setEncryption(NO_ENCRYPTION) ;
47          }
48  
49      /***
50       * Our Account identifier.
51       *
52       */
53      private String account ;
54  
55      /***
56       * Access to our Account identifier.
57       *
58       */
59      public String getAccount()
60          {
61          return this.account ;
62          }
63  
64      /***
65       * Access to our Account identifier.
66       *
67       */
68      public void setAccount(String value)
69          {
70          this.account = value ;
71          }
72  
73      /***
74       * Our Account password.
75       *
76       */
77      private String password ;
78  
79      /***
80       * Access to our Account password.
81       *
82       */
83      public String getPassword()
84          {
85          return this.password ;
86          }
87  
88      /***
89       * Access to our Account password.
90       *
91       */
92      public void setPassword(String value)
93          {
94          this.password = value ;
95          }
96  
97      /***
98       * Our Account encryption.
99       *
100      */
101     private String encryption ;
102 
103     /***
104      * Access to our Account encryption.
105      *
106      */
107     public String getEncryption()
108         {
109         return this.encryption ;
110         }
111 
112     /***
113      * Access to our Account encryption.
114      *
115      */
116     public void setEncryption(String value)
117         {
118         this.encryption = value ;
119         }
120 
121     /*
122      * Compare this with another PasswordData.
123      * This checks both the the Account identifier and password.
124      *
125      */
126     public synchronized boolean equals(Object object)
127         {
128         //
129         // If the object is null.
130         if (null == object)
131             {
132             return false ;
133             }
134         //
135         // If the object is not null.
136         else {
137             //
138             // If the object is a PasswordData
139             if (object instanceof PasswordData)
140                 {
141                 PasswordData that = (PasswordData) object ;
142                 //
143                 // If our account identifier is null
144                 if (null == this.getAccount())
145                     {
146                     //
147                     // Check that account identifier is null.
148                     return (null == that.getAccount()) ;
149                     }
150                 //
151                 // If our account identifier is not null.
152                 else {
153                     //
154                     // Check both the account identifier and password are the same.
155                     return (
156                         this.getAccount().equals(that.getAccount())
157                         &&
158                         this.getPassword().equals(that.getPassword())
159                         ) ;
160                     }
161                 }
162             //
163             // If object is not a PasswordData
164             else {
165                 return false ;
166                 }
167             }
168         }
169 
170     /***
171      * Generate a hash code for comparison tests.
172      * This combines the hash code for both identifier and password.
173      *
174      */
175     public synchronized int hashCode()
176         {
177         int result = 0 ;
178         //
179         // If we have a valid account.
180         if (null != this.getAccount())
181             {
182             result += this.getAccount().hashCode() ;
183             }
184         //
185         // If we have a valid password.
186         if (null != this.getPassword())
187             {
188             result += this.getPassword().hashCode() ;
189             }
190         return result ;
191         }
192     }