diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/profile/def/GenericExtDefault.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cms/profile/def/GenericExtDefault.java | 126 |
1 files changed, 73 insertions, 53 deletions
diff --git a/pki/base/common/src/com/netscape/cms/profile/def/GenericExtDefault.java b/pki/base/common/src/com/netscape/cms/profile/def/GenericExtDefault.java index eb18d5ea1..4051f31a4 100644 --- a/pki/base/common/src/com/netscape/cms/profile/def/GenericExtDefault.java +++ b/pki/base/common/src/com/netscape/cms/profile/def/GenericExtDefault.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cms.profile.def; + import java.util.Locale; import netscape.security.util.DerOutputStream; @@ -33,10 +34,12 @@ import com.netscape.certsrv.property.EPropertyException; import com.netscape.certsrv.property.IDescriptor; import com.netscape.certsrv.request.IRequest; + /** - * This class implements an enrollment default policy that populates a Netscape - * comment extension into the certificate template. - * + * This class implements an enrollment default policy + * that populates a Netscape comment extension + * into the certificate template. + * * @version $Revision$, $Date$ */ public class GenericExtDefault extends EnrollExtDefault { @@ -59,19 +62,22 @@ public class GenericExtDefault extends EnrollExtDefault { } public void init(IProfile profile, IConfigStore config) - throws EProfileException { + throws EProfileException { super.init(profile, config); } - public IDescriptor getConfigDescriptor(Locale locale, String name) { + public IDescriptor getConfigDescriptor(Locale locale, String name) { if (name.equals(CONFIG_CRITICAL)) { - return new Descriptor(IDescriptor.BOOLEAN, null, "false", + return new Descriptor(IDescriptor.BOOLEAN, null, + "false", CMS.getUserMessage(locale, "CMS_PROFILE_CRITICAL")); } else if (name.equals(CONFIG_OID)) { - return new Descriptor(IDescriptor.STRING, null, "Comment Here...", + return new Descriptor(IDescriptor.STRING, null, + "Comment Here...", CMS.getUserMessage(locale, "CMS_PROFILE_OID")); } else if (name.equals(CONFIG_DATA)) { - return new Descriptor(IDescriptor.STRING, null, "Comment Here...", + return new Descriptor(IDescriptor.STRING, null, + "Comment Here...", CMS.getUserMessage(locale, "CMS_PROFILE_EXT_VALUE")); } else { return null; @@ -80,51 +86,57 @@ public class GenericExtDefault extends EnrollExtDefault { public IDescriptor getValueDescriptor(Locale locale, String name) { if (name.equals(VAL_CRITICAL)) { - return new Descriptor(IDescriptor.BOOLEAN, null, "false", + return new Descriptor(IDescriptor.BOOLEAN, null, + "false", CMS.getUserMessage(locale, "CMS_PROFILE_CRITICAL")); } else if (name.equals(VAL_DATA)) { - return new Descriptor(IDescriptor.STRING_LIST, null, null, + return new Descriptor(IDescriptor.STRING_LIST, null, + null, CMS.getUserMessage(locale, "CMS_PROFILE_EXT_VALUE")); } else { return null; } } - public void setValue(String name, Locale locale, X509CertInfo info, - String value) throws EPropertyException { + public void setValue(String name, Locale locale, + X509CertInfo info, String value) + throws EPropertyException { try { Extension ext = null; if (name == null) { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } ObjectIdentifier oid = new ObjectIdentifier(getConfig(CONFIG_OID)); - ext = (Extension) getExtension(oid.toString(), info); + ext = (Extension) + getExtension(oid.toString(), info); - if (ext == null) { - populate(null, info); + if(ext == null) { + populate(null,info); } if (name.equals(VAL_CRITICAL)) { - ext = (Extension) getExtension(oid.toString(), info); - if (ext == null) { + ext = (Extension) + getExtension(oid.toString(), info); + if (ext == null) { return; } boolean val = Boolean.valueOf(value).booleanValue(); - ext.setCritical(val); - } else if (name.equals(VAL_DATA)) { - ext = (Extension) getExtension(oid.toString(), info); - if (ext == null) { + ext.setCritical(val); + } else if (name.equals(VAL_DATA)) { + ext = (Extension) + getExtension(oid.toString(), info); + if (ext == null) { return; } byte data[] = getBytes(value); - ext.setExtensionValue(data); + ext.setExtensionValue(data); } else { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } replaceExtension(ext.getExtensionId().toString(), ext, info); @@ -133,33 +145,37 @@ public class GenericExtDefault extends EnrollExtDefault { } } - public String getValue(String name, Locale locale, X509CertInfo info) - throws EPropertyException { + public String getValue(String name, Locale locale, + X509CertInfo info) + throws EPropertyException { Extension ext = null; if (name == null) { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } ObjectIdentifier oid = new ObjectIdentifier(getConfig(CONFIG_OID)); - ext = (Extension) getExtension(oid.toString(), info); + ext = (Extension) + getExtension(oid.toString(), info); - if (ext == null) { + if(ext == null) + { try { - populate(null, info); + populate(null,info); } catch (EProfileException e) { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } } if (name.equals(VAL_CRITICAL)) { - ext = (Extension) getExtension(oid.toString(), info); + ext = (Extension) + getExtension(oid.toString(), info); if (ext == null) { return null; @@ -169,9 +185,10 @@ public class GenericExtDefault extends EnrollExtDefault { } else { return "false"; } - } else if (name.equals(VAL_DATA)) { + } else if (name.equals(VAL_DATA)) { - ext = (Extension) getExtension(oid.toString(), info); + ext = (Extension) + getExtension(oid.toString(), info); if (ext == null) return ""; @@ -180,29 +197,31 @@ public class GenericExtDefault extends EnrollExtDefault { if (data == null) return ""; - + return toStr(data); } else { - throw new EPropertyException(CMS.getUserMessage(locale, - "CMS_INVALID_PROPERTY", name)); + throw new EPropertyException(CMS.getUserMessage( + locale, "CMS_INVALID_PROPERTY", name)); } } public String getText(Locale locale) { - String params[] = { getConfig(CONFIG_CRITICAL), getConfig(CONFIG_OID), - getConfig(CONFIG_DATA) }; + String params[] = { + getConfig(CONFIG_CRITICAL), + getConfig(CONFIG_OID), + getConfig(CONFIG_DATA) + }; - return CMS - .getUserMessage(locale, "CMS_PROFILE_DEF_GENERIC_EXT", params); + return CMS.getUserMessage(locale, "CMS_PROFILE_DEF_GENERIC_EXT", params); } public String toStr(byte data[]) { StringBuffer b = new StringBuffer(); for (int i = 0; i < data.length; i++) { - if ((data[i] & 0xff) < 16) { - b.append("0"); - } - b.append(Integer.toString((int) (data[i] & 0xff), 0x10)); + if ((data[i] & 0xff) < 16) { + b.append("0"); + } + b.append(Integer.toString((int)(data[i] & 0xff), 0x10)); } return b.toString(); } @@ -211,14 +230,14 @@ public class GenericExtDefault extends EnrollExtDefault { * Populates the request with this policy default. */ public void populate(IRequest request, X509CertInfo info) - throws EProfileException { + throws EProfileException { Extension ext = createExtension(request); addExtension(ext.getExtensionId().toString(), ext, info); } public Extension createExtension(IRequest request) { - Extension ext = null; + Extension ext = null; try { boolean critical = getConfigBoolean(CONFIG_CRITICAL); @@ -231,12 +250,13 @@ public class GenericExtDefault extends EnrollExtDefault { data = getBytes(mapPattern(request, getConfig(CONFIG_DATA))); } - DerOutputStream out = new DerOutputStream(); + DerOutputStream out = new DerOutputStream(); out.putOctetString(data); ext = new Extension(oid, critical, out.toByteArray()); } catch (Exception e) { - CMS.debug("GenericExtDefault: createExtension " + e.toString()); + CMS.debug("GenericExtDefault: createExtension " + + e.toString()); } return ext; } |