Search in sources :

Example 16 with BasicAttribute

use of javax.naming.directory.BasicAttribute in project perun by CESNET.

the class LdapConnectorImpl method addGroup.

//------------------GROUP MODIFICATION METHODS-------------------------------
public void addGroup(Group group) throws InternalErrorException {
    // Create a set of attributes
    Attributes attributes = new BasicAttributes();
    // Create the objectclass to add
    Attribute objClasses = new BasicAttribute("objectClass");
    objClasses.add("top");
    objClasses.add("perunGroup");
    // Add attributes
    attributes.put(objClasses);
    attributes.put("cn", group.getName());
    attributes.put("perunGroupId", String.valueOf(group.getId()));
    attributes.put("perunUniqueGroupName", new String(this.getVoShortName(group.getVoId()) + ":" + group.getName()));
    attributes.put("perunVoId", String.valueOf(group.getVoId()));
    if (group.getDescription() != null && !group.getDescription().isEmpty())
        attributes.put("description", group.getDescription());
    if (group.getParentGroupId() != null) {
        attributes.put("perunParentGroup", "perunGroupId=" + group.getParentGroupId().toString() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
        attributes.put("perunParentGroupId", group.getParentGroupId().toString());
    }
    // Create the entry
    try {
        ldapTemplate.bind(getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())), null, attributes);
        log.debug("New entry created in LDAP: Group {} in Vo with Id=" + group.getVoId() + ".", group);
    } catch (NameNotFoundException e) {
        throw new InternalErrorException(e);
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) NameNotFoundException(org.springframework.ldap.NameNotFoundException) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 17 with BasicAttribute

use of javax.naming.directory.BasicAttribute in project perun by CESNET.

the class LdapConnectorImpl method createVo.

//--------------------------VO MODIFICATION METHODS---------------------------
public void createVo(Vo vo) throws InternalErrorException {
    // Create a set of attributes for vo
    Attributes voAttributes = new BasicAttributes();
    // Create the objectclass to add
    Attribute voObjClasses = new BasicAttribute("objectClass");
    voObjClasses.add("top");
    voObjClasses.add("organization");
    voObjClasses.add("perunVO");
    // Add attributes
    voAttributes.put(voObjClasses);
    voAttributes.put("o", vo.getShortName());
    voAttributes.put("description", vo.getName());
    voAttributes.put("perunVoId", String.valueOf(vo.getId()));
    // Create the entires
    try {
        ldapTemplate.bind(getVoDNByVoId(String.valueOf(vo.getId())), null, voAttributes);
        log.debug("New entry created in LDAP: Vo {}.", vo);
    } catch (NameNotFoundException e) {
        throw new InternalErrorException(e);
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) NameNotFoundException(org.springframework.ldap.NameNotFoundException) BasicAttributes(javax.naming.directory.BasicAttributes) Attributes(javax.naming.directory.Attributes) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 18 with BasicAttribute

use of javax.naming.directory.BasicAttribute in project perun by CESNET.

the class LdapConnectorImpl method addMemberToGroup.

//-----------------------------MEMBER MODIFICATION METHODS--------------------
public void addMemberToGroup(Member member, Group group) throws InternalErrorException {
    //Add member to group
    Attribute uniqueMember = new BasicAttribute("uniqueMember", "perunUserId=" + member.getUserId() + ",ou=People," + ldapProperties.getLdapBase());
    ModificationItem uniqueMemberItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, uniqueMember);
    this.updateGroup(group, new ModificationItem[] { uniqueMemberItem });
    //Add member to vo if this group is memebrsGroup
    if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
        //Add info to vo
        this.updateVo(group.getVoId(), new ModificationItem[] { uniqueMemberItem });
        //Add info also to user
        Attribute memberOfPerunVo = new BasicAttribute("memberOfPerunVo", String.valueOf(group.getVoId()));
        ModificationItem memberOfPerunVoItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, memberOfPerunVo);
        this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfPerunVoItem });
    }
    //Add group info to member
    Attribute memberOf = new BasicAttribute("memberOf", "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
    ModificationItem memberOfItem = new ModificationItem(DirContext.ADD_ATTRIBUTE, memberOf);
    this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfItem });
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute)

Example 19 with BasicAttribute

use of javax.naming.directory.BasicAttribute in project jackrabbit-oak by apache.

the class InternalLdapServer method addMembers.

public void addMembers(String groupDN, Iterable<String> memberDNs) throws Exception {
    LdapContext ctxt = getWiredContext();
    Attribute attr = new BasicAttribute("member");
    for (String dn : memberDNs) {
        attr.add(dn);
    }
    BasicAttributes attrs = new BasicAttributes();
    attrs.put(attr);
    ctxt.modifyAttributes(groupDN, DirContext.ADD_ATTRIBUTE, attrs);
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) BasicAttributes(javax.naming.directory.BasicAttributes) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) LdapContext(javax.naming.ldap.LdapContext)

Example 20 with BasicAttribute

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

the class LDAPExtSampler method getUserModAttributes.

/***************************************************************************
     * 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 Modify test
     *
     * @return The BasicAttributes
     **************************************************************************/
private ModificationItem[] getUserModAttributes() {
    ModificationItem[] mods = new ModificationItem[getLDAPArguments().getArguments().size()];
    BasicAttribute attr;
    PropertyIterator iter = getLDAPArguments().iterator();
    int count = 0;
    while (iter.hasNext()) {
        LDAPArgument item = (LDAPArgument) iter.next().getObjectValue();
        if ((item.getValue()).length() == 0) {
            attr = new BasicAttribute(item.getName());
        } else {
            attr = getBasicAttribute(item.getName(), item.getValue());
        }
        final String opcode = item.getOpcode();
        if ("add".equals(opcode)) {
            // $NON-NLS-1$
            mods[count++] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr);
        } else if (// $NON-NLS-1$
        "delete".equals(opcode) || "remove".equals(opcode)) {
            // $NON-NLS-1$
            mods[count++] = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr);
        } else if ("replace".equals(opcode)) {
            // $NON-NLS-1$
            mods[count++] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr);
        } else {
            log.warn("Invalid opCode: " + opcode);
        }
    }
    return mods;
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) PropertyIterator(org.apache.jmeter.testelement.property.PropertyIterator) LDAPArgument(org.apache.jmeter.protocol.ldap.config.gui.LDAPArgument)

Aggregations

BasicAttribute (javax.naming.directory.BasicAttribute)44 Attribute (javax.naming.directory.Attribute)28 BasicAttributes (javax.naming.directory.BasicAttributes)25 Attributes (javax.naming.directory.Attributes)17 ModificationItem (javax.naming.directory.ModificationItem)17 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 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 DirContext (javax.naming.directory.DirContext)5 Test (org.junit.Test)5 PrivkeySchema (org.nhindirect.ldap.PrivkeySchema)5 Collections (java.util.Collections)4 Date (java.util.Date)3 Enumeration (java.util.Enumeration)3