Search in sources :

Example 31 with BasicAttribute

use of javax.naming.directory.BasicAttribute in project OpenAM by OpenRock.

the class SMSEntry method addAttribute.

/**
     * Adds the attribute value to the given attribute name. It is stored
     * locally and is not written to the directory.
     */
public void addAttribute(String attrName, String value) throws SMSException {
    Set attrValues = null;
    if (attrSet == null) {
        attrSet = new CaseInsensitiveHashMap();
    } else if (attrSet.containsKey(attrName)) {
        attrValues = (Set) attrSet.get(attrName);
        if (attrValues.contains(value)) {
            // Value is already present
            if (debug.messageEnabled()) {
                debug.message("SMSEntry: Duplicate value for addition");
            }
            throw (new SMSException(LdapException.newLdapException(ResultCode.ATTRIBUTE_OR_VALUE_EXISTS, getBundleString(IUMSConstants.SMS_ATTR_OR_VAL_EXISTS)), "sms-ATTR_OR_VAL_EXISTS"));
        }
    }
    // Add the attribute to attrset
    if (attrValues == null) {
        attrValues = new HashSet();
    }
    attrValues.add(value);
    attrSet.put(attrName, attrValues);
    // Check if the modification set exists, and add the attribute
    if (modSet == null) {
        modSet = new HashSet();
    }
    modSet.add(new ModificationItem(DirContext.ADD_ATTRIBUTE, new BasicAttribute(attrName, value)));
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) CaseInsensitiveHashMap(com.sun.identity.common.CaseInsensitiveHashMap) CaseInsensitiveHashSet(com.sun.identity.common.CaseInsensitiveHashSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 32 with BasicAttribute

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

the class LdapConnectorImpl method createUser.

//-----------------------USER MODIFICATION METHODS----------------------------
public void createUser(User user) 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("person");
    objClasses.add("organizationalPerson");
    objClasses.add("inetOrgPerson");
    objClasses.add("perunUser");
    objClasses.add("tenOperEntry");
    objClasses.add("inetUser");
    String firstName = user.getFirstName();
    String lastName = user.getLastName();
    if (firstName == null)
        firstName = "";
    if (lastName == null || lastName.isEmpty())
        lastName = "N/A";
    // Add attributes
    attributes.put(objClasses);
    attributes.put("entryStatus", "active");
    attributes.put("sn", lastName);
    attributes.put("cn", firstName + " " + lastName);
    if (!firstName.isEmpty())
        attributes.put("givenName", firstName);
    attributes.put("perunUserId", String.valueOf(user.getId()));
    if (user.isServiceUser())
        attributes.put("isServiceUser", "1");
    else
        attributes.put("isServiceUser", "0");
    if (user.isSponsoredUser())
        attributes.put("isSponsoredUser", "1");
    else
        attributes.put("isSponsoredUser", "0");
    // Create the entry
    try {
        ldapTemplate.bind(getUserDN(String.valueOf(user.getId())), null, attributes);
        log.debug("New entry created in LDAP: User {} in Group with Id=" + user.getId() + ".", user);
    } 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 33 with BasicAttribute

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

the class LdapConnectorImpl method removeGroup.

public void removeGroup(Group group) throws InternalErrorException {
    List<String> uniqueUsersIds = new ArrayList<String>();
    uniqueUsersIds = this.getAllUniqueMembersInGroup(group.getId(), group.getVoId());
    for (String s : uniqueUsersIds) {
        Attribute memberOf = new BasicAttribute("memberOf", "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
        ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
        this.updateUserWithUserId(s, new ModificationItem[] { memberOfItem });
    }
    try {
        ldapTemplate.unbind(getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())));
        log.debug("Entry deleted from LDAP: Group {} from Vo with ID=" + group.getVoId() + ".", group);
    } catch (NameNotFoundException e) {
        throw new InternalErrorException(e);
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) NameNotFoundException(org.springframework.ldap.NameNotFoundException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 34 with BasicAttribute

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

the class LdapConnectorImpl method removeMemberFromGroup.

public void removeMemberFromGroup(Member member, Group group) throws InternalErrorException {
    //Remove member from group
    Attribute uniqueMember = new BasicAttribute("uniqueMember", "perunUserId=" + member.getUserId() + ",ou=People," + ldapProperties.getLdapBase());
    ModificationItem uniqueMemberItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, uniqueMember);
    this.updateGroup(group, new ModificationItem[] { uniqueMemberItem });
    //Remove member from vo if this group is membersGroup
    if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
        //Remove info from vo
        this.updateVo(group.getVoId(), new ModificationItem[] { uniqueMemberItem });
        //Remove also information from user
        Attribute memberOfPerunVo = new BasicAttribute("memberOfPerunVo", String.valueOf(group.getVoId()));
        ModificationItem memberOfPerunVoItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOfPerunVo);
        this.updateUserWithUserId(String.valueOf(member.getUserId()), new ModificationItem[] { memberOfPerunVoItem });
    }
    //Remove group info from member
    Attribute memberOf = new BasicAttribute("memberOf", "perunGroupId=" + group.getId() + ",perunVoId=" + group.getVoId() + "," + ldapProperties.getLdapBase());
    ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_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 35 with BasicAttribute

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

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