summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cms/profile/def/SubjectDirAttributesExtDefault.java
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/profile/def/SubjectDirAttributesExtDefault.java')
-rw-r--r--pki/base/common/src/com/netscape/cms/profile/def/SubjectDirAttributesExtDefault.java272
1 files changed, 143 insertions, 129 deletions
diff --git a/pki/base/common/src/com/netscape/cms/profile/def/SubjectDirAttributesExtDefault.java b/pki/base/common/src/com/netscape/cms/profile/def/SubjectDirAttributesExtDefault.java
index aecbdc8c1..0259fb36e 100644
--- a/pki/base/common/src/com/netscape/cms/profile/def/SubjectDirAttributesExtDefault.java
+++ b/pki/base/common/src/com/netscape/cms/profile/def/SubjectDirAttributesExtDefault.java
@@ -43,9 +43,10 @@ import com.netscape.certsrv.property.IDescriptor;
import com.netscape.certsrv.request.IRequest;
/**
- * This class implements an enrollment default policy that populates a subject
- * directory attributes extension into the certificate template.
- *
+ * This class implements an enrollment default policy
+ * that populates a subject directory attributes extension
+ * into the certificate template.
+ *
* @version $Revision$, $Date$
*/
public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
@@ -70,7 +71,7 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
}
public void init(IProfile profile, IConfigStore config)
- throws EProfileException {
+ throws EProfileException {
super.init(profile, config);
refreshConfigAndValueNames();
}
@@ -93,25 +94,27 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
return num;
}
- public void setConfig(String name, String value) throws EPropertyException {
+ public void setConfig(String name, String value)
+ throws EPropertyException {
int num = 0;
if (name.equals(DEF_NUM_ATTRS)) {
- try {
- num = Integer.parseInt(value);
+ try {
+ num = Integer.parseInt(value);
- if (num >= MAX_NUM_ATTRS || num < 0) {
- throw new EPropertyException(CMS.getUserMessage(
+ if (num >= MAX_NUM_ATTRS || num < 0) {
+ throw new EPropertyException(CMS.getUserMessage(
"CMS_INVALID_PROPERTY", CONFIG_NUM_ATTRS));
- }
+ }
- } catch (Exception e) {
+ } catch (Exception e) {
throw new EPropertyException(CMS.getUserMessage(
- "CMS_INVALID_PROPERTY", CONFIG_NUM_ATTRS));
- }
+ "CMS_INVALID_PROPERTY", CONFIG_NUM_ATTRS));
+ }
}
super.setConfig(name, value);
}
+
public Enumeration getConfigNames() {
refreshConfigAndValueNames();
return super.getConfigNames();
@@ -133,82 +136,93 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
}
}
- public IDescriptor getConfigDescriptor(Locale locale, String name) {
- if (name.equals(CONFIG_CRITICAL)) {
- return new Descriptor(IDescriptor.BOOLEAN, null, "false",
+ public IDescriptor getConfigDescriptor(Locale locale, String name) {
+ if (name.equals(CONFIG_CRITICAL)) {
+ return new Descriptor(IDescriptor.BOOLEAN, null,
+ "false",
CMS.getUserMessage(locale, "CMS_PROFILE_CRITICAL"));
} else if (name.startsWith(CONFIG_ATTR_NAME)) {
- return new Descriptor(IDescriptor.STRING, null, null,
+ return new Descriptor(IDescriptor.STRING, null,
+ null,
CMS.getUserMessage(locale, "CMS_PROFILE_NUM_ATTRS"));
} else if (name.startsWith(CONFIG_ATTR_NAME)) {
- return new Descriptor(IDescriptor.STRING, null, null,
+ return new Descriptor(IDescriptor.STRING, null,
+ null,
CMS.getUserMessage(locale, "CMS_PROFILE_ATTR_NAME"));
} else if (name.startsWith(CONFIG_PATTERN)) {
- return new Descriptor(IDescriptor.STRING, null, null,
+ return new Descriptor(IDescriptor.STRING, null,
+ null,
CMS.getUserMessage(locale, "CMS_PROFILE_ATTR_VALUE"));
} else if (name.startsWith(CONFIG_ENABLE)) {
- return new Descriptor(IDescriptor.BOOLEAN, null, null,
+ return new Descriptor(IDescriptor.BOOLEAN, null,
+ null,
CMS.getUserMessage(locale, "CMS_PROFILE_ENABLE"));
} else if (name.startsWith(CONFIG_NUM_ATTRS)) {
- return new Descriptor(IDescriptor.INTEGER, null, "1",
- CMS.getUserMessage(locale, "CMS_PROFILE_NUM_ATTRS"));
- }
+ return new Descriptor(IDescriptor.INTEGER, null,
+ "1",
+ CMS.getUserMessage(locale, "CMS_PROFILE_NUM_ATTRS"));
+ }
return null;
}
public IDescriptor getValueDescriptor(Locale locale, String name) {
- if (name.equals(VAL_CRITICAL)) {
- return new Descriptor(IDescriptor.BOOLEAN, null, "false",
+ if (name.equals(VAL_CRITICAL)) {
+ return new Descriptor(IDescriptor.BOOLEAN, null,
+ "false",
CMS.getUserMessage(locale, "CMS_PROFILE_CRITICAL"));
} else if (name.equals(VAL_ATTR)) {
- return new Descriptor(IDescriptor.STRING_LIST, null, null,
+ return new Descriptor(IDescriptor.STRING_LIST, null,
+ null,
CMS.getUserMessage(locale, "CMS_PROFILE_SUBJDIR_ATTRS"));
} 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 {
SubjectDirAttributesExtension ext = null;
- if (name == null) {
- throw new EPropertyException(CMS.getUserMessage(locale,
- "CMS_INVALID_PROPERTY", name));
+ if (name == null) {
+ throw new EPropertyException(CMS.getUserMessage(
+ locale, "CMS_INVALID_PROPERTY", name));
}
- ext = (SubjectDirAttributesExtension) getExtension(
- PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
- info);
+ ext = (SubjectDirAttributesExtension)
+ getExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
+ info);
if (name.equals(VAL_CRITICAL)) {
- ext = (SubjectDirAttributesExtension) getExtension(
- PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
- info);
+ ext = (SubjectDirAttributesExtension)
+ getExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
+ info);
boolean val = Boolean.valueOf(value).booleanValue();
- if (ext == null) {
+ if(ext == null)
+ {
return;
}
- ext.setCritical(val);
- } else if (name.equals(VAL_ATTR)) {
- ext = (SubjectDirAttributesExtension) getExtension(
- PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
- info);
-
- if (ext == null) {
+ ext.setCritical(val);
+ } else if (name.equals(VAL_ATTR)) {
+ ext = (SubjectDirAttributesExtension)
+ getExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
+ info);
+
+ if(ext == null)
+ {
return;
}
Vector v = parseRecords(value);
int size = v.size();
-
+
boolean critical = ext.isCritical();
X500NameAttrMap map = X500NameAttrMap.getDefault();
Vector attrV = new Vector();
- for (int i = 0; i < size; i++) {
+ for (int i=0; i < size; i++) {
NameValuePairs nvps = (NameValuePairs) v.elementAt(i);
Enumeration names = nvps.getNames();
String attrName = null;
@@ -227,8 +241,8 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
}
if (enable.equals("true")) {
- AttributeConfig attributeConfig = new AttributeConfig(
- attrName, attrValue);
+ AttributeConfig attributeConfig =
+ new AttributeConfig(attrName, attrValue);
Attribute attr = attributeConfig.mAttribute;
if (attr != null)
attrV.addElement(attr);
@@ -242,42 +256,43 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
} else
return;
} else {
- throw new EPropertyException(CMS.getUserMessage(locale,
- "CMS_INVALID_PROPERTY", name));
+ throw new EPropertyException(CMS.getUserMessage(
+ locale, "CMS_INVALID_PROPERTY", name));
}
- replaceExtension(
- PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
- ext, info);
+ replaceExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
+ ext, info);
} catch (EProfileException e) {
- CMS.debug("SubjectDirAttributesExtDefault: setValue "
- + e.toString());
- throw new EPropertyException(CMS.getUserMessage(locale,
- "CMS_INVALID_PROPERTY", name));
+ CMS.debug("SubjectDirAttributesExtDefault: setValue " +
+ e.toString());
+ throw new EPropertyException(CMS.getUserMessage(
+ locale, "CMS_INVALID_PROPERTY", name));
} catch (IOException e) {
- CMS.debug("SubjectDirAttributesExtDefault: setValue "
- + e.toString());
- throw new EPropertyException(CMS.getUserMessage(locale,
- "CMS_INVALID_PROPERTY", name));
+ CMS.debug("SubjectDirAttributesExtDefault: setValue " +
+ e.toString());
+ throw new EPropertyException(CMS.getUserMessage(
+ locale, "CMS_INVALID_PROPERTY", name));
}
}
- public String getValue(String name, Locale locale, X509CertInfo info)
- throws EPropertyException {
+ public String getValue(String name, Locale locale,
+ X509CertInfo info)
+ throws EPropertyException {
SubjectDirAttributesExtension 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));
}
- ext = (SubjectDirAttributesExtension) getExtension(
- PKIXExtensions.SubjectDirectoryAttributes_Id.toString(), info);
+ ext = (SubjectDirAttributesExtension)
+ getExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
+ info);
if (name.equals(VAL_CRITICAL)) {
- ext = (SubjectDirAttributesExtension) getExtension(
- PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
- info);
+ ext = (SubjectDirAttributesExtension)
+ getExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
+ info);
if (ext == null) {
return null;
@@ -287,10 +302,10 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
} else {
return "false";
}
- } else if (name.equals(VAL_ATTR)) {
- ext = (SubjectDirAttributesExtension) getExtension(
- PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
- info);
+ } else if (name.equals(VAL_ATTR)) {
+ ext = (SubjectDirAttributesExtension)
+ getExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
+ info);
if (ext == null)
return "";
@@ -300,45 +315,42 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
Vector recs = new Vector();
int num = getNumAttrs();
Enumeration e = ext.getAttributesList();
- CMS.debug("SubjectDirAttributesExtDefault: getValue: attributesList="
- + e);
- int i = 0;
+ CMS.debug("SubjectDirAttributesExtDefault: getValue: attributesList="+e);
+ int i=0;
while (e.hasMoreElements()) {
NameValuePairs pairs = new NameValuePairs();
pairs.add(ENABLE, "true");
- Attribute attr = (Attribute) (e.nextElement());
- CMS.debug("SubjectDirAttributesExtDefault: getValue: attribute="
- + attr);
+ Attribute attr = (Attribute)(e.nextElement());
+ CMS.debug("SubjectDirAttributesExtDefault: getValue: attribute="+attr);
ObjectIdentifier oid = attr.getOid();
- CMS.debug("SubjectDirAttributesExtDefault: getValue: oid="
- + oid);
-
+ CMS.debug("SubjectDirAttributesExtDefault: getValue: oid="+oid);
+
String vv = map.getName(oid);
- if (vv != null)
+ if (vv != null)
pairs.add(ATTR_NAME, vv);
else
pairs.add(ATTR_NAME, oid.toString());
Enumeration v = attr.getValues();
-
+
// just support single value for now
StringBuffer ss = new StringBuffer();
while (v.hasMoreElements()) {
if (ss.length() == 0)
- ss.append((String) (v.nextElement()));
+ ss.append((String)(v.nextElement()));
else {
ss.append(",");
- ss.append((String) (v.nextElement()));
+ ss.append((String)(v.nextElement()));
}
}
- pairs.add(ATTR_VALUE, ss.toString());
+ pairs .add(ATTR_VALUE, ss.toString());
recs.addElement(pairs);
i++;
}
-
- for (; i < num; i++) {
+
+ for (;i < num; i++) {
NameValuePairs pairs = new NameValuePairs();
pairs.add(ENABLE, "false");
pairs.add(ATTR_NAME, "GENERATIONQUALIFIER");
@@ -348,8 +360,8 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
return buildRecords(recs);
} else {
- throw new EPropertyException(CMS.getUserMessage(locale,
- "CMS_INVALID_PROPERTY", name));
+ throw new EPropertyException(CMS.getUserMessage(
+ locale, "CMS_INVALID_PROPERTY", name));
}
}
@@ -371,50 +383,52 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
sb.append(getConfig(CONFIG_ENABLE + i));
sb.append("}");
}
- return CMS.getUserMessage(locale,
- "CMS_PROFILE_DEF_SUBJECT_DIR_ATTR_EXT",
- getConfig(CONFIG_CRITICAL), sb.toString());
+ return CMS.getUserMessage(locale,
+ "CMS_PROFILE_DEF_SUBJECT_DIR_ATTR_EXT",
+ getConfig(CONFIG_CRITICAL),
+ sb.toString());
}
/**
* Populates the request with this policy default.
*/
public void populate(IRequest request, X509CertInfo info)
- throws EProfileException {
+ throws EProfileException {
SubjectDirAttributesExtension ext = createExtension(request);
if (ext == null)
return;
- addExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
- ext, info);
+ addExtension(PKIXExtensions.SubjectDirectoryAttributes_Id.toString(),
+ ext, info);
}
public SubjectDirAttributesExtension createExtension(IRequest request)
- throws EProfileException {
- SubjectDirAttributesExtension ext = null;
+ throws EProfileException {
+ SubjectDirAttributesExtension ext = null;
int num = 0;
boolean critical = getConfigBoolean(CONFIG_CRITICAL);
num = getNumAttrs();
-
+
AttributeConfig attributeConfig = null;
Vector attrs = new Vector();
for (int i = 0; i < num; i++) {
- String enable = getConfig(CONFIG_ENABLE + i);
+ String enable = getConfig(CONFIG_ENABLE + i);
if (enable != null && enable.equals("true")) {
String attrName = getConfig(CONFIG_ATTR_NAME + i);
- String pattern = getConfig(CONFIG_PATTERN + i);
+ String pattern = getConfig(CONFIG_PATTERN + i);
if (pattern == null || pattern.equals(""))
pattern = " ";
- // check pattern syntax
+ //check pattern syntax
int startpos = pattern.indexOf("$");
int lastpos = pattern.lastIndexOf("$");
String attrValue = pattern;
- if (!pattern.equals("") && startpos != -1 && startpos == 0
- && lastpos != -1 && lastpos == (pattern.length() - 1)) {
+ if (!pattern.equals("") && startpos != -1 &&
+ startpos == 0 && lastpos != -1 &&
+ lastpos == (pattern.length()-1)) {
if (request != null) {
try {
attrValue = mapPattern(request, pattern);
@@ -422,7 +436,7 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
throw new EProfileException(e.toString());
}
}
- }
+ }
try {
attributeConfig = new AttributeConfig(attrName, attrValue);
} catch (EPropertyException e) {
@@ -439,7 +453,8 @@ public class SubjectDirAttributesExtDefault extends EnrollExtDefault {
Attribute[] attrList = new Attribute[attrs.size()];
attrs.copyInto(attrList);
try {
- ext = new SubjectDirAttributesExtension(attrList, critical);
+ ext =
+ new SubjectDirAttributesExtension(attrList, critical);
} catch (IOException e) {
throw new EProfileException(e.toString());
}
@@ -455,52 +470,51 @@ class AttributeConfig {
protected Attribute mAttribute = null;
public AttributeConfig(String attrName, String attrValue)
- throws EPropertyException {
+ throws EPropertyException {
X500NameAttrMap map = X500NameAttrMap.getDefault();
-
+
if (attrName == null || attrName.length() == 0) {
- throw new EPropertyException(CMS.getUserMessage(
- "CMS_PROFILE_SUBJDIR_EMPTY_ATTRNAME", attrName));
+ throw new EPropertyException(
+ CMS.getUserMessage("CMS_PROFILE_SUBJDIR_EMPTY_ATTRNAME", attrName));
}
-
+
if (attrValue == null || attrValue.length() == 0) {
- throw new EPropertyException(CMS.getUserMessage(
- "CMS_PROFILE_SUBJDIR_EMPTY_ATTRVAL", attrValue));
+ throw new EPropertyException(
+ CMS.getUserMessage("CMS_PROFILE_SUBJDIR_EMPTY_ATTRVAL", attrValue));
}
try {
mAttributeOID = new ObjectIdentifier(attrName);
} catch (Exception e) {
- CMS.debug("SubjectDirAttributesExtDefault: invalid OID syntax: "
- + attrName);
+ CMS.debug("SubjectDirAttributesExtDefault: invalid OID syntax: "+ attrName);
}
if (mAttributeOID == null) {
mAttributeOID = map.getOid(attrName);
if (mAttributeOID == null)
- throw new EPropertyException(CMS.getUserMessage(
- "CMS_BASE_INVALID_ATTRIBUTE", attrName));
+ throw new EPropertyException(
+ CMS.getUserMessage("CMS_BASE_INVALID_ATTRIBUTE", attrName));
try {
checkValue(mAttributeOID, attrValue);
} catch (IOException e) {
throw new EPropertyException(CMS.getUserMessage(
- "CMS_BASE_INVALID_ATTR_VALUE", e.getMessage()));
+ "CMS_BASE_INVALID_ATTR_VALUE", e.getMessage()));
}
}
+
try {
- mAttribute = new Attribute(mAttributeOID,
- str2MultiValues(attrValue));
+ mAttribute = new Attribute(mAttributeOID,
+ str2MultiValues(attrValue));
} catch (IOException e) {
throw new EPropertyException(CMS.getUserMessage(
- "CMS_BASE_INVALID_ATTR_VALUE", e.getMessage()));
+ "CMS_BASE_INVALID_ATTR_VALUE", e.getMessage()));
}
}
- private static void checkValue(ObjectIdentifier oid, String val)
- throws IOException {
- AVAValueConverter c = X500NameAttrMap.getDefault().getValueConverter(
- oid);
+ private static void checkValue(ObjectIdentifier oid, String val)
+ throws IOException {
+ AVAValueConverter c = X500NameAttrMap.getDefault().getValueConverter(oid);
DerValue derval;
derval = c.getValue(val); // errs encountered will get thrown.
@@ -513,7 +527,7 @@ class AttributeConfig {
while (tokenizer.hasMoreTokens()) {
v.addElement(tokenizer.nextToken());
}
-
+
return v;
}
}