📄 dncomponents.java
字号:
public static String dnIdToProfileName(int dnid) { String val = (String)dnIdToProfileNameMap.get(new Integer(dnid)); return val; } public static int dnIdToProfileId(int dnid) { Integer val = (Integer)dnIdToProfileIdMap.get(new Integer(dnid)); return val.intValue(); } /** * Method to get a language error constant for the admin-GUI from a profile name */ public static String getLanguageConstantFromProfileName(String name) { String ret = (String)profileNameLanguageMap.get(name); return ret; } /** * Method to get a language error constant for the admin-GUI from a profile id */ public static String getLanguageConstantFromProfileId(int id) { String ret = (String)profileIdLanguageMap.get(new Integer(id)); return ret; } /** * Method to get a clear text error msg for the admin-GUI from a dn id */ public static String getErrTextFromDnId(int id) { String ret = (String)dnIdErrorMap.get(new Integer(id)); return ret; } /** This method is only used to initialize EndEntityProfile, because of legacy baggage. * Should be refactored sometime! Please don't use this whatever you do! * @return */ public static HashMap getProfilenameIdMap() { return profileNameIdMap; } /** A function that takes an fieldid pointing to a coresponding id in UserView and DnFieldExctractor. * For example : profileFieldIdToUserFieldIdMapper(EndEntityProfile.COMMONNAME) returns DnFieldExctractor.COMMONNAME. * * Should only be used with subjectDN, Subject Alternative Names and subject directory attribute fields. */ public static int profileIdToDnId(int profileid) { Integer val = (Integer)profileIdToDnIdMap.get(new Integer(profileid)); if (val == null) { log.error("No dn id mapping from profile id "+profileid); // We allow it to fail here } return val.intValue(); } /** * Returns the dnObject (forward or reverse) that is in use */ public static String[]getDnObjects() { if (!reverseOrder) { return dNObjectsForward; } return getDnObjectsReverse(); } /** * Returns the reversed dnObjects. * Protected to allow testing */ protected static String[] getDnObjectsReverse() { // Create and reverse the order if it has not been initialized already if (dNObjectsReverse == null) { // this cast is not needed in java 5, but is needed for java 1.4 dNObjectsReverse = (String[])dNObjectsForward.clone(); ArrayUtils.reverse(dNObjectsReverse); } return dNObjectsReverse; } private static void load() { loadOrdering(); loadMappings(); } /** * Load DN ordering used in CertTools.stringToBCDNString etc. * Loads from file placed in src/dncomponents.properties * * A line is: * DNName;DNid;ProfileName;ProfileId,ErrorString,LanguageConstant * */ private static void loadMappings() { // Read the file to an array of lines String line; BufferedReader in = null; InputStreamReader inf = null; try { InputStream is = obj.getClass().getResourceAsStream("/profilemappings.properties"); //log.info("is is: " + is); if (is != null) { inf = new InputStreamReader(is); //inf = new FileReader("c:\\foo.properties"); in = new BufferedReader(inf); if (!in.ready()) throw new IOException(); String[] splits = null; int lines = 0; while ((line = in.readLine()) != null) { if (!line.startsWith("#")) { // # is a comment line splits = StringUtils.split(line, ';'); if ( (splits != null) && (splits.length > 5) ) { String type = splits[0]; String dnname = splits[1]; Integer dnid = new Integer(splits[2]); String profilename = splits[3]; Integer profileid = new Integer(splits[4]); String errstr = splits[5]; String langstr = splits[6]; // Fill maps dnNameIdMap.put(dnname, dnid); profileNameIdMap.put(profilename, profileid); dnIdToProfileNameMap.put(dnid, profilename); dnIdToProfileIdMap.put(dnid, profileid); dnIdErrorMap.put(dnid, errstr); profileIdToDnIdMap.put(profileid, dnid); dnErrorTextMap.put(dnid, errstr); profileNameLanguageMap.put(profilename, langstr); profileIdLanguageMap.put(profileid, langstr); if (type.equals("DN")) { dnProfileFields.add(profilename); dnLanguageTexts.add(langstr); dnDnIds.add(dnid); dnExtractorFields.add(dnname+"="); dnIdToExtractorFieldMap.put(dnid, dnname+"="); } if (type.equals("ALTNAME")) { altNameFields.add(dnname); altNameLanguageTexts.add(langstr); altNameDnIds.add(dnid); altNameExtractorFields.add(dnname+"="); altNameIdToExtractorFieldMap.put(dnid, dnname+"="); } if (type.equals("DIRATTR")) { dirAttrFields.add(dnname); dirAttrLanguageTexts.add(langstr); dirAttrDnIds.add(dnid); dirAttrExtractorFields.add(dnname+"="); dirAttrIdToExtractorFieldMap.put(dnid, dnname+"="); } lines++; } } } in.close(); log.debug("Read profile maps with "+lines+" lines."); } else { throw new IOException("Input stream for /profilemappings.properties is null"); } } catch (IOException e) { log.error("Can not load profile mappings: ", e); } finally { try { if (inf != null) inf.close(); if (in != null) in.close(); } catch (IOException e) {} } } /** * Load DN ordering used in CertTools.stringToBCDNString etc. * Loads from file placed in src/dncomponents.properties * */ private static void loadOrdering() { // Read the file to an array of lines String line; LinkedHashMap map = new LinkedHashMap(); BufferedReader in = null; InputStreamReader inf = null; try { InputStream is = obj.getClass().getResourceAsStream("/dncomponents.properties"); //log.info("is is: " + is); if (is != null) { inf = new InputStreamReader(is); //inf = new FileReader("c:\\foo.properties"); in = new BufferedReader(inf); if (!in.ready()) throw new IOException(); String[] splits = null; while ((line = in.readLine()) != null) { if (!line.startsWith("#")) { // # is a comment line splits = StringUtils.split(line, '='); if ( (splits != null) && (splits.length > 1) ) { String name = splits[0]; DERObjectIdentifier oid = new DERObjectIdentifier(splits[1]); map.put(name, oid); } } } in.close(); // Now we have read it in, transfer it to the main oid map log.info("Using DN components from properties file"); oids.clear(); oids.putAll(map); Set keys = map.keySet(); // Set the maps to the desired ordering dNObjectsForward = (String[])keys.toArray(new String[0]); } else { log.debug("Using default values for DN components"); } } catch (IOException e) { log.debug("Using default values for DN components"); } finally { try { if (inf != null) inf.close(); if (in != null) in.close(); } catch (IOException e) {} } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -