Search in sources :

Example 41 with BasicAttributes

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;
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute)

Example 42 with BasicAttributes

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);
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) HashMap(java.util.HashMap) Map(java.util.Map) CertificateException(java.security.cert.CertificateException) NamingException(javax.naming.NamingException) CRLException(java.security.cert.CRLException)

Aggregations

BasicAttributes (javax.naming.directory.BasicAttributes)42 BasicAttribute (javax.naming.directory.BasicAttribute)32 Attribute (javax.naming.directory.Attribute)25 Attributes (javax.naming.directory.Attributes)25 Test (org.junit.Test)9 File (java.io.File)7 HashSet (java.util.HashSet)7 MutablePartitionConfiguration (org.apache.directory.server.core.configuration.MutablePartitionConfiguration)7 AbstractBootstrapSchema (org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema)7 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 DirContext (javax.naming.directory.DirContext)5 PrivkeySchema (org.nhindirect.ldap.PrivkeySchema)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 Hashtable (java.util.Hashtable)4 NamingException (javax.naming.NamingException)4 SearchControls (javax.naming.directory.SearchControls)4 SearchResult (javax.naming.directory.SearchResult)4 Lookup (org.nhindirect.stagent.cert.impl.util.Lookup)4 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)3