1 13 14 package org.ejbca.ui.web.admin.loginterface; 15 16 import java.util.Date ; 17 import java.util.HashMap ; 18 import java.text.DateFormat ; 19 import java.rmi.RemoteException ; 20 21 import org.ejbca.core.model.log.Admin; 22 import org.ejbca.core.model.log.LogEntry; 23 import org.ejbca.ui.web.admin.rainterface.SortBy; 24 import org.ejbca.util.dn.DNFieldExtractor; 25 26 32 public class LogEntryView implements java.io.Serializable , Cloneable , Comparable { 33 public static final int TIME = 0; 35 public static final int ADMINTYPE = 1; 36 public static final int ADMINDATA = 2; 37 public static final int ADMINCERTSERNO = 3; 38 public static final int CA = 4; 39 public static final int MODULE = 5; 40 public static final int USERNAME = 6; 41 public static final int CERTIFICATE = 7; 42 public static final int CERTIFICATESERNO = 8; 43 public static final int EVENT = 9; 44 public static final int COMMENT = 10; 45 public static final int VERIFY = 11; 46 47 public static final String TRUE = "T"; 48 public static final String FALSE = "F"; 49 50 public static final int NUMBEROF_FIELDS=12; 51 52 53 54 public LogEntryView(SubjectDNProxy dnproxy) { 55 logentrydata = new String [NUMBEROF_FIELDS]; 56 for(int i=0; i< NUMBEROF_FIELDS ; i++){ 57 logentrydata[i] = ""; 58 } 59 this.dnproxy = dnproxy; 60 } 61 62 public LogEntryView(LogEntry logentry, SubjectDNProxy dnproxy, String [] localinfoeventnames, String [] localerroreventnames, String [] localmodulenames, HashMap caidtonamemap) throws RemoteException { 63 logentrydata = new String [NUMBEROF_FIELDS]; 64 for(int i=0; i< NUMBEROF_FIELDS ; i++){ 65 logentrydata[i] = ""; 66 } 67 this.dnproxy = dnproxy; 68 setValues(logentry,localinfoeventnames,localerroreventnames, localmodulenames, caidtonamemap); 69 } 70 71 72 74 public String getValue(int parameter){ 75 return logentrydata[parameter]; 76 } 77 78 79 public void setValue(int parameter, String value){ 80 logentrydata[parameter]=value; 81 } 82 83 84 public String [] getValues(){ 85 return logentrydata; 86 } 87 88 89 public void setValues(LogEntry logentry, String [] localinfoeventnames, String [] localerroreventnames,String [] localmodulenames, HashMap caidtonamemap) throws RemoteException { 90 91 logentrydata[TIME] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(logentry.getTime()); 92 this.time = logentry.getTime(); 93 94 logentrydata[ADMINTYPE] = Integer.toString(logentry.getAdminType()); 95 if(logentry.getAdminType() == Admin.TYPE_CLIENTCERT_USER){ 96 String dnstring = dnproxy.getSubjectDN(logentry.getAdminData()); 97 if(dnstring !=null){ 98 DNFieldExtractor dn = new DNFieldExtractor(dnstring, DNFieldExtractor.TYPE_SUBJECTDN); 99 logentrydata[ADMINCERTSERNO] = logentry.getAdminData(); 100 logentrydata[ADMINDATA] = dn.getField(DNFieldExtractor.CN,0) + ", " + dn.getField(DNFieldExtractor.O,0); 101 } 102 }else{ 103 if(logentry.getAdminType() == Admin.TYPE_PUBLIC_WEB_USER){ 104 if(logentry.getAdminData() != null) 105 logentrydata[ADMINDATA] = "IP : " + logentry.getAdminData(); 106 if(logentrydata[ADMINDATA] == null) 107 logentrydata[ADMINDATA] = ""; 108 }else{ 109 if(logentry.getAdminData() != null) 110 logentrydata[ADMINDATA] = logentry.getAdminData(); 111 if(logentrydata[ADMINDATA] == null) 112 logentrydata[ADMINDATA] = ""; 113 } 114 } 115 116 117 logentrydata[CA] = (String ) caidtonamemap.get(new Integer (logentry.getCAId())); 118 119 logentrydata[MODULE] = localmodulenames[logentry.getModule()]; 120 121 logentrydata[USERNAME] = logentry.getUsername(); 122 if(logentrydata[USERNAME] != null && logentrydata[USERNAME].trim().equals("")) 123 logentrydata[USERNAME] = null; 124 125 logentrydata[CERTIFICATESERNO] = logentry.getCertificateSNR(); 126 if(logentry.getCertificateSNR() != null) 127 if(logentry.getCertificateSNR().trim().equals("")) 128 logentrydata[CERTIFICATESERNO] = null; 129 else 130 logentrydata[CERTIFICATESERNO] = logentry.getCertificateSNR(); 131 132 if(logentrydata[CERTIFICATESERNO] != null){ 133 String dnstring = dnproxy.getSubjectDN(logentry.getCertificateSNR()); 134 if(dnstring != null){ 135 DNFieldExtractor dn = new DNFieldExtractor(dnstring, DNFieldExtractor.TYPE_SUBJECTDN); 136 logentrydata[CERTIFICATE] = dn.getField(DNFieldExtractor.CN,0) + ", " + dn.getField(DNFieldExtractor.O,0); 137 } 138 } 139 140 if(logentry.getEvent() < LogEntry.EVENT_ERROR_BOUNDRARY) 141 logentrydata[EVENT] = localinfoeventnames[logentry.getEvent()]; 142 else 143 logentrydata[EVENT] = localerroreventnames[logentry.getEvent() - LogEntry.EVENT_ERROR_BOUNDRARY]; 144 145 logentrydata[COMMENT] = logentry.getComment(); 146 logentrydata[VERIFY] = logentry.getVerifyResult(); 147 } 148 149 public int compareTo(Object obj) { 150 int returnvalue = -1; 151 int sortby = this.sortby.getSortBy(); 152 switch(sortby){ 153 case SortBy.USERNAME : 154 returnvalue = logentrydata[USERNAME].compareTo(((LogEntryView) obj).getValue(USERNAME)); 155 break; 156 case SortBy.ADMINTYPE : 157 returnvalue = logentrydata[ADMINTYPE].compareTo(((LogEntryView) obj).getValue(ADMINTYPE)); 158 break; 159 case SortBy.ADMINDATA : 160 returnvalue = logentrydata[ADMINDATA].compareTo(((LogEntryView) obj).getValue(ADMINDATA)); 161 break; 162 case SortBy.CA : 163 returnvalue = logentrydata[CA].compareTo(((LogEntryView) obj).getValue(CA)); 164 break; 165 case SortBy.MODULE : 166 returnvalue = logentrydata[MODULE].compareTo(((LogEntryView) obj).getValue(MODULE)); 167 break; 168 case SortBy.CERTIFICATE : 169 returnvalue = logentrydata[CERTIFICATE].compareTo(((LogEntryView) obj).getValue(CERTIFICATE)); 170 break; 171 case SortBy.EVENT : 172 returnvalue = logentrydata[EVENT].compareTo(((LogEntryView) obj).getValue(EVENT)); 173 break; 174 case SortBy.COMMENT : 175 returnvalue = logentrydata[COMMENT].compareTo(((LogEntryView) obj).getValue(COMMENT)); 176 break; 177 case SortBy.TIME : 178 returnvalue = time.compareTo(((LogEntryView) obj).getTime()); 179 break; 180 default: 181 returnvalue = time.compareTo(((LogEntryView) obj).getTime()); 182 } 183 if(this.sortby.getSortOrder() == SortBy.DECENDING) 184 returnvalue = 0-returnvalue; 185 186 return returnvalue; 187 } 188 189 public void setSortBy(SortBy sortby){ 190 this.sortby=sortby; 191 } 192 193 public Date getTime(){return time;} 194 195 197 private String [] logentrydata; 199 private SortBy sortby; 200 private Date time; 201 private SubjectDNProxy dnproxy; 202 } 203 | Popular Tags |