Search in sources :

Example 81 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project hive by apache.

the class LdapTestUtils method mockAttributes.

private static Attributes mockAttributes(NameValues... namedValues) throws NamingException {
    Attributes attributes = new BasicAttributes();
    for (NameValues namedValue : namedValues) {
        Attribute attr = new BasicAttribute(namedValue.name);
        for (String value : namedValue.values) {
            attr.add(value);
        }
        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) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes)

Example 82 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project yyl_example by Relucent.

the class LdapDaoHelper method modify.

/**
 * 修改条目<br>
 * @param entry 修改的条目
 * @param ctx LDAP上下文连接
 * @deprecated 该方法未经过严谨测试
 */
public static void modify(LdapEntry entry, LdapContext ctx) throws NamingException {
    String dn = entry.getDn();
    Attributes attrs = new BasicAttributes(true);
    if (entry != null && !entry.isEmpty()) {
        Iterator<String> iterator = entry.keySet().iterator();
        while (iterator.hasNext()) {
            String id = iterator.next();
            Attribute attr = new BasicAttribute(id.toString());
            List<?> values = entry.getAll(id);
            if (values != null) {
                for (Object value : values) {
                    attr.add(value);
                }
            }
            attrs.put(attr);
        }
    }
    ctx.modifyAttributes(dn, DirContext.REPLACE_ATTRIBUTE, attrs);
}
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 83 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project jmeter by apache.

the class LDAPSampler method getUserAttributes.

/**
 * Collect all the value from the table (Arguments), using this create the
 * basicAttributes. This will create the Basic Attributes for the User
 * defined TestCase for Add Test.
 *
 * @return the BasicAttributes
 */
private BasicAttributes getUserAttributes() {
    // $NON-NLS-1$
    BasicAttribute basicattribute = new BasicAttribute("objectclass");
    // $NON-NLS-1$
    basicattribute.add("top");
    // $NON-NLS-1$
    basicattribute.add("person");
    // $NON-NLS-1$
    basicattribute.add("organizationalPerson");
    // $NON-NLS-1$
    basicattribute.add("inetOrgPerson");
    BasicAttributes attrs = new BasicAttributes(true);
    attrs.put(basicattribute);
    BasicAttribute attr;
    for (JMeterProperty jMeterProperty : getArguments()) {
        Argument item = (Argument) jMeterProperty.getObjectValue();
        attr = getBasicAttribute(item.getName(), item.getValue());
        attrs.put(attr);
    }
    return attrs;
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) JMeterProperty(org.apache.jmeter.testelement.property.JMeterProperty) Argument(org.apache.jmeter.config.Argument)

Example 84 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project cxf by apache.

the class LdapCertificateRepo method saveCertificate.

protected 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 85 with BasicAttributes

use of javax.naming.directory.BasicAttributes in project bw-calendar-engine by Bedework.

the class UserGroupsLdapImpl method getGroupMembers.

/* Find members for given group
   *
   */
private void getGroupMembers(final DirConfigProperties dirProps, final BwGroup group) throws CalFacadeException {
    LdapConfigProperties props = (LdapConfigProperties) dirProps;
    InitialLdapContext ctx = null;
    try {
        ctx = createLdapInitContext(props);
        BasicAttributes matchAttrs = new BasicAttributes(true);
        matchAttrs.put(props.getGroupIdAttr(), group.getAccount());
        String[] memberAttr = { props.getGroupMemberAttr() };
        ArrayList<String> mbrs = null;
        boolean beenHere = false;
        NamingEnumeration response = ctx.search(props.getGroupContextDn(), matchAttrs, memberAttr);
        while (response.hasMore()) {
            SearchResult sr = (SearchResult) response.next();
            Attributes attrs = sr.getAttributes();
            if (beenHere) {
                throw new CalFacadeException("org.bedework.ldap.groups.multiple.result");
            }
            beenHere = true;
            Attribute membersAttr = attrs.get(props.getGroupMemberAttr());
            mbrs = new ArrayList<String>();
            for (int m = 0; m < membersAttr.size(); m++) {
                mbrs.add(membersAttr.get(m).toString());
            }
        }
        // LDAP We need a way to search recursively for groups.
        /* Search for each user in the group */
        String memberContext = props.getGroupMemberContextDn();
        String memberSearchAttr = props.getGroupMemberSearchAttr();
        String[] idAttr = { props.getGroupMemberUserIdAttr(), props.getGroupMemberGroupIdAttr(), "objectclass" };
        for (String mbr : mbrs) {
            if (memberContext != null) {
                matchAttrs = new BasicAttributes(true);
                matchAttrs.put(memberSearchAttr, mbr);
                response = ctx.search(memberContext, matchAttrs, idAttr);
            } else {
                response = ctx.search(memberContext, null, idAttr);
            }
            if (response.hasMore()) {
                SearchResult sr = (SearchResult) response.next();
                Attributes attrs = sr.getAttributes();
                Attribute ocsAttr = attrs.get("objectclass");
                String userOc = props.getUserObjectClass();
                String groupOc = props.getGroupObjectClass();
                boolean isGroup = false;
                for (int oci = 0; oci < ocsAttr.size(); oci++) {
                    String oc = ocsAttr.get(oci).toString();
                    if (userOc.equals(oc)) {
                        break;
                    }
                    if (groupOc.equals(oc)) {
                        isGroup = true;
                        break;
                    }
                }
                BwPrincipal p = null;
                Attribute attr;
                if (isGroup) {
                    p = BwPrincipal.makeGroupPrincipal();
                    attr = attrs.get(props.getGroupMemberGroupIdAttr());
                } else {
                    p = BwPrincipal.makeUserPrincipal();
                    attr = attrs.get(props.getGroupMemberUserIdAttr());
                }
                if (attr.size() != 1) {
                    throw new CalFacadeException("org.bedework.ldap.groups.multiple.result");
                }
                p.setAccount(attr.get(0).toString());
                p.setPrincipalRef(makePrincipalUri(p.getAccount(), p.getKind()));
                group.addGroupMember(p);
            }
        }
    } catch (Throwable t) {
        if (debug) {
            error(t);
        }
        throw new CalFacadeException(t);
    } finally {
        // Close the context to release the connection
        if (ctx != null) {
            closeContext(ctx);
        }
    }
    for (BwGroup g : group.getGroups()) {
        getGroupMembers(props, g);
    }
}
Also used : BasicAttributes(javax.naming.directory.BasicAttributes) BwGroup(org.bedework.calfacade.BwGroup) Attribute(javax.naming.directory.Attribute) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) NamingEnumeration(javax.naming.NamingEnumeration) SearchResult(javax.naming.directory.SearchResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) InitialLdapContext(javax.naming.ldap.InitialLdapContext) LdapConfigProperties(org.bedework.calfacade.configs.LdapConfigProperties)

Aggregations

BasicAttributes (javax.naming.directory.BasicAttributes)100 Attributes (javax.naming.directory.Attributes)62 BasicAttribute (javax.naming.directory.BasicAttribute)57 Attribute (javax.naming.directory.Attribute)44 Test (org.junit.Test)22 SearchResult (javax.naming.directory.SearchResult)21 DirContext (javax.naming.directory.DirContext)18 NamingException (javax.naming.NamingException)15 InitialDirContext (javax.naming.directory.InitialDirContext)14 NamingEnumeration (javax.naming.NamingEnumeration)12 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)10 LdapContext (javax.naming.ldap.LdapContext)9 HashMap (java.util.HashMap)8 InitialLdapContext (javax.naming.ldap.InitialLdapContext)8 File (java.io.File)7 Map (java.util.Map)7 MutablePartitionConfiguration (org.apache.directory.server.core.configuration.MutablePartitionConfiguration)7 AbstractBootstrapSchema (org.apache.directory.server.core.schema.bootstrap.AbstractBootstrapSchema)7 IOException (java.io.IOException)6