001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.ui.web.admin.rainterface;
013:
014: import java.util.Date;
015: import java.util.HashMap;
016:
017: import org.ejbca.core.model.ra.ExtendedInformation;
018: import org.ejbca.core.model.ra.UserDataVO;
019: import org.ejbca.util.StringTools;
020: import org.ejbca.util.dn.DNFieldExtractor;
021:
022: /**
023: * A class representing a web interface view of a user in the ra user database.
024: *
025: * @version $Id: UserView.java,v 1.6 2006/12/02 11:17:57 anatom Exp $
026: */
027: public class UserView implements java.io.Serializable, Cloneable,
028: Comparable {
029: // Public constants.
030:
031: public UserView() {
032: userdata = new UserDataVO();
033: userdata.setType(1);
034: subjectdnfields = new DNFieldExtractor("",
035: DNFieldExtractor.TYPE_SUBJECTDN);
036: subjectaltnames = new DNFieldExtractor("",
037: DNFieldExtractor.TYPE_SUBJECTALTNAME);
038: subjectdirattrs = new DNFieldExtractor("",
039: DNFieldExtractor.TYPE_SUBJECTDIRATTR);
040: }
041:
042: public UserView(UserDataVO newuserdata, HashMap caidtonamemap) {
043: userdata = newuserdata;
044: this .caname = (String) caidtonamemap.get(new Integer(
045: newuserdata.getCAId()));
046: subjectdnfields = new DNFieldExtractor(userdata.getDN(),
047: DNFieldExtractor.TYPE_SUBJECTDN);
048: subjectaltnames = new DNFieldExtractor(userdata
049: .getSubjectAltName(),
050: DNFieldExtractor.TYPE_SUBJECTALTNAME);
051: subjectdirattrs = new DNFieldExtractor(userdata
052: .getExtendedinformation()
053: .getSubjectDirectoryAttributes(),
054: DNFieldExtractor.TYPE_SUBJECTDIRATTR);
055: setCommonName();
056:
057: cleartextpwd = userdata.getPassword() != null;
058: }
059:
060: public void setUsername(String user) {
061: userdata.setUsername(StringTools.strip(user));
062: }
063:
064: public String getUsername() {
065: return userdata.getUsername();
066: }
067:
068: public void setSubjectDN(String dn) {
069: userdata.setDN(dn);
070: subjectdnfields.setDN(dn, DNFieldExtractor.TYPE_SUBJECTDN);
071:
072: setCommonName();
073: }
074:
075: public String getSubjectDN() {
076: return userdata.getDN();
077: }
078:
079: public void setSubjectAltName(String subjectaltname) {
080: userdata.setSubjectAltName(subjectaltname);
081: subjectaltnames.setDN(subjectaltname,
082: DNFieldExtractor.TYPE_SUBJECTALTNAME);
083: }
084:
085: public String getSubjectAltName() {
086: return userdata.getSubjectAltName();
087: }
088:
089: public void setSubjectDirAttributes(String subjectdirattr) {
090: ExtendedInformation ext = userdata.getExtendedinformation();
091: ext.setSubjectDirectoryAttributes(subjectdirattr);
092: userdata.setExtendedinformation(ext);
093: subjectdirattrs.setDN(subjectdirattr,
094: DNFieldExtractor.TYPE_SUBJECTDIRATTR);
095: }
096:
097: public String getSubjectDirAttributes() {
098: return userdata.getExtendedinformation()
099: .getSubjectDirectoryAttributes();
100: }
101:
102: public void setEmail(String email) {
103: userdata.setEmail(email);
104: }
105:
106: public String getEmail() {
107: return userdata.getEmail();
108: }
109:
110: public void setPassword(String pwd) {
111: userdata.setPassword(pwd);
112: }
113:
114: public String getPassword() {
115: return userdata.getPassword();
116: }
117:
118: public boolean getClearTextPassword() {
119: return cleartextpwd;
120: }
121:
122: public void setClearTextPassword(boolean cleartextpwd) {
123: this .cleartextpwd = cleartextpwd;
124: }
125:
126: public void setStatus(int status) {
127: userdata.setStatus(status);
128: }
129:
130: public int getStatus() {
131: return userdata.getStatus();
132: }
133:
134: public void setType(int type) {
135: userdata.setType(type);
136: }
137:
138: public int getType() {
139: return userdata.getType();
140: }
141:
142: public void setAdministrator(boolean admin) {
143: userdata.setAdministrator(admin);
144: }
145:
146: public boolean getAdministrator() {
147: return userdata.getAdministrator();
148: }
149:
150: public void setKeyRecoverable(boolean keyrecoverable) {
151: userdata.setKeyRecoverable(keyrecoverable);
152: }
153:
154: public boolean getKeyRecoverable() {
155: return userdata.getKeyRecoverable();
156: }
157:
158: public void setSendNotification(boolean sendnotification) {
159: userdata.setSendNotification(sendnotification);
160: }
161:
162: public boolean getSendNotification() {
163: return userdata.getSendNotification();
164: }
165:
166: public void setPrintUserData(boolean printUserData) {
167: userdata.setPrintUserData(printUserData);
168: }
169:
170: public boolean getPrintUserData() {
171: return userdata.getPrintUserData();
172: }
173:
174: public void setEndEntityProfileId(int profileid) {
175: userdata.setEndEntityProfileId(profileid);
176: }
177:
178: public int getEndEntityProfileId() {
179: return userdata.getEndEntityProfileId();
180: }
181:
182: public void setCertificateProfileId(int profileid) {
183: userdata.setCertificateProfileId(profileid);
184: }
185:
186: public int getCertificateProfileId() {
187: return userdata.getCertificateProfileId();
188: }
189:
190: public void setTimeCreated(Date timecreated) {
191: userdata.setTimeCreated(timecreated);
192: }
193:
194: public Date getTimeCreated() {
195: return userdata.getTimeCreated();
196: }
197:
198: public void setTimeModified(Date timemodified) {
199: userdata.setTimeModified(timemodified);
200: }
201:
202: public Date getTimeModified() {
203: return userdata.getTimeModified();
204: }
205:
206: public int getTokenType() {
207: return userdata.getTokenType();
208: }
209:
210: public void setTokenType(int tokentype) {
211: userdata.setTokenType(tokentype);
212: }
213:
214: public int getHardTokenIssuerId() {
215: return userdata.getHardTokenIssuerId();
216: }
217:
218: public void setHardTokenIssuerId(int hardtokenissuerid) {
219: userdata.setHardTokenIssuerId(hardtokenissuerid);
220: }
221:
222: public int getCAId() {
223: return userdata.getCAId();
224: }
225:
226: public void setCAId(int caid) {
227: userdata.setCAId(caid);
228: }
229:
230: public String getCAName() {
231: return caname;
232: }
233:
234: public void setExtendedInformation(ExtendedInformation extinfo) {
235: userdata.setExtendedinformation(extinfo);
236: }
237:
238: public ExtendedInformation getExtendedInformation() {
239: return userdata.getExtendedinformation();
240: }
241:
242: public String getSubjectDNField(int parameter, int number) {
243: return subjectdnfields.getField(parameter, number);
244: }
245:
246: public String getSubjectAltNameField(int parameter, int number) {
247: return subjectaltnames.getField(parameter, number);
248: }
249:
250: public String getSubjectDirAttributeField(int parameter, int number) {
251: return subjectdirattrs.getField(parameter, number);
252: }
253:
254: /**
255: * getCommonName is a special function used in list end entity gui to display names in cases not a CN field exists in dn only, surname and givennamn
256: */
257: public String getCommonName() {
258: return commonname;
259: }
260:
261: private void setCommonName() {
262: commonname = getSubjectDNField(DNFieldExtractor.CN, 0);
263: if (commonname.equals("")) {
264: commonname = getSubjectDNField(DNFieldExtractor.GIVENNAME,
265: 0)
266: + " "
267: + getSubjectDNField(DNFieldExtractor.SURNAME, 0);
268: }
269: }
270:
271: public int compareTo(Object obj) {
272: int returnvalue = -1;
273: int sortby = this .sortby.getSortBy();
274: switch (sortby) {
275: case SortBy.USERNAME:
276: returnvalue = getUsername().compareTo(
277: ((UserView) obj).getUsername());
278: break;
279: case SortBy.COMMONNAME:
280: returnvalue = this .commonname.compareTo(((UserView) obj)
281: .getCommonName());
282: break;
283: case SortBy.SERIALNUMBER:
284: returnvalue = getSubjectDNField(DNFieldExtractor.SN, 0)
285: .compareTo(
286: ((UserView) obj).getSubjectDNField(
287: DNFieldExtractor.SN, 0));
288: break;
289: case SortBy.TITLE:
290: returnvalue = getSubjectDNField(DNFieldExtractor.T, 0)
291: .compareTo(
292: ((UserView) obj).getSubjectDNField(
293: DNFieldExtractor.T, 0));
294: break;
295: case SortBy.ORGANIZATIONUNIT:
296: returnvalue = getSubjectDNField(DNFieldExtractor.OU, 0)
297: .compareTo(
298: ((UserView) obj).getSubjectDNField(
299: DNFieldExtractor.OU, 0));
300: break;
301: case SortBy.ORGANIZATION:
302: returnvalue = getSubjectDNField(DNFieldExtractor.O, 0)
303: .compareTo(
304: ((UserView) obj).getSubjectDNField(
305: DNFieldExtractor.O, 0));
306: break;
307: case SortBy.LOCALE:
308: returnvalue = getSubjectDNField(DNFieldExtractor.L, 0)
309: .compareTo(
310: ((UserView) obj).getSubjectDNField(
311: DNFieldExtractor.L, 0));
312: break;
313: case SortBy.STATE:
314: returnvalue = getSubjectDNField(DNFieldExtractor.ST, 0)
315: .compareTo(
316: ((UserView) obj).getSubjectDNField(
317: DNFieldExtractor.ST, 0));
318: break;
319: case SortBy.DOMAINCOMPONENT:
320: returnvalue = getSubjectDNField(DNFieldExtractor.DC, 0)
321: .compareTo(
322: ((UserView) obj).getSubjectDNField(
323: DNFieldExtractor.DC, 0));
324: break;
325: case SortBy.COUNTRY:
326: returnvalue = getSubjectDNField(DNFieldExtractor.C, 0)
327: .compareTo(
328: ((UserView) obj).getSubjectDNField(
329: DNFieldExtractor.C, 0));
330: break;
331: case SortBy.EMAIL:
332: returnvalue = getEmail().compareTo(
333: ((UserView) obj).getEmail());
334: break;
335: case SortBy.STATUS:
336: returnvalue = (new Integer(getStatus()))
337: .compareTo(new Integer(((UserView) obj).getStatus()));
338: break;
339: case SortBy.TIMECREATED:
340: returnvalue = getTimeCreated().compareTo(
341: ((UserView) obj).getTimeCreated());
342: break;
343: case SortBy.TIMEMODIFIED:
344: returnvalue = getTimeModified().compareTo(
345: ((UserView) obj).getTimeModified());
346: break;
347: case SortBy.CA:
348: returnvalue = getCAName().compareTo(
349: ((UserView) obj).getCAName());
350: break;
351: default:
352: returnvalue = getUsername().compareTo(
353: ((UserView) obj).getUsername());
354:
355: }
356: if (this .sortby.getSortOrder() == SortBy.DECENDING)
357: returnvalue = 0 - returnvalue;
358:
359: return returnvalue;
360: }
361:
362: public void setSortBy(SortBy sortby) {
363: this .sortby = sortby;
364: }
365:
366: // Private constants.
367:
368: // Private methods.
369: private SortBy sortby;
370: private UserDataVO userdata;
371: private DNFieldExtractor subjectdnfields;
372: private DNFieldExtractor subjectaltnames;
373: private DNFieldExtractor subjectdirattrs;
374: private String commonname = "";
375: private String caname;
376: private boolean cleartextpwd;
377: }
|