KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > rainterface > UserView


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 package org.ejbca.ui.web.admin.rainterface;
15
16 import java.util.Date JavaDoc;
17 import java.util.HashMap JavaDoc;
18
19 import org.ejbca.core.model.ra.ExtendedInformation;
20 import org.ejbca.core.model.ra.UserDataVO;
21 import org.ejbca.util.StringTools;
22 import org.ejbca.util.dn.DNFieldExtractor;
23
24
25
26
27 /**
28  * A class representing a web interface view of a user in the ra user database.
29  *
30  * @version $Id: UserView.java,v 1.6 2006/12/02 11:17:57 anatom Exp $
31  */

32 public class UserView implements java.io.Serializable JavaDoc, Cloneable JavaDoc, Comparable JavaDoc {
33     // Public constants.
34

35    public UserView(){
36       userdata = new UserDataVO();
37       userdata.setType(1);
38       subjectdnfields = new DNFieldExtractor("", DNFieldExtractor.TYPE_SUBJECTDN);
39       subjectaltnames = new DNFieldExtractor("", DNFieldExtractor.TYPE_SUBJECTALTNAME);
40       subjectdirattrs = new DNFieldExtractor("", DNFieldExtractor.TYPE_SUBJECTDIRATTR);
41    }
42
43
44     public UserView(UserDataVO newuserdata, HashMap JavaDoc caidtonamemap){
45       userdata = newuserdata;
46       this.caname = (String JavaDoc) caidtonamemap.get(new Integer JavaDoc(newuserdata.getCAId()));
47       subjectdnfields = new DNFieldExtractor(userdata.getDN(), DNFieldExtractor.TYPE_SUBJECTDN);
48       subjectaltnames = new DNFieldExtractor(userdata.getSubjectAltName(), DNFieldExtractor.TYPE_SUBJECTALTNAME);
49       subjectdirattrs = new DNFieldExtractor(userdata.getExtendedinformation().getSubjectDirectoryAttributes(), DNFieldExtractor.TYPE_SUBJECTDIRATTR);
50       setCommonName();
51
52       cleartextpwd = userdata.getPassword() != null;
53     }
54
55     public void setUsername(String JavaDoc user) { userdata.setUsername(StringTools.strip(user));}
56     public String JavaDoc getUsername() {return userdata.getUsername();}
57
58     public void setSubjectDN(String JavaDoc dn) {
59       userdata.setDN(dn);
60       subjectdnfields.setDN(dn, DNFieldExtractor.TYPE_SUBJECTDN);
61       
62       setCommonName();
63     }
64     public String JavaDoc getSubjectDN() {return userdata.getDN();}
65
66     public void setSubjectAltName( String JavaDoc subjectaltname) {
67       userdata.setSubjectAltName(subjectaltname);
68       subjectaltnames.setDN(subjectaltname, DNFieldExtractor.TYPE_SUBJECTALTNAME);
69     }
70     public String JavaDoc getSubjectAltName() {return userdata.getSubjectAltName();}
71
72     public void setSubjectDirAttributes( String JavaDoc subjectdirattr) {
73         ExtendedInformation ext = userdata.getExtendedinformation();
74         ext.setSubjectDirectoryAttributes(subjectdirattr);
75         userdata.setExtendedinformation(ext);
76         subjectdirattrs.setDN(subjectdirattr, DNFieldExtractor.TYPE_SUBJECTDIRATTR);
77       }
78       public String JavaDoc getSubjectDirAttributes() {return userdata.getExtendedinformation().getSubjectDirectoryAttributes();}
79
80     public void setEmail(String JavaDoc email) { userdata.setEmail(email);}
81     public String JavaDoc getEmail() {return userdata.getEmail();}
82
83     public void setPassword(String JavaDoc pwd) {userdata.setPassword(pwd);}
84     public String JavaDoc getPassword() {return userdata.getPassword();}
85
86     public boolean getClearTextPassword(){ return cleartextpwd;}
87     public void setClearTextPassword(boolean cleartextpwd){ this.cleartextpwd=cleartextpwd;}
88
89     public void setStatus(int status) {userdata.setStatus(status);}
90     public int getStatus() {return userdata.getStatus();}
91     public void setType(int type) {userdata.setType(type);}
92     public int getType() {return userdata.getType();}
93     public void setAdministrator(boolean admin) {userdata.setAdministrator(admin);}
94     public boolean getAdministrator() {return userdata.getAdministrator();}
95     public void setKeyRecoverable(boolean keyrecoverable) {userdata.setKeyRecoverable(keyrecoverable);}
96     public boolean getKeyRecoverable() {return userdata.getKeyRecoverable();}
97     public void setSendNotification(boolean sendnotification) {userdata.setSendNotification(sendnotification);}
98     public boolean getSendNotification() {return userdata.getSendNotification();}
99     public void setPrintUserData(boolean printUserData) {userdata.setPrintUserData(printUserData);}
100     public boolean getPrintUserData() {return userdata.getPrintUserData();}
101     public void setEndEntityProfileId(int profileid) { userdata.setEndEntityProfileId(profileid); }
102     public int getEndEntityProfileId(){ return userdata.getEndEntityProfileId(); }
103     public void setCertificateProfileId(int profileid) { userdata.setCertificateProfileId(profileid); }
104     public int getCertificateProfileId() {return userdata.getCertificateProfileId();}
105     public void setTimeCreated(Date JavaDoc timecreated) { userdata.setTimeCreated(timecreated); }
106     public Date JavaDoc getTimeCreated() {return userdata.getTimeCreated();}
107     public void setTimeModified(Date JavaDoc timemodified) { userdata.setTimeModified(timemodified); }
108     public Date JavaDoc getTimeModified() {return userdata.getTimeModified();}
109     public int getTokenType(){ return userdata.getTokenType();}
110     public void setTokenType(int tokentype) {userdata.setTokenType(tokentype);}
111     public int getHardTokenIssuerId() {return userdata.getHardTokenIssuerId();}
112     public void setHardTokenIssuerId(int hardtokenissuerid) { userdata.setHardTokenIssuerId(hardtokenissuerid);}
113     public int getCAId() {return userdata.getCAId();}
114     public void setCAId(int caid) { userdata.setCAId(caid);}
115     public String JavaDoc getCAName() { return caname;}
116     public void setExtendedInformation(ExtendedInformation extinfo) { userdata.setExtendedinformation(extinfo);}
117     public ExtendedInformation getExtendedInformation() { return userdata.getExtendedinformation();}
118     
119     public String JavaDoc getSubjectDNField(int parameter, int number){
120       return subjectdnfields.getField(parameter,number);
121     }
122
123     public String JavaDoc getSubjectAltNameField(int parameter, int number){
124       return subjectaltnames.getField(parameter,number);
125     }
126     
127     public String JavaDoc getSubjectDirAttributeField(int parameter, int number){
128         return subjectdirattrs.getField(parameter,number);
129       }
130     /**
131      * 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
132      */

133     public String JavaDoc getCommonName(){
134       return commonname;
135     }
136     
137     private void setCommonName(){
138         commonname = getSubjectDNField(DNFieldExtractor.CN,0);
139         if(commonname.equals("")){
140           commonname = getSubjectDNField(DNFieldExtractor.GIVENNAME,0) + " " + getSubjectDNField(DNFieldExtractor.SURNAME,0);
141         }
142     }
143
144     public int compareTo(Object JavaDoc obj) {
145       int returnvalue = -1;
146       int sortby = this.sortby.getSortBy();
147       switch(sortby){
148           case SortBy.USERNAME :
149             returnvalue = getUsername().compareTo(((UserView) obj).getUsername());
150             break;
151           case SortBy.COMMONNAME :
152             returnvalue = this.commonname.compareTo(((UserView) obj).getCommonName());
153             break;
154           case SortBy.SERIALNUMBER :
155             returnvalue = getSubjectDNField(DNFieldExtractor.SN,0).compareTo(((UserView) obj).getSubjectDNField(DNFieldExtractor.SN,0));
156             break;
157           case SortBy.TITLE :
158             returnvalue = getSubjectDNField(DNFieldExtractor.T,0).compareTo(((UserView) obj).getSubjectDNField(DNFieldExtractor.T,0));
159             break;
160           case SortBy.ORGANIZATIONUNIT :
161             returnvalue = getSubjectDNField(DNFieldExtractor.OU,0).compareTo(((UserView) obj).getSubjectDNField(DNFieldExtractor.OU,0));
162             break;
163           case SortBy.ORGANIZATION :
164             returnvalue = getSubjectDNField(DNFieldExtractor.O,0).compareTo(((UserView) obj).getSubjectDNField(DNFieldExtractor.O,0));
165             break;
166           case SortBy.LOCALE :
167             returnvalue = getSubjectDNField(DNFieldExtractor.L,0).compareTo(((UserView) obj).getSubjectDNField(DNFieldExtractor.L,0));
168             break;
169           case SortBy.STATE :
170             returnvalue = getSubjectDNField(DNFieldExtractor.ST,0).compareTo(((UserView) obj).getSubjectDNField(DNFieldExtractor.ST,0));
171             break;
172           case SortBy.DOMAINCOMPONENT :
173             returnvalue = getSubjectDNField(DNFieldExtractor.DC,0).compareTo(((UserView) obj).getSubjectDNField(DNFieldExtractor.DC,0));
174             break;
175           case SortBy.COUNTRY :
176             returnvalue = getSubjectDNField(DNFieldExtractor.C,0).compareTo(((UserView) obj).getSubjectDNField(DNFieldExtractor.C,0));
177             break;
178           case SortBy.EMAIL :
179             returnvalue = getEmail().compareTo(((UserView) obj).getEmail());
180             break;
181           case SortBy.STATUS :
182             returnvalue = (new Integer JavaDoc(getStatus())).compareTo(new Integer JavaDoc(((UserView) obj).getStatus()));
183             break;
184           case SortBy.TIMECREATED :
185             returnvalue = getTimeCreated().compareTo(((UserView) obj).getTimeCreated());
186             break;
187           case SortBy.TIMEMODIFIED :
188             returnvalue = getTimeModified().compareTo(((UserView) obj).getTimeModified());
189             break;
190           case SortBy.CA :
191             returnvalue = getCAName().compareTo(((UserView) obj).getCAName());
192             break;
193           default:
194             returnvalue = getUsername().compareTo(((UserView) obj).getUsername());
195
196       }
197       if(this.sortby.getSortOrder() == SortBy.DECENDING)
198         returnvalue = 0-returnvalue;
199
200       return returnvalue;
201     }
202
203     public void setSortBy(SortBy sortby){
204       this.sortby=sortby;
205     }
206
207     // Private constants.
208

209     // Private methods.
210
private SortBy sortby;
211     private UserDataVO userdata;
212     private DNFieldExtractor subjectdnfields;
213     private DNFieldExtractor subjectaltnames;
214     private DNFieldExtractor subjectdirattrs;
215     private String JavaDoc commonname = "";
216     private String JavaDoc caname;
217     private boolean cleartextpwd;
218 }
219
Popular Tags