📄 endentityprofile.java
字号:
/************************************************************************* * * * EJBCA: The OpenSource Certificate Authority * * * * This software is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or any later version. * * * * See terms of license at gnu.org. * * * *************************************************************************/ package org.ejbca.core.model.ra.raadmin;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import org.apache.commons.lang.StringUtils;import org.apache.log4j.Logger;import org.ejbca.core.model.InternalResources;import org.ejbca.core.model.SecConst;import org.ejbca.core.model.UpgradeableDataHashMap;import org.ejbca.util.Base64;import org.ejbca.util.StringTools;import org.ejbca.util.dn.DNFieldExtractor;import org.ejbca.util.dn.DnComponents;import org.ejbca.util.passgen.PasswordGeneratorFactory;/** * The model representation of an end entity profile, used in in the ra module * of ejbca web interface. * * The algorithm for constants in the EndEntityProfile is: * Values are stored as 100*parameternumber+parameter, so the first COMMONNAME value is 105, the second 205 etc. * Use flags are stored as 10000+100*parameternumber+parameter, so the first USE_COMMONNAME value is 10105, the second 10205 etc. * Required flags are stored as 20000+100*parameternumber+parameter, so the first REQUIRED_COMMONNAME value is 20105, the second 20205 etc. * Modifyable flags are stored as 30000+100*parameternumber+parameter, so the first MODIFYABLE_COMMONNAME value is 30105, the second 30205 etc. * * * @author Philip Vendil * @version $Id: EndEntityProfile.java,v 1.17 2007/01/16 11:43:52 anatom Exp $ */public class EndEntityProfile extends UpgradeableDataHashMap implements java.io.Serializable, Cloneable { private static final Logger log = Logger.getLogger(EndEntityProfile.class); /** Internal localization of logs and errors */ private static final InternalResources intres = InternalResources.getInstance(); public static final float LATEST_VERSION = 6; /** * Determines if a de-serialized file is compatible with this class. * * Maintainers must change this value if and only if the new version * of this class is not compatible with old versions. See Sun docs * for <a href=http://java.sun.com/products/jdk/1.1/docs/guide * /serialization/spec/version.doc.html> details. </a> * */ private static final long serialVersionUID = -8356152324295231461L; // Public constants /** Constant values for end entity profile. */ private static HashMap dataConstants = new HashMap(); // Default values // These must be in a strict order that can never change // Custom values configurable in a properties file will start at number 100 static { dataConstants.put("USERNAME", new Integer(0)); dataConstants.put("PASSWORD", new Integer(1)); dataConstants.put("CLEARTEXTPASSWORD", new Integer(2)); // DN components /* These are loaded through DnComponents instead dataConstants.put(DnComponents.DNEMAIL, Integer.valueOf(3)); dataConstants.put(DnComponents.UID, Integer.valueOf(4)); dataConstants.put(DnComponents.COMMONNAME, Integer.valueOf(5)); dataConstants.put(DnComponents.SN, Integer.valueOf(6)); dataConstants.put(DnComponents.GIVENNAME, Integer.valueOf(7)); dataConstants.put(DnComponents.INITIALS, Integer.valueOf(8)); dataConstants.put(DnComponents.SURNAME, Integer.valueOf(9)); dataConstants.put(DnComponents.TITLE, Integer.valueOf(10)); dataConstants.put(DnComponents.ORGANIZATIONUNIT, Integer.valueOf(11)); dataConstants.put(DnComponents.ORGANIZATION, Integer.valueOf(12)); dataConstants.put(DnComponents.LOCALE, Integer.valueOf(13)); dataConstants.put(DnComponents.STATE, Integer.valueOf(14)); dataConstants.put(DnComponents.DOMAINCOMPONENT, Integer.valueOf(15)); dataConstants.put(DnComponents.COUNTRY, Integer.valueOf(16)); dataConstants.put(DnComponents.UNSTRUCTUREDADDRESS, Integer.valueOf(39)); dataConstants.put(DnComponents.UNSTRUCTUREDNAME, Integer.valueOf(40)); // AltNames dataConstants.put(DnComponents.RFC822NAME, Integer.valueOf(17)); dataConstants.put(DnComponents.DNSNAME, Integer.valueOf(18)); dataConstants.put(DnComponents.IPADDRESS, Integer.valueOf(19)); dataConstants.put(DnComponents.OTHERNAME, Integer.valueOf(20)); dataConstants.put(DnComponents.UNIFORMRESOURCEID, Integer.valueOf(21)); dataConstants.put(DnComponents.X400ADDRESS, Integer.valueOf(22)); dataConstants.put(DnComponents.DIRECTORYNAME, Integer.valueOf(23)); dataConstants.put(DnComponents.EDIPARTNAME, Integer.valueOf(24)); dataConstants.put(DnComponents.REGISTEREDID, Integer.valueOf(25)); dataConstants.put(DnComponents.UPN, Integer.valueOf(36)); dataConstants.put(DnComponents.GUID, Integer.valueOf(41)); // Altnames end // Subject directory attributes dataConstants.put(DnComponents.DATEOFBIRTH, Integer.valueOf(42)); dataConstants.put(DnComponents.PLACEOFBIRTH, Integer.valueOf(43)); dataConstants.put(DnComponents.GENDER, Integer.valueOf(44)); dataConstants.put(DnComponents.COUNTRYOFCITIZENSHIP, Integer.valueOf(45)); dataConstants.put(DnComponents.COUNTRYOFRESIDENCE, Integer.valueOf(46)); // Subject directory attributes end */ dataConstants.put("EMAIL", new Integer(26)); dataConstants.put("ADMINISTRATOR", new Integer(27)); dataConstants.put("KEYRECOVERABLE", new Integer(28)); dataConstants.put("DEFAULTCERTPROFILE", new Integer(29)); dataConstants.put("AVAILCERTPROFILES", new Integer(30)); dataConstants.put("DEFKEYSTORE", new Integer(31)); dataConstants.put("AVAILKEYSTORE", new Integer(32)); dataConstants.put("DEFAULTTOKENISSUER", new Integer(33)); dataConstants.put("AVAILTOKENISSUER", new Integer(34)); dataConstants.put("SENDNOTIFICATION", new Integer(35)); dataConstants.put("DEFAULTCA", new Integer(37)); dataConstants.put("AVAILCAS", new Integer(38)); // Load all DN, altName and directoryAttributes from DnComponents. dataConstants.putAll(DnComponents.getProfilenameIdMap()); } // Type of data constants. private static final int VALUE = 0; private static final int USE = 1; private static final int ISREQUIRED = 2; private static final int MODIFYABLE = 3; // Field constants, used in the map above public static final String USERNAME = "USERNAME"; public static final String PASSWORD = "PASSWORD"; public static final String CLEARTEXTPASSWORD = "CLEARTEXTPASSWORD"; public static final String EMAIL = "EMAIL"; public static final String ADMINISTRATOR = "ADMINISTRATOR"; public static final String KEYRECOVERABLE = "KEYRECOVERABLE"; public static final String DEFAULTCERTPROFILE = "DEFAULTCERTPROFILE"; public static final String AVAILCERTPROFILES = "AVAILCERTPROFILES"; public static final String DEFKEYSTORE = "DEFKEYSTORE"; public static final String AVAILKEYSTORE = "AVAILKEYSTORE"; public static final String DEFAULTTOKENISSUER = "DEFAULTTOKENISSUER"; public static final String AVAILTOKENISSUER = "AVAILTOKENISSUER"; public static final String SENDNOTIFICATION = "SENDNOTIFICATION"; public static final String DEFAULTCA = "DEFAULTCA"; public static final String AVAILCAS = "AVAILCAS"; public static final String SPLITCHAR = ";"; public static final String TRUE = "true"; public static final String FALSE = "false"; // Constants used with field ordering public static final int FIELDTYPE = 0; public static final int NUMBER = 1; // Public methods. /** Creates a new instance of EndEntity Profile */ public EndEntityProfile() { super(); // Set default required fields. init(false); } /** Creates a default empty end entity profile with all standard fields added to it. */ public EndEntityProfile(boolean emptyprofile){ super(); init(emptyprofile); } private void init(boolean emptyprofile){ if(emptyprofile){ // initialize profile data ArrayList numberoffields = new ArrayList(dataConstants.size()); for(int i =0; i < dataConstants.size(); i++){ numberoffields.add(new Integer(0)); } data.put(NUMBERARRAY,numberoffields); data.put(SUBJECTDNFIELDORDER,new ArrayList()); data.put(SUBJECTALTNAMEFIELDORDER,new ArrayList()); data.put(SUBJECTDIRATTRFIELDORDER,new ArrayList()); Set keySet = dataConstants.keySet(); Iterator iter = keySet.iterator(); while (iter.hasNext()) { String key = (String)iter.next(); if (key.equals(SENDNOTIFICATION) || key.equals(DnComponents.OTHERNAME) || key.equals(DnComponents.X400ADDRESS) || key.equals(DnComponents.EDIPARTNAME) || key.equals(DnComponents.REGISTEREDID)) { continue; } else { addField(key); setValue(key,0,""); setRequired(key,0,false); setUse(key,0,true); setModifyable(key,0,true); } } setRequired(USERNAME,0,true); setRequired(PASSWORD,0,true); setRequired(DnComponents.COMMONNAME,0,true); setRequired(DEFAULTCERTPROFILE,0,true); setRequired(AVAILCERTPROFILES,0,true); setRequired(DEFKEYSTORE,0,true); setRequired(AVAILKEYSTORE,0,true); setRequired(DEFAULTCA,0,true); setRequired(AVAILCAS,0,true); setValue(DEFAULTCERTPROFILE,0,"1"); setValue(AVAILCERTPROFILES,0,"1"); setValue(DEFKEYSTORE,0, "" + SecConst.TOKEN_SOFT_BROWSERGEN); setValue(AVAILKEYSTORE,0, SecConst.TOKEN_SOFT_BROWSERGEN + ";" + SecConst.TOKEN_SOFT_P12 + ";" + SecConst.TOKEN_SOFT_JKS + ";" + SecConst.TOKEN_SOFT_PEM); setValue(AVAILCAS,0, Integer.toString(SecConst.ALLCAS)); // Do not use hard token issuers by default. setUse(AVAILTOKENISSUER, 0, false); }else{ // initialize profile data ArrayList numberoffields = new ArrayList(dataConstants.size()); for(int i =0; i < dataConstants.size(); i++){ numberoffields.add(new Integer(0)); } data.put(NUMBERARRAY,numberoffields); data.put(SUBJECTDNFIELDORDER,new ArrayList()); data.put(SUBJECTALTNAMEFIELDORDER,new ArrayList()); data.put(SUBJECTDIRATTRFIELDORDER,new ArrayList()); addField(USERNAME); addField(PASSWORD); addField(DnComponents.COMMONNAME); addField(EMAIL); addField(DEFAULTCERTPROFILE); addField(AVAILCERTPROFILES); addField(DEFKEYSTORE); addField(AVAILKEYSTORE); addField(DEFAULTTOKENISSUER); addField(AVAILTOKENISSUER); addField(AVAILCAS); addField(DEFAULTCA); setRequired(USERNAME,0,true); setRequired(PASSWORD,0,true); setRequired(DnComponents.COMMONNAME,0,true); setRequired(DEFAULTCERTPROFILE,0,true); setRequired(AVAILCERTPROFILES,0,true); setRequired(DEFKEYSTORE,0,true); setRequired(AVAILKEYSTORE,0,true); setRequired(DEFAULTCA,0,true); setRequired(AVAILCAS,0,true); setValue(DEFAULTCERTPROFILE,0,"1"); setValue(AVAILCERTPROFILES,0,"1;2;3"); setValue(DEFKEYSTORE,0, "" + SecConst.TOKEN_SOFT_BROWSERGEN); setValue(AVAILKEYSTORE,0, SecConst.TOKEN_SOFT_BROWSERGEN + ";" + SecConst.TOKEN_SOFT_P12 + ";" + SecConst.TOKEN_SOFT_JKS + ";" + SecConst.TOKEN_SOFT_PEM); // Do not use hard token issuers by default. setUse(AVAILTOKENISSUER, 0, false); } } public void addField(String parameter){ addField(getParameterNumber(parameter)); } /** * Function that adds a field to the profile. * * @param paramter is the field and one of the field constants. */ public void addField(int parameter){ int size = getNumberOfField(parameter);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -