use of javax.naming.directory.BasicAttributes in project Lucee by lucee.
the class LDAPClient method toAttributes.
private static Attributes toAttributes(String strAttributes, String delimiter, String separator) throws PageException {
String[] arrAttr = toStringAttributes(strAttributes, delimiter);
BasicAttributes attributes = new BasicAttributes();
for (int i = 0; i < arrAttr.length; i++) {
String strAttr = arrAttr[i];
// Type
int eqIndex = strAttr.indexOf('=');
Attribute attr = new BasicAttribute((eqIndex != -1) ? strAttr.substring(0, eqIndex).trim() : null);
// Value
String strValue = (eqIndex != -1) ? strAttr.substring(eqIndex + 1) : strAttr;
String[] arrValue = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(strValue, separator));
// Fill
for (int y = 0; y < arrValue.length; y++) {
attr.add(arrValue[y]);
}
attributes.put(attr);
}
return attributes;
}
use of javax.naming.directory.BasicAttributes in project cxf by apache.
the class LdapCertificateRepo method saveCertificate.
private void saveCertificate(X509Certificate cert, String dn, Map<String, String> appAttrs) {
Attributes attribs = new BasicAttributes();
attribs.put(new BasicAttribute(ATTR_OBJECT_CLASS, ldapConfig.getCertObjectClass()));
attribs.put(new BasicAttribute(ldapConfig.getAttrUID(), cert.getSubjectX500Principal().getName()));
attribs.put(new BasicAttribute(ldapConfig.getAttrIssuerID(), cert.getIssuerX500Principal().getName()));
attribs.put(new BasicAttribute(ldapConfig.getAttrSerialNumber(), cert.getSerialNumber().toString(16)));
addConstantAttributes(ldapConfig.getConstAttrNamesCSV(), ldapConfig.getConstAttrValuesCSV(), attribs);
if (appAttrs != null && !appAttrs.isEmpty()) {
for (Map.Entry<String, String> entry : appAttrs.entrySet()) {
attribs.put(new BasicAttribute(entry.getKey(), entry.getValue()));
}
}
try {
attribs.put(new BasicAttribute(ldapConfig.getAttrCrtBinary(), cert.getEncoded()));
ldapSearch.bind(dn, attribs);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
Aggregations