1 13 14 package org.ejbca.ui.web.admin.loginterface; 15 16 import java.security.cert.X509Certificate ; 17 import java.util.Arrays ; 18 import java.util.Collection ; 19 import java.util.Date ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 23 import javax.servlet.http.HttpServletRequest ; 24 25 import org.ejbca.core.ejb.ServiceLocator; 26 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal; 27 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocalHome; 28 import org.ejbca.core.ejb.log.ILogSessionLocal; 29 import org.ejbca.core.ejb.log.ILogSessionLocalHome; 30 import org.ejbca.core.model.ca.caadmin.CADoesntExistsException; 31 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceNotActiveException; 32 import org.ejbca.core.model.ca.caadmin.extendedcaservices.ExtendedCAServiceRequestException; 33 import org.ejbca.core.model.ca.caadmin.extendedcaservices.IllegalExtendedCAServiceRequestException; 34 import org.ejbca.core.model.log.Admin; 35 import org.ejbca.core.model.log.ILogExporter; 36 import org.ejbca.core.model.log.LogConfiguration; 37 import org.ejbca.core.model.log.LogConstants; 38 import org.ejbca.core.model.log.LogEntry; 39 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean; 40 import org.ejbca.ui.web.admin.configuration.InformationMemory; 41 import org.ejbca.util.HTMLTools; 42 import org.ejbca.util.StringTools; 43 import org.ejbca.util.query.BasicMatch; 44 import org.ejbca.util.query.IllegalQueryException; 45 import org.ejbca.util.query.LogMatch; 46 import org.ejbca.util.query.Query; 47 48 54 public class LogInterfaceBean implements java.io.Serializable { 55 56 57 public LogInterfaceBean(){ 58 } 59 65 public void initialize(HttpServletRequest request, EjbcaWebBean ejbcawebbean) throws Exception { 66 67 if(!initialized){ 68 admin = new Admin(((X509Certificate []) request.getAttribute( "javax.servlet.request.X509Certificate" ))[0]); 69 70 final ServiceLocator locator = ServiceLocator.getInstance(); 71 ILogSessionLocalHome logsessionhome = (ILogSessionLocalHome) locator.getLocalHome(ILogSessionLocalHome.COMP_NAME); 72 logsession = logsessionhome.create(); 73 74 ICertificateStoreSessionLocalHome certificatesessionhome = (ICertificateStoreSessionLocalHome) locator.getLocalHome(ICertificateStoreSessionLocalHome.COMP_NAME); 75 certificatesession = certificatesessionhome.create(); 76 77 this.informationmemory = ejbcawebbean.getInformationMemory(); 78 79 initializeEventNameTables(ejbcawebbean); 80 81 dnproxy = new SubjectDNProxy(admin, certificatesession); 82 83 HashMap caidtonamemap = ejbcawebbean.getInformationMemory().getCAIdToNameMap(); 84 85 if(caidtonamemap.get(new Integer (LogConstants.INTERNALCAID)) == null){ 87 caidtonamemap.put(new Integer (LogConstants.INTERNALCAID),ejbcawebbean.getText("INTERNALCA")); 88 } 89 90 logentriesview = new LogEntriesView(dnproxy, localinfoeventnamesunsorted, localerroreventnamesunsorted, localmodulenamesunsorted, caidtonamemap); 91 initialized =true; 92 } 93 } 94 95 102 103 public LogEntryView[] filterByQuery(Query query, int index, int size) throws Exception { 104 Collection logentries = logsession.query(query, informationmemory.getViewLogQueryString(), informationmemory.getViewLogCAIdString()); 105 logentriesview.setEntries(logentries); 106 lastquery = query; 107 108 return logentriesview.getEntries(index,size); 109 } 110 111 119 public LogEntriesView filterByUsername(String username, HashMap caidtonamemap) throws Exception { 120 LogEntriesView returnval = new LogEntriesView(dnproxy, localinfoeventnamesunsorted, localerroreventnamesunsorted, localmodulenamesunsorted, caidtonamemap); 121 String user = StringTools.strip(username); 122 Query query = new Query(Query.TYPE_LOGQUERY); 123 query.add(LogMatch.MATCH_WITH_USERNAME, BasicMatch.MATCH_TYPE_EQUALS, user); 124 125 Collection logentries = logsession.query(query,informationmemory.getViewLogQueryString(), informationmemory.getViewLogCAIdString()); 126 returnval.setEntries(logentries); 127 lastquery = query; 128 129 return returnval; 130 } 131 132 140 public LogEntryView[] filterByTime(int time, int index, int size) throws Exception { 141 Query query = new Query(Query.TYPE_LOGQUERY); 142 Date starttime = new Date ( (new Date ()).getTime() - (time * 60000)); 143 144 query.add(starttime, new Date ()); 145 146 Collection logentries = logsession.query(query,informationmemory.getViewLogQueryString(), informationmemory.getViewLogCAIdString()); 147 logentriesview.setEntries(logentries); 148 lastquery = query; 149 150 return logentriesview.getEntries(index,size); 151 } 152 153 154 public int getResultSize(){ 155 return logentriesview.size(); 156 } 157 158 159 public void sortUserData(int sortby, int sortorder){ 160 logentriesview.sortBy(sortby,sortorder); 161 } 162 163 164 public LogEntryView[] getEntries(int index, int size){ 165 return logentriesview.getEntries(index, size); 166 } 167 168 public boolean nextButton(int index, int size){ 169 return index + size < logentriesview.size(); 170 } 171 public boolean previousButton(int index){ 172 return index > 0 ; 173 } 174 175 180 public LogConfiguration loadLogConfiguration(int caid) { 181 return logsession.loadLogConfiguration(caid); 182 } 183 184 189 public void saveLogConfiguration(int caid, LogConfiguration logconfiguration) { 190 logsession.saveLogConfiguration(admin, caid, logconfiguration); 191 } 192 193 194 195 200 public HashMap getEventNameHashToIdMap(){ 201 return localeventnamehashtoid; 202 } 203 204 209 public HashMap getTranslatedEventNameToIdMap(){ 210 return localtranslatedeventnamestoid; 211 } 212 213 218 public HashMap getModuleNameToIdMap(){ 219 return localmodulenamestoid; 220 } 221 222 227 public String [] getLocalInfoEventNames(){ 228 return localinfoeventnames; 229 } 230 231 236 public String [] getLocalErrorEventNames(){ 237 return localerroreventnames; 238 } 239 240 245 public String [] getAllLocalEventNames(){ 246 return alllocaleventnames; 247 } 248 249 254 public String [] getLocalModuleNames(EjbcaWebBean ejbcawebbean){ 255 Collection authorizedmodules = this.informationmemory.getAuthorizedModules(); 256 String [] returnval = new String [authorizedmodules.size()]; 257 Iterator iter = authorizedmodules.iterator(); 258 int i = 0; 259 while(iter.hasNext()){ 260 returnval[i] = ejbcawebbean.getText(LogEntry.MODULETEXTS[((Integer ) iter.next()).intValue()]); 261 i++; 262 } 263 264 return returnval; 265 } 266 267 278 public byte[] exportLastQuery(ILogExporter exporter) throws IllegalQueryException, CADoesntExistsException, ExtendedCAServiceRequestException, IllegalExtendedCAServiceRequestException, ExtendedCAServiceNotActiveException { 279 byte[] ret = logsession.export(admin, lastquery, informationmemory.getViewLogQueryString(), informationmemory.getViewLogCAIdString(), exporter); 280 return ret; 281 } 282 283 private void initializeEventNameTables(EjbcaWebBean ejbcawebbean){ 285 int alleventsize = LogEntry.EVENTNAMES_INFO.length + LogEntry.EVENTNAMES_ERROR.length; 286 alllocaleventnames = new String [alleventsize]; 287 localinfoeventnames = new String [LogEntry.EVENTNAMES_INFO.length]; 288 localinfoeventnamesunsorted = new String [LogEntry.EVENTNAMES_INFO.length]; 289 localeventnamehashtoid = new HashMap (); 290 localtranslatedeventnamestoid = new HashMap (); 291 for(int i = 0; i < localinfoeventnames.length; i++){ 292 String s = ejbcawebbean.getText(LogEntry.EVENTNAMES_INFO[i]); 294 localinfoeventnames[i] = s; 295 localinfoeventnamesunsorted[i] = s; 296 String translateds = HTMLTools.htmlunescape(s); 297 alllocaleventnames[i] = translateds; 298 Integer hashcode = new Integer (localinfoeventnames[i].hashCode()); 300 String hash = hashcode.toString(); 301 localeventnamehashtoid.put(hash, new Integer (i)); 302 localtranslatedeventnamestoid.put(translateds, new Integer (i)); 303 } 304 Arrays.sort(localinfoeventnames); 305 306 localerroreventnamesunsorted = new String [LogEntry.EVENTNAMES_ERROR.length]; 307 localerroreventnames = new String [LogEntry.EVENTNAMES_ERROR.length]; 308 for(int i = 0; i < localerroreventnames.length; i++){ 309 String s = ejbcawebbean.getText(LogEntry.EVENTNAMES_ERROR[i]); 311 localerroreventnames[i] = s; 312 localerroreventnamesunsorted[i] = s; 313 String translateds = HTMLTools.htmlunescape(s); 314 alllocaleventnames[LogEntry.EVENTNAMES_INFO.length + i] = translateds; 315 Integer hashcode = new Integer (s.hashCode()); 317 String hash = hashcode.toString(); 318 localeventnamehashtoid.put(hash, new Integer (i + LogEntry.EVENT_ERROR_BOUNDRARY)); 319 localtranslatedeventnamestoid.put(translateds, new Integer (i + LogEntry.EVENT_ERROR_BOUNDRARY)); 320 } 321 Arrays.sort(localerroreventnames); 322 Arrays.sort(alllocaleventnames); 323 324 localmodulenames = new String [LogEntry.MODULETEXTS.length]; 325 localmodulenamesunsorted = new String [LogEntry.MODULETEXTS.length]; 326 localmodulenamestoid = new HashMap (9); 327 for(int i = 0; i < localmodulenames.length; i++){ 328 localmodulenames[i] = ejbcawebbean.getText(LogEntry.MODULETEXTS[i]); 329 localmodulenamesunsorted[i] = localmodulenames[i]; 330 localmodulenamestoid.put(localmodulenames[i], new Integer (i)); 331 } 332 Arrays.sort(localmodulenames); 333 334 } 335 336 337 private ICertificateStoreSessionLocal certificatesession; 339 private ILogSessionLocal logsession; 340 private LogEntriesView logentriesview; 341 private Admin admin; 342 private SubjectDNProxy dnproxy; 343 private boolean initialized=false; 344 private InformationMemory informationmemory; 345 346 private HashMap localeventnamehashtoid; 347 private HashMap localtranslatedeventnamestoid; 348 private HashMap localmodulenamestoid; 349 private String [] localinfoeventnames; 350 private String [] localerroreventnames; 351 private String [] localinfoeventnamesunsorted; 352 private String [] localerroreventnamesunsorted; 353 private String [] alllocaleventnames; 354 private String [] localmodulenames; 355 private String [] localmodulenamesunsorted; 356 private Query lastquery; 357 358 } 359 | Popular Tags |