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.core.model.log;
013:
014: import java.io.Serializable;
015: import java.security.cert.X509Certificate;
016:
017: import org.ejbca.core.model.authorization.AdminEntity;
018: import org.ejbca.core.model.authorization.AdminInformation;
019: import org.ejbca.util.CertTools;
020:
021: /**
022: * This is a class containing information about the administrator or admin preforming the event.
023: * Data contained in the class is preferbly
024: *
025: * @author TomSelleck
026: * @version $Id: Admin.java,v 1.5 2007/06/25 14:45:32 herrvendil Exp $
027: */
028: public class Admin implements Serializable {
029:
030: /**
031: * Determines if a de-serialized file is compatible with this class.
032: *
033: * Maintainers must change this value if and only if the new version
034: * of this class is not compatible with old versions. See Sun docs
035: * for <a href=http://java.sun.com/products/jdk/1.1/docs/guide
036: * /serialization/spec/version.doc.html> details. </a>
037: *
038: */
039: private static final long serialVersionUID = -9221031402622809524L;
040:
041: // Public Constants
042: // Indicates the type of administrator.
043: /** An administrator authenticated with client certificate */
044: public static final int TYPE_CLIENTCERT_USER = 0;
045: /** A user of the public web pages */
046: public static final int TYPE_PUBLIC_WEB_USER = 1;
047: /** An internal RA function, such as cmd line or CMP */
048: public static final int TYPE_RA_USER = 2;
049: /** An internal CA admin function, such as cms line */
050: public static final int TYPE_CACOMMANDLINE_USER = 3;
051: /** Batch generation tool */
052: public static final int TYPE_BATCHCOMMANDLINE_USER = 4;
053: /** Internal user in EJBCA, such as automatic job */
054: public static final int TYPE_INTERNALUSER = 5;
055:
056: public static final int SPECIAL_ADMIN_BOUNDRARY = 100;
057:
058: public static final String[] ADMINTYPETEXTS = { "CLIENTCERT",
059: "PUBLICWEBUSER", "RACMDLINE", "CACMDLINE", "BATCHCMDLINE",
060: "INTERNALUSER" };
061:
062: private static final int[] ADMINTYPETOADMINENTITY = { 0,
063: AdminEntity.SPECIALADMIN_PUBLICWEBUSER,
064: AdminEntity.SPECIALADMIN_RAADMIN,
065: AdminEntity.SPECIALADMIN_CACOMMANDLINEADMIN,
066: AdminEntity.SPECIALADMIN_BATCHCOMMANDLINEADMIN,
067: AdminEntity.SPECIALADMIN_INTERNALUSER };
068:
069: protected int type = -1;
070: protected String data;
071: protected X509Certificate certificate;
072:
073: // Public Constructors
074: public Admin(X509Certificate certificate) {
075: this (TYPE_CLIENTCERT_USER, certificate.getSerialNumber()
076: .toString(16)
077: + ", " + CertTools.getIssuerDN(certificate));
078: this .certificate = certificate;
079: }
080:
081: public Admin(int type, String ip) {
082: this .type = type;
083: this .data = ip;
084: }
085:
086: public Admin(int type) {
087: this (type, null);
088: }
089:
090: // Public Methods
091:
092: public int getAdminType() {
093: return this .type;
094: }
095:
096: public String getAdminData() {
097: return this .data;
098: }
099:
100: // Method that takes the internal data and returns a AdminInformation object required by the Authorization module.
101: public AdminInformation getAdminInformation() {
102: if (type == TYPE_CLIENTCERT_USER)
103: return new AdminInformation(certificate);
104:
105: return new AdminInformation(ADMINTYPETOADMINENTITY[type]);
106: }
107:
108: /**
109: * Method thar returns the caid of the CA, the admin belongs to.
110: * Doesn't work properly for public web and special users so use with care.
111: */
112:
113: public int getCaId() {
114: int returnval = LogConstants.INTERNALCAID;
115: if (type == TYPE_CLIENTCERT_USER)
116: returnval = CertTools.getIssuerDN(certificate).hashCode();
117: return returnval;
118: }
119:
120: public String toString() {
121: if ((type > -1) && (type < ADMINTYPETEXTS.length - 1)) {
122: return ADMINTYPETEXTS[type];
123: }
124: return "UNKNOWN";
125: }
126:
127: }
|