KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > log > LogEntry


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 /*
15  * LogEntry.java
16  *
17  * Created on den 28 aug 2002, 10:02
18  */

19
20 package org.ejbca.core.model.log;
21
22 import java.io.Serializable JavaDoc;
23 import java.io.UnsupportedEncodingException JavaDoc;
24 import java.security.MessageDigest JavaDoc;
25 import java.security.NoSuchAlgorithmException JavaDoc;
26 import java.security.NoSuchProviderException JavaDoc;
27 import java.util.Date JavaDoc;
28
29 import org.bouncycastle.util.encoders.Hex;
30 import org.ejbca.core.model.protect.Protectable;
31 import org.ejbca.core.model.protect.TableVerifyResult;
32
33 /**
34  * This is a class containing information about one log event in the database. Used mainly during database queries by the web interface.
35  *
36  * @author TomSelleck
37  * @version $Id: LogEntry.java,v 1.10.2.1 2007/04/02 08:22:56 jeklund Exp $
38  */

39 public class LogEntry implements Serializable JavaDoc, Protectable {
40
41     /**
42      * Determines if a de-serialized file is compatible with this class.
43      *
44      * Maintainers must change this value if and only if the new version
45      * of this class is not compatible with old versions. See Sun docs
46      * for <a HREF=http://java.sun.com/products/jdk/1.1/docs/guide
47      * /serialization/spec/version.doc.html> details. </a>
48      *
49      */

50     private static final long serialVersionUID = -1L;
51     
52     // Public constants
53

54     /*Possible log events, all information events should have an id below 1000 and all error events should have a id above 1000 */
55     // Information events. Important all id:s should map to the array EVENTNAMES_INFO.
56
public static final int EVENT_INFO_UNKNOWN = 0;
57     public static final int EVENT_INFO_ADDEDENDENTITY = 1;
58     public static final int EVENT_INFO_CHANGEDENDENTITY = 2;
59     public static final int EVENT_INFO_REVOKEDENDENTITY = 3;
60     public static final int EVENT_INFO_REVOKEDCERT = 4;
61     public static final int EVENT_INFO_DELETEDENDENTITY = 5;
62     public static final int EVENT_INFO_EDITSYSTEMCONFIGURATION = 6;
63     public static final int EVENT_INFO_EDITEDADMINISTRATORPRIVILEGES = 7;
64     public static final int EVENT_INFO_EDITLOGCONFIGURATION = 8;
65     public static final int EVENT_INFO_ADMINISTRATORPREFERENCECHANGED = 9;
66     public static final int EVENT_INFO_ENDENTITYPROFILE = 10;
67     public static final int EVENT_INFO_USERAUTHENTICATION = 11;
68     public static final int EVENT_INFO_STORECERTIFICATE = 12;
69     public static final int EVENT_INFO_STORECRL = 13;
70     public static final int EVENT_INFO_GETLASTCRL = 14;
71     public static final int EVENT_INFO_CERTPROFILE = 15;
72     public static final int EVENT_INFO_DATABASE = 16;
73     public static final int EVENT_INFO_CREATECERTIFICATE = 17;
74     public static final int EVENT_INFO_CREATECRL = 18;
75     public static final int EVENT_INFO_ADMINISTRATORLOGGEDIN = 19;
76     public static final int EVENT_INFO_AUTHORIZEDTORESOURCE = 20;
77     public static final int EVENT_INFO_PUBLICWEBUSERCONNECTED = 21;
78     public static final int EVENT_INFO_HARDTOKEN_USERDATASENT = 22;
79     public static final int EVENT_INFO_HARDTOKENGENERATED = 23;
80     public static final int EVENT_INFO_HARDTOKENDATA = 24;
81     public static final int EVENT_INFO_HARDTOKENISSUERDATA = 25;
82     public static final int EVENT_INFO_HARDTOKENCERTIFICATEMAP = 26;
83     public static final int EVENT_INFO_KEYRECOVERY = 27;
84     public static final int EVENT_INFO_NOTIFICATION = 28;
85     public static final int EVENT_INFO_HARDTOKENVIEWED = 29;
86     public static final int EVENT_INFO_CACREATED = 30;
87     public static final int EVENT_INFO_CAEDITED = 31;
88     public static final int EVENT_INFO_CAREVOKED = 32;
89     public static final int EVENT_INFO_HARDTOKENPROFILEDATA = 33;
90     public static final int EVENT_INFO_PUBLISHERDATA = 34;
91     public static final int EVENT_INFO_USERDATASOURCEDATA = 35;
92     public static final int EVENT_INFO_USERDATAFETCHED = 36;
93     public static final int EVENT_INFO_UNREVOKEDCERT = 37;
94     public static final int EVENT_INFO_APPROVALREQUESTED = 38;
95     public static final int EVENT_INFO_APPROVALAPPROVED = 39;
96     public static final int EVENT_INFO_APPROVALREJECTED = 40;
97     public static final int EVENT_INFO_SERVICESEDITED = 41;
98     public static final int EVENT_INFO_SERVICEEXECUTED = 42;
99     public static final int EVENT_INFO_REQUESTCERTIFICATE = 43;
100     public static final int EVENT_INFO_CARENEWED = 44;
101     public static final int EVENT_INFO_CAEXPORTED = 45;
102
103     // Error events. Important all id:s should map to the array EVENTNAMES_ERROR - EVENT_ERROR_BOUNDRARY.
104
public static final int EVENT_ERROR_UNKNOWN = 1000;
105     public static final int EVENT_ERROR_ADDEDENDENTITY = 1001;
106     public static final int EVENT_ERROR_CHANGEDENDENTITY = 1002;
107     public static final int EVENT_ERROR_REVOKEDENDENTITY = 1003;
108     public static final int EVENT_ERROR_REVOKEDCERT = 1004;
109     public static final int EVENT_ERROR_DELETEENDENTITY = 1005;
110     public static final int EVENT_ERROR_EDITSYSTEMCONFIGURATION = 1006;
111     public static final int EVENT_ERROR_EDITEDADMINISTRATORPRIVILEGES = 1007;
112     public static final int EVENT_ERROR_EDITLOGCONFIGURATION = 1008;
113     public static final int EVENT_ERROR_ADMINISTRATORPREFERENCECHANGED = 1009;
114     public static final int EVENT_ERROR_ENDENTITYPROFILE = 1010;
115     public static final int EVENT_ERROR_USERAUTHENTICATION = 1011;
116     public static final int EVENT_ERROR_STORECERTIFICATE = 1012;
117     public static final int EVENT_ERROR_STORECRL = 1013;
118     public static final int EVENT_ERROR_GETLASTCRL = 1014;
119     public static final int EVENT_ERROR_CERTPROFILE = 1015;
120     public static final int EVENT_ERROR_DATABASE = 1016;
121     public static final int EVENT_ERROR_CREATECERTIFICATE = 1017;
122     public static final int EVENT_ERROR_CREATECRL = 1018;
123     public static final int EVENT_ERROR_ADMINISTRATORLOGGEDIN = 1019;
124     public static final int EVENT_ERROR_NOTAUTHORIZEDTORESOURCE = 1020;
125     public static final int EVENT_ERROR_PUBLICWEBUSERCONNECTED = 1021;
126     public static final int EVENT_ERROR_HARDTOKEN_USERDATASENT = 1022;
127     public static final int EVENT_ERROR_HARDTOKENGENERATED = 1023;
128     public static final int EVENT_ERROR_HARDTOKENDATA = 1024;
129     public static final int EVENT_ERROR_HARDTOKENISSUERDATA = 1025;
130     public static final int EVENT_ERROR_HARDTOKENCERTIFICATEMAP = 1026;
131     public static final int EVENT_ERROR_KEYRECOVERY = 1027;
132     public static final int EVENT_ERROR_NOTIFICATION = 1028;
133     public static final int EVENT_ERROR_HARDTOKENVIEWED = 1029;
134     public static final int EVENT_ERROR_CACREATED = 1030;
135     public static final int EVENT_ERROR_CAEDITED = 1031;
136     public static final int EVENT_ERROR_CAREVOKED = 1032;
137     public static final int EVENT_ERROR_HARDTOKENPROFILEDATA = 1033;
138     public static final int EVENT_ERROR_PUBLISHERDATA = 1034;
139     public static final int EVENT_ERROR_USERDATASOURCEDATA = 1035;
140     public static final int EVENT_ERROR_USERDATAFETCHED = 1036;
141     public static final int EVENT_ERROR_UNREVOKEDCERT = 1037;
142     public static final int EVENT_ERROR_APPROVALREQUESTED = 1038;
143     public static final int EVENT_ERROR_APPROVALAPPROVED = 1039;
144     public static final int EVENT_ERROR_APPROVALREJECTED = 1040;
145     public static final int EVENT_ERROR_SERVICESEDITED = 1041;
146     public static final int EVENT_ERROR_SERVICEEXECUTED = 1042;
147     public static final int EVENT_ERROR_REQUESTCERTIFICATE = 1043;
148     public static final int EVENT_ERROR_CARENEWED = 1044;
149     public static final int EVENT_ERROR_CAEXPORTED = 1045;
150
151     // Indicates the module using the logsession bean.
152
public static final int MODULE_CA = 0;
153     public static final int MODULE_RA = 1;
154     public static final int MODULE_LOG = 2;
155     public static final int MODULE_PUBLICWEB = 3;
156     public static final int MODULE_ADMINWEB = 4;
157     public static final int MODULE_HARDTOKEN = 5;
158     public static final int MODULE_KEYRECOVERY = 6;
159     public static final int MODULE_AUTHORIZATION = 7;
160     public static final int MODULE_APPROVAL = 8;
161     public static final int MODULE_SERVICES = 9;
162
163     public static final int EVENT_ERROR_BOUNDRARY = 1000;
164
165     // Id -> String maps
166
public static final String JavaDoc[] EVENTNAMES_INFO = {"EVENT_INFO_UNKNOWN", "EVENT_INFO_ADDEDENDENTITY", "EVENT_INFO_CHANGEDENDENTITY", "EVENT_INFO_REVOKEDENDENTITY", "EVENT_INFO_REVOKEDCERT",
167                                                     "EVENT_INFO_DELETEDENDENTITY", "EVENT_INFO_EDITSYSTEMCONFIGURATION", "EVENT_INFO_EDITEDADMINISTRATORPRIVILEGES",
168                                                     "EVENT_INFO_EDITLOGCONFIGURATION", "EVENT_INFO_ADMINISTRATORPREFERENCECHANGED", "EVENT_INFO_ENDENTITYPROFILE", "EVENT_INFO_USERAUTHENTICATION",
169                                                     "EVENT_INFO_STORECERTIFICATE", "EVENT_INFO_STORECRL", "EVENT_INFO_GETLASTCRL", "EVENT_INFO_CERTPROFILE", "EVENT_INFO_DATABASE",
170                                                     "EVENT_INFO_CREATECERTIFICATE", "EVENT_INFO_CREATECRL", "EVENT_INFO_ADMINISTRATORLOGGEDIN", "EVENT_INFO_AUTHORIZEDTORESOURCE",
171                                                     "EVENT_INFO_PUBLICWEBUSERCONNECTED", "EVENT_INFO_HARDTOKEN_USERDATASENT", "EVENT_INFO_HARDTOKENGENERATED", "EVENT_INFO_HARDTOKENDATA",
172                                                     "EVENT_INFO_HARDTOKENISSUERDATA", "EVENT_INFO_HARDTOKENCERTIFICATEMAP", "EVENT_INFO_KEYRECOVERY", "EVENT_INFO_NOTIFICATION",
173                                                     "EVENT_INFO_HARDTOKENVIEWED", "EVENT_INFO_CACREATED", "EVENT_INFO_CAEDITED", "EVENT_INFO_CAREVOKED", "EVENT_INFO_HARDTOKENPROFILEDATA",
174                                                     "EVENT_INFO_PUBLISHERDATA", "EVENT_INFO_USERDATASOURCEDATA", "EVENT_INFO_USERDATAFETCHED", "EVENT_INFO_UNREVOKEDCERT",
175                                                     "EVENT_INFO_APPROVALREQUESTED","EVENT_INFO_APPROVALAPPROVED","EVENT_INFO_APPROVALREJECTED","EVENT_INFO_SERVICESEDITED","EVENT_INFO_SERVICEEXECUTED",
176                                                     "EVENT_INFO_REQUESTCERTIFICATE", "EVENT_INFO_CARENEWED", "EVENT_INFO_CAEXPORTED"};
177
178
179     public static final String JavaDoc[] EVENTNAMES_ERROR = {"EVENT_ERROR_UNKNOWN", "EVENT_ERROR_ADDEDENDENTITY", "EVENT_ERROR_CHANGEDENDENTITY", "EVENT_ERROR_REVOKEDENDENTITY", "EVENT_ERROR_REVOKEDCERT",
180                                                      "EVENT_ERROR_DELETEENDENTITY", "EVENT_ERROR_EDITSYSTEMCONFIGURATION", "EVENT_ERROR_EDITEDADMINISTRATORPRIVILEGES",
181                                                      "EVENT_ERROR_EDITLOGCONFIGURATION", "EVENT_ERROR_ADMINISTRATORPREFERENCECHANGED", "EVENT_ERROR_ENDENTITYPROFILE", "EVENT_ERROR_USERAUTHENTICATION",
182                                                      "EVENT_ERROR_STORECERTIFICATE", "EVENT_ERROR_STORECRL", "EVENT_ERROR_GETLASTCRL", "EVENT_ERROR_CERTPROFILE", "EVENT_ERROR_DATABASE",
183                                                      "EVENT_ERROR_CREATECERTIFICATE", "EVENT_ERROR_CREATECRL", "EVENT_ERROR_ADMINISTRATORLOGGEDIN", "EVENT_ERROR_NOTAUTHORIZEDTORESOURCE",
184                                                      "EVENT_ERROR_PUBLICWEBUSERCONNECTED", "EVENT_ERROR_HARDTOKEN_USERDATASENT", "EVENT_ERROR_HARDTOKENGENERATED", "EVENT_ERROR_HARDTOKENDATA",
185                                                      "EVENT_ERROR_HARDTOKENISSUERDATA", "EVENT_ERROR_HARDTOKENCERTIFICATEMAP", "EVENT_ERROR_KEYRECOVERY", "EVENT_ERROR_NOTIFICATION",
186                                                      "EVENT_ERROR_HARDTOKENVIEWED", "EVENT_ERROR_CACREATED", "EVENT_ERROR_CAEDITED", "EVENT_ERROR_CAREVOKED", "EVENT_ERROR_HARDTOKENPROFILEDATA",
187                                                      "EVENT_ERROR_PUBLISHERDATA", "EVENT_ERROR_USERDATASOURCEDATA", "EVENT_ERROR_USERDATAFETCHED", "EVENT_ERROR_UNREVOKEDCERT",
188                                                      "EVENT_ERROR_APPROVALREQUESTED","EVENT_ERROR_APPROVALAPPROVED","EVENT_ERROR_APPROVALREJECTED","EVENT_ERROR_SERVICESEDITED",
189                                                      "EVENT_ERROR_SERVICEEXECUTED", "EVENT_ERROR_REQUESTCERTIFICATE", "EVENT_ERROR_CARENEWED", "EVENT_ERROR_CAEXPORTED"};
190
191     public static final String JavaDoc[] MODULETEXTS = {"CA", "RA", "LOG", "PUBLICWEB", "ADMINWEB", "HARDTOKEN", "KEYRECOVERY", "AUTHORIZATION","APPROVAL","SERVICE"};
192
193
194     /**
195      * Function used by EJBCA to log information.
196      *
197      * @param admintype is pricipally the type of data stored in the admindata field, should be one of org.ejbca.core.model.log.Admin.TYPE_ constants.
198      * @param admindata is the data identifying the administrator, should be certificate snr or ip-address when no certificate could be retrieved.
199      * @param module indicates from which module the event was logged. i.e one of the constans LogEntry.MODULE_RA, LogEntry.MODULE_CA ....
200      * @param time the time the event occured.
201      * @param username the name of the user involved or null if no user is involved.
202      * @param certificate the certificate involved in the event or null if no certificate is involved.
203      * @param event id of the event, should be one of the org.ejbca.core.model.log.LogEntry.EVENT_ constants.
204      * @param comment comment of the event.
205      */

206
207     public LogEntry(int id, int admintype, String JavaDoc admindata, int caid, int module, Date JavaDoc time, String JavaDoc username, String JavaDoc certificatesnr, int event, String JavaDoc comment) {
208         this.id = id;
209         this.admintype = admintype;
210         this.admindata = admindata;
211         this.caid = caid;
212         this.module = module;
213         this.time = time;
214         this.username = username;
215         this.certificatesnr = certificatesnr;
216         this.event = event;
217         this.comment = comment;
218     }
219
220     // Public methods
221

222     /**
223      * Method used to map between event id and a string representation of event
224      *
225      * @return a string representation of the event.
226      */

227     public String JavaDoc getEventName() {
228         if (this.event >= EVENT_ERROR_BOUNDRARY)
229             return EVENTNAMES_ERROR[this.event - EVENT_ERROR_BOUNDRARY];
230         return EVENTNAMES_INFO[this.event];
231     }
232
233
234     public int getId() {
235         return this.id;
236     }
237
238     public int getAdminType() {
239         return this.admintype;
240     }
241
242     public String JavaDoc getAdminData() {
243         return this.admindata;
244     }
245
246     public int getCAId() {
247         return this.caid;
248     }
249
250     public int getModule() {
251         return this.module;
252     }
253
254     public Date JavaDoc getTime() {
255         return this.time;
256     }
257
258     public String JavaDoc getUsername() {
259         return this.username;
260     }
261
262     public String JavaDoc getCertificateSNR() {
263         return this.certificatesnr;
264     }
265
266     public int getEvent() {
267         return this.event;
268     }
269
270     public String JavaDoc getComment() {
271         return this.comment;
272     }
273
274     public String JavaDoc getVerifyResult() {
275         return this.verifyResult;
276     }
277
278     public void setVerifyResult(String JavaDoc result) {
279         this.verifyResult=result;
280     }
281     
282     //
283
// Protectable
284
//
285
public int getHashVersion() {
286         return 1;
287     }
288     public String JavaDoc getDbKeyString() {
289         return Integer.toString(id);
290     }
291     public String JavaDoc getEntryType() {
292         return "LOGENTRY";
293     }
294     public String JavaDoc getHash() throws NoSuchAlgorithmException JavaDoc, NoSuchProviderException JavaDoc, UnsupportedEncodingException JavaDoc {
295         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
296         buf.append(id).append(admintype).append(admindata).append(caid).append(module).append(time.getTime()).
297             append(username).append(certificatesnr).append(event).append(comment);
298         MessageDigest JavaDoc digest = MessageDigest.getInstance("SHA-256", "BC");
299         byte[] result = digest.digest(buf.toString().getBytes("UTF-8"));
300         return new String JavaDoc(Hex.encode(result));
301     }
302     public String JavaDoc getHash(int version) throws NoSuchAlgorithmException JavaDoc, NoSuchProviderException JavaDoc, UnsupportedEncodingException JavaDoc {
303         return getHash();
304     }
305
306     // Private methods
307

308     // Private fields
309
private int id;
310     private int admintype;
311     private String JavaDoc admindata;
312     private int caid;
313     private int module;
314     private Date JavaDoc time;
315     private String JavaDoc username;
316     private String JavaDoc certificatesnr;
317     private int event;
318     private String JavaDoc comment;
319     private String JavaDoc verifyResult = TableVerifyResult.VERIFY_DISABLED_MSG;
320
321 }
322
Popular Tags