1 13 14 19 20 package org.ejbca.core.model.log; 21 22 23 import java.io.Serializable ; 24 import java.security.cert.X509Certificate ; 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 37 public class Admin implements Serializable { 38 39 48 private static final long serialVersionUID = -9221031402622809524L; 49 50 53 public static final int TYPE_CLIENTCERT_USER = 0; 54 55 public static final int TYPE_PUBLIC_WEB_USER = 1; 56 57 public static final int TYPE_RA_USER = 2; 58 59 public static final int TYPE_CACOMMANDLINE_USER = 3; 60 61 public static final int TYPE_BATCHCOMMANDLINE_USER = 4; 62 63 public static final int TYPE_INTERNALUSER = 5; 64 65 public static final int SPECIAL_ADMIN_BOUNDRARY = 100; 66 67 public static final String [] 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 data; 75 private X509Certificate certificate; 76 77 public Admin(X509Certificate 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 ip) { 84 this.type = type; 85 this.data = ip; 86 } 87 88 public Admin(int type) { 89 this(type, null); 90 } 91 92 93 95 public int getAdminType() { 96 return this.type; 97 } 98 99 public String getAdminData() { 100 return this.data; 101 } 102 103 public AdminInformation getAdminInformation() { 105 if (type == TYPE_CLIENTCERT_USER) 106 return new AdminInformation(certificate); 107 108 return new AdminInformation(ADMINTYPETOADMINENTITY[type]); 109 } 110 111 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 toString() { 123 if ((type > -1) && (type < ADMINTYPETEXTS.length-1)) { 124 return ADMINTYPETEXTS[type]; 125 } 126 return "UNKNOWN"; 127 } 128 129 } 130 | Popular Tags |