KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Admin.java
16  *
17  * Created on den 25 august 2002, 10:02
18  */

19
20 package org.ejbca.core.model.log;
21
22
23 import java.io.Serializable JavaDoc;
24 import java.security.cert.X509Certificate JavaDoc;
25
26 import org.ejbca.core.model.authorization.AdminEntity;
27 import org.ejbca.core.model.authorization.AdminInformation;
28 import org.ejbca.util.CertTools;
29
30 /**
31  * This is a class containing information about the administrator or admin preforming the event.
32  * Data contained in the class is preferbly
33  *
34  * @author TomSelleck
35  * @version $Id: Admin.java,v 1.4 2007/01/07 20:08:57 anatom Exp $
36  */

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

48     private static final long serialVersionUID = -9221031402622809524L;
49     
50     // Public Constants
51
// Indicates the type of administrator.
52
/** An administrator authenticated with client certificate */
53     public static final int TYPE_CLIENTCERT_USER = 0;
54     /** A user of the public web pages */
55     public static final int TYPE_PUBLIC_WEB_USER = 1;
56     /** An internal RA function, such as cmd line or CMP */
57     public static final int TYPE_RA_USER = 2;
58     /** An internal CA admin function, such as cms line */
59     public static final int TYPE_CACOMMANDLINE_USER = 3;
60     /** Batch generation tool */
61     public static final int TYPE_BATCHCOMMANDLINE_USER = 4;
62     /** Internal user in EJBCA, such as automatic job */
63     public static final int TYPE_INTERNALUSER = 5;
64
65     public static final int SPECIAL_ADMIN_BOUNDRARY = 100;
66
67     public static final String JavaDoc[] ADMINTYPETEXTS = {"CLIENTCERT", "PUBLICWEBUSER", "RACMDLINE", "CACMDLINE", "BATCHCMDLINE", "INTERNALUSER"};
68
69     private static final int[] ADMINTYPETOADMINENTITY = {0, AdminEntity.SPECIALADMIN_PUBLICWEBUSER, AdminEntity.SPECIALADMIN_RAADMIN,
70                                                          AdminEntity.SPECIALADMIN_CACOMMANDLINEADMIN, AdminEntity.SPECIALADMIN_BATCHCOMMANDLINEADMIN,
71                                                          AdminEntity.SPECIALADMIN_INTERNALUSER};
72
73     private int type = -1;
74     private String JavaDoc data;
75     private X509Certificate JavaDoc certificate;
76
77     // Public Constructors
78
public Admin(X509Certificate JavaDoc certificate) {
79         this(TYPE_CLIENTCERT_USER, certificate.getSerialNumber().toString(16) + ", " + CertTools.getIssuerDN(certificate));
80         this.certificate = certificate;
81     }
82
83     public Admin(int type, String JavaDoc ip) {
84         this.type = type;
85         this.data = ip;
86     }
87
88     public Admin(int type) {
89         this(type, null);
90     }
91
92
93     // Public Methods
94

95     public int getAdminType() {
96         return this.type;
97     }
98
99     public String JavaDoc getAdminData() {
100         return this.data;
101     }
102
103     // Method that takes the internal data and returns a AdminInformation object required by the Authorization module.
104
public AdminInformation getAdminInformation() {
105         if (type == TYPE_CLIENTCERT_USER)
106             return new AdminInformation(certificate);
107
108         return new AdminInformation(ADMINTYPETOADMINENTITY[type]);
109     }
110
111     /**
112      * Method thar returns the caid of the CA, the admin belongs to.
113      * Doesn't work properly for public web and special users so use with care.
114      */

115
116     public int getCaId() {
117         int returnval = LogConstants.INTERNALCAID;
118         if (type == TYPE_CLIENTCERT_USER)
119             returnval = CertTools.getIssuerDN(certificate).hashCode();
120         return returnval;
121     }
122     public String JavaDoc toString() {
123         if ((type > -1) && (type < ADMINTYPETEXTS.length-1)) {
124             return ADMINTYPETEXTS[type];
125         }
126         return "UNKNOWN";
127     }
128
129 }
130
Popular Tags