Search in sources :

Example 46 with BasicAttribute

use of javax.naming.directory.BasicAttribute in project JGroups by belaban.

the class MockDirContext method addEntry.

public MockDirContext addEntry(String dnsQuery, String dnsResponse, DNSResolver.DNSRecordType recordType) {
    Attributes attributes = responseMap.computeIfAbsent(new DNSKey(dnsQuery, recordType), v -> new BasicAttributes());
    Attribute attribute = attributes.get(recordType.toString());
    if (attribute == null) {
        attributes.put(new BasicAttribute(recordType.toString(), dnsResponse));
    } else {
        attribute.add(dnsResponse);
    }
    return this;
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Example 47 with BasicAttribute

use of javax.naming.directory.BasicAttribute 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 48 with BasicAttribute

use of javax.naming.directory.BasicAttribute in project Lucee by lucee.

the class LDAPClient method modify.

public void modify(String dn, int modifytype, String strAttributes, String delimiter, String separator) throws NamingException, PageException {
    DirContext context = new InitialDirContext(env);
    String[] strArrAttributes = toStringAttributes(strAttributes, delimiter);
    int count = 0;
    for (int i = 0; i < strArrAttributes.length; i++) {
        String[] attributesValues = getAttributesValues(strArrAttributes[i], separator);
        if (attributesValues == null)
            count++;
        else
            count += attributesValues.length;
    }
    ModificationItem[] modItems = new ModificationItem[count];
    BasicAttribute basicAttr = null;
    int k = 0;
    for (int i = 0; i < strArrAttributes.length; i++) {
        String attribute = strArrAttributes[i];
        String type = getAttrValueType(attribute);
        String[] values = getAttributesValues(attribute, separator);
        if (modifytype == DirContext.REPLACE_ATTRIBUTE) {
            if (values == null)
                basicAttr = new BasicAttribute(type);
            else
                basicAttr = new BasicAttribute(type, values[0]);
            modItems[k] = new ModificationItem(modifytype, basicAttr);
            k++;
            if (values != null && values.length > 1) {
                for (int j = 1; j < values.length; j++) {
                    basicAttr = new BasicAttribute(type, values[j]);
                    modItems[k] = new ModificationItem(DirContext.ADD_ATTRIBUTE, basicAttr);
                    k++;
                }
            }
        } else {
            for (int j = 0; j < values.length; j++) {
                if (type != null || modifytype == DirContext.ADD_ATTRIBUTE)
                    basicAttr = new BasicAttribute(type, values[j]);
                else
                    basicAttr = new BasicAttribute(values[j]);
                modItems[k] = new ModificationItem(modifytype, basicAttr);
                k++;
            }
        }
    }
    context.modifyAttributes(dn, modItems);
    context.close();
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) InitialDirContext(javax.naming.directory.InitialDirContext) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext)

Example 49 with BasicAttribute

use of javax.naming.directory.BasicAttribute 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)

Example 50 with BasicAttribute

use of javax.naming.directory.BasicAttribute in project Payara by payara.

the class ResourceAttributes method getAll.

/**
 * Get all attributes.
 */
public NamingEnumeration<? extends Attribute> getAll() {
    if (attributes == null) {
        Vector<BasicAttribute> attributes = new Vector<BasicAttribute>();
        Date creationDate = getCreationDate();
        if (creationDate != null) {
            attributes.addElement(new BasicAttribute(CREATION_DATE, creationDate));
            attributes.addElement(new BasicAttribute(ALTERNATE_CREATION_DATE, creationDate));
        }
        Date lastModifiedDate = getLastModifiedDate();
        if (lastModifiedDate != null) {
            attributes.addElement(new BasicAttribute(LAST_MODIFIED, lastModifiedDate));
            attributes.addElement(new BasicAttribute(ALTERNATE_LAST_MODIFIED, lastModifiedDate));
        }
        String name = getName();
        if (name != null) {
            attributes.addElement(new BasicAttribute(NAME, name));
        }
        String resourceType = getResourceType();
        if (resourceType != null) {
            attributes.addElement(new BasicAttribute(TYPE, resourceType));
            attributes.addElement(new BasicAttribute(ALTERNATE_TYPE, resourceType));
        }
        long contentLength = getContentLength();
        if (contentLength >= 0) {
            Long contentLengthLong = Long.valueOf(contentLength);
            attributes.addElement(new BasicAttribute(CONTENT_LENGTH, contentLengthLong));
            attributes.addElement(new BasicAttribute(ALTERNATE_CONTENT_LENGTH, contentLengthLong));
        }
        String etag = getETag();
        if (etag != null) {
            attributes.addElement(new BasicAttribute(ETAG, etag));
            attributes.addElement(new BasicAttribute(ALTERNATE_ETAG, etag));
        }
        return new RecyclableNamingEnumeration<BasicAttribute>(attributes);
    } else {
        return attributes.getAll();
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) Vector(java.util.Vector) Date(java.util.Date)

Aggregations

BasicAttribute (javax.naming.directory.BasicAttribute)50 Attribute (javax.naming.directory.Attribute)30 BasicAttributes (javax.naming.directory.BasicAttributes)28 Attributes (javax.naming.directory.Attributes)19 ModificationItem (javax.naming.directory.ModificationItem)18 HashSet (java.util.HashSet)14 File (java.io.File)7 Set (java.util.Set)7 MutablePartitionConfiguration (org.apache.directory.server.core.configuration.MutablePartitionConfiguration)7 AbstractBootstrapSchema (org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema)7 DirContext (javax.naming.directory.DirContext)6 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 PrivkeySchema (org.nhindirect.ldap.PrivkeySchema)5 Collections (java.util.Collections)4 Date (java.util.Date)4 NamingException (javax.naming.NamingException)4