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.loginterface;
013:
014: import java.util.Date;
015: import java.util.HashMap;
016: import java.text.DateFormat;
017: import java.rmi.RemoteException;
018:
019: import org.ejbca.core.model.log.Admin;
020: import org.ejbca.core.model.log.LogConstants;
021: import org.ejbca.core.model.log.LogEntry;
022: import org.ejbca.ui.web.admin.rainterface.SortBy;
023: import org.ejbca.util.dn.DNFieldExtractor;
024:
025: /**
026: * A class used as a help class for displaying LogEntries.
027: *
028: * @author TomSelleck
029: * @version $Id: LogEntryView.java,v 1.5 2007/12/04 18:43:36 jeklund Exp $
030: */
031: public class LogEntryView implements java.io.Serializable, Cloneable,
032: Comparable {
033: // Public constants.
034: public static final int TIME = 0;
035: public static final int ADMINTYPE = 1;
036: public static final int ADMINDATA = 2;
037: public static final int ADMINCERTSERNO = 3;
038: public static final int CA = 4;
039: public static final int MODULE = 5;
040: public static final int USERNAME = 6;
041: public static final int CERTIFICATE = 7;
042: public static final int CERTIFICATESERNO = 8;
043: public static final int EVENT = 9;
044: public static final int COMMENT = 10;
045: public static final int VERIFY = 11;
046:
047: public static final String TRUE = "T";
048: public static final String FALSE = "F";
049:
050: public static final int NUMBEROF_FIELDS = 12;
051:
052: /** Creates a new instance of UserView */
053: public LogEntryView(SubjectDNProxy dnproxy) {
054: logentrydata = new String[NUMBEROF_FIELDS];
055: for (int i = 0; i < NUMBEROF_FIELDS; i++) {
056: logentrydata[i] = "";
057: }
058: this .dnproxy = dnproxy;
059: }
060:
061: public LogEntryView(LogEntry logentry, SubjectDNProxy dnproxy,
062: String[] localinfoeventnames,
063: String[] localerroreventnames,
064: String[] localsystemeventnames, String[] localmodulenames,
065: HashMap caidtonamemap) throws RemoteException {
066: logentrydata = new String[NUMBEROF_FIELDS];
067: for (int i = 0; i < NUMBEROF_FIELDS; i++) {
068: logentrydata[i] = "";
069: }
070: this .dnproxy = dnproxy;
071: setValues(logentry, localinfoeventnames, localerroreventnames,
072: localsystemeventnames, localmodulenames, caidtonamemap);
073: }
074:
075: // Public methods.
076: /** Method that returns the specific logentry pointed by the parameter. */
077: public String getValue(int parameter) {
078: return logentrydata[parameter];
079: }
080:
081: /** Method that returns the specific logentry pointed by the parameter. */
082: public void setValue(int parameter, String value) {
083: logentrydata[parameter] = value;
084: }
085:
086: /** Method that returns the logentrydata as a String array */
087: public String[] getValues() {
088: return logentrydata;
089: }
090:
091: /* Sets the values according to the values in the LogEntry object.*/
092: public void setValues(LogEntry logentry,
093: String[] localinfoeventnames,
094: String[] localerroreventnames,
095: String[] localsystemeventnames, String[] localmodulenames,
096: HashMap caidtonamemap) throws RemoteException {
097:
098: logentrydata[TIME] = DateFormat.getDateTimeInstance(
099: DateFormat.SHORT, DateFormat.SHORT).format(
100: logentry.getTime());
101: this .time = logentry.getTime();
102:
103: logentrydata[ADMINTYPE] = Integer.toString(logentry
104: .getAdminType());
105: if (logentry.getAdminType() == Admin.TYPE_CLIENTCERT_USER) {
106: String dnstring = dnproxy.getSubjectDN(logentry
107: .getAdminData());
108: if (dnstring != null) {
109: DNFieldExtractor dn = new DNFieldExtractor(dnstring,
110: DNFieldExtractor.TYPE_SUBJECTDN);
111: logentrydata[ADMINCERTSERNO] = logentry.getAdminData();
112: logentrydata[ADMINDATA] = dn.getField(
113: DNFieldExtractor.CN, 0)
114: + ", " + dn.getField(DNFieldExtractor.O, 0);
115: }
116: } else {
117: if (logentry.getAdminType() == Admin.TYPE_PUBLIC_WEB_USER) {
118: if (logentry.getAdminData() != null)
119: logentrydata[ADMINDATA] = "IP : "
120: + logentry.getAdminData();
121: if (logentrydata[ADMINDATA] == null)
122: logentrydata[ADMINDATA] = "";
123: } else {
124: if (logentry.getAdminData() != null)
125: logentrydata[ADMINDATA] = logentry.getAdminData();
126: if (logentrydata[ADMINDATA] == null)
127: logentrydata[ADMINDATA] = "";
128: }
129: }
130:
131: logentrydata[CA] = (String) caidtonamemap.get(new Integer(
132: logentry.getCAId()));
133:
134: logentrydata[MODULE] = localmodulenames[logentry.getModule()];
135:
136: logentrydata[USERNAME] = logentry.getUsername();
137: if (logentrydata[USERNAME] != null
138: && logentrydata[USERNAME].trim().equals(""))
139: logentrydata[USERNAME] = null;
140:
141: logentrydata[CERTIFICATESERNO] = logentry.getCertificateSNR();
142: if (logentry.getCertificateSNR() != null)
143: if (logentry.getCertificateSNR().trim().equals(""))
144: logentrydata[CERTIFICATESERNO] = null;
145: else
146: logentrydata[CERTIFICATESERNO] = logentry
147: .getCertificateSNR();
148:
149: if (logentrydata[CERTIFICATESERNO] != null) {
150: String dnstring = dnproxy.getSubjectDN(logentry
151: .getCertificateSNR());
152: if (dnstring != null) {
153: DNFieldExtractor dn = new DNFieldExtractor(dnstring,
154: DNFieldExtractor.TYPE_SUBJECTDN);
155: logentrydata[CERTIFICATE] = dn.getField(
156: DNFieldExtractor.CN, 0)
157: + ", " + dn.getField(DNFieldExtractor.O, 0);
158: }
159: }
160:
161: if (logentry.getEvent() < LogConstants.EVENT_ERROR_BOUNDRARY) {
162: logentrydata[EVENT] = localinfoeventnames[logentry
163: .getEvent()];
164: } else if (logentry.getEvent() < LogConstants.EVENT_SYSTEM_BOUNDRARY) {
165: logentrydata[EVENT] = localerroreventnames[logentry
166: .getEvent()
167: - LogConstants.EVENT_ERROR_BOUNDRARY];
168: } else {
169: logentrydata[EVENT] = localsystemeventnames[logentry
170: .getEvent()
171: - LogConstants.EVENT_SYSTEM_BOUNDRARY];
172: }
173:
174: logentrydata[COMMENT] = logentry.getComment();
175: logentrydata[VERIFY] = logentry.getVerifyResult();
176: }
177:
178: public int compareTo(Object obj) {
179: int returnvalue = -1;
180: int sortby = this .sortby.getSortBy();
181: switch (sortby) {
182: case SortBy.USERNAME:
183: returnvalue = logentrydata[USERNAME]
184: .compareTo(((LogEntryView) obj).getValue(USERNAME));
185: break;
186: case SortBy.ADMINTYPE:
187: returnvalue = logentrydata[ADMINTYPE]
188: .compareTo(((LogEntryView) obj).getValue(ADMINTYPE));
189: break;
190: case SortBy.ADMINDATA:
191: returnvalue = logentrydata[ADMINDATA]
192: .compareTo(((LogEntryView) obj).getValue(ADMINDATA));
193: break;
194: case SortBy.CA:
195: returnvalue = logentrydata[CA]
196: .compareTo(((LogEntryView) obj).getValue(CA));
197: break;
198: case SortBy.MODULE:
199: returnvalue = logentrydata[MODULE]
200: .compareTo(((LogEntryView) obj).getValue(MODULE));
201: break;
202: case SortBy.CERTIFICATE:
203: returnvalue = logentrydata[CERTIFICATE]
204: .compareTo(((LogEntryView) obj)
205: .getValue(CERTIFICATE));
206: break;
207: case SortBy.EVENT:
208: returnvalue = logentrydata[EVENT]
209: .compareTo(((LogEntryView) obj).getValue(EVENT));
210: break;
211: case SortBy.COMMENT:
212: returnvalue = logentrydata[COMMENT]
213: .compareTo(((LogEntryView) obj).getValue(COMMENT));
214: break;
215: case SortBy.TIME:
216: returnvalue = time
217: .compareTo(((LogEntryView) obj).getTime());
218: break;
219: default:
220: returnvalue = time
221: .compareTo(((LogEntryView) obj).getTime());
222: }
223: if (this .sortby.getSortOrder() == SortBy.DECENDING)
224: returnvalue = 0 - returnvalue;
225:
226: return returnvalue;
227: }
228:
229: public void setSortBy(SortBy sortby) {
230: this .sortby = sortby;
231: }
232:
233: public Date getTime() {
234: return time;
235: }
236:
237: // Private constants.
238:
239: // Private methods.
240: private String[] logentrydata;
241: private SortBy sortby;
242: private Date time;
243: private SubjectDNProxy dnproxy;
244: }
|