1 13 14 package org.ejbca.ui.web.admin.rainterface; 15 16 import java.util.Date ; 17 import java.util.HashMap ; 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 32 public class UserView implements java.io.Serializable , Cloneable , Comparable { 33 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 caidtonamemap){ 45 userdata = newuserdata; 46 this.caname = (String ) caidtonamemap.get(new Integer (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 user) { userdata.setUsername(StringTools.strip(user));} 56 public String getUsername() {return userdata.getUsername();} 57 58 public void setSubjectDN(String dn) { 59 userdata.setDN(dn); 60 subjectdnfields.setDN(dn, DNFieldExtractor.TYPE_SUBJECTDN); 61 62 setCommonName(); 63 } 64 public String getSubjectDN() {return userdata.getDN();} 65 66 public void setSubjectAltName( String subjectaltname) { 67 userdata.setSubjectAltName(subjectaltname); 68 subjectaltnames.setDN(subjectaltname, DNFieldExtractor.TYPE_SUBJECTALTNAME); 69 } 70 public String getSubjectAltName() {return userdata.getSubjectAltName();} 71 72 public void setSubjectDirAttributes( String 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 getSubjectDirAttributes() {return userdata.getExtendedinformation().getSubjectDirectoryAttributes();} 79 80 public void setEmail(String email) { userdata.setEmail(email);} 81 public String getEmail() {return userdata.getEmail();} 82 83 public void setPassword(String pwd) {userdata.setPassword(pwd);} 84 public String 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 timecreated) { userdata.setTimeCreated(timecreated); } 106 public Date getTimeCreated() {return userdata.getTimeCreated();} 107 public void setTimeModified(Date timemodified) { userdata.setTimeModified(timemodified); } 108 public Date 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 getCAName() { return caname;} 116 public void setExtendedInformation(ExtendedInformation extinfo) { userdata.setExtendedinformation(extinfo);} 117 public ExtendedInformation getExtendedInformation() { return userdata.getExtendedinformation();} 118 119 public String getSubjectDNField(int parameter, int number){ 120 return subjectdnfields.getField(parameter,number); 121 } 122 123 public String getSubjectAltNameField(int parameter, int number){ 124 return subjectaltnames.getField(parameter,number); 125 } 126 127 public String getSubjectDirAttributeField(int parameter, int number){ 128 return subjectdirattrs.getField(parameter,number); 129 } 130 133 public String 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 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 (getStatus())).compareTo(new Integer (((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 209 private SortBy sortby; 211 private UserDataVO userdata; 212 private DNFieldExtractor subjectdnfields; 213 private DNFieldExtractor subjectaltnames; 214 private DNFieldExtractor subjectdirattrs; 215 private String commonname = ""; 216 private String caname; 217 private boolean cleartextpwd; 218 } 219 | Popular Tags |