Search in sources :

Example 16 with ModificationItem

use of javax.naming.directory.ModificationItem 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 17 with ModificationItem

use of javax.naming.directory.ModificationItem 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 18 with ModificationItem

use of javax.naming.directory.ModificationItem 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 19 with ModificationItem

use of javax.naming.directory.ModificationItem in project camel by apache.

the class SpringLdapProducer method process.

/**
     * Performs the LDAP operation defined in SpringLdapEndpoint that created
     * this producer. The in-message in the exchange must be a map, containing
     * the following entries:
     * 
     * <pre>
     * key: "dn" - base DN for the LDAP operation
     * key: "filter" - necessary for the search operation only; LDAP filter for the search operation,
     * see <a http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol>http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol</a>
     * key: "attributes" - necessary for the bind operation only; an instance of javax.naming.directory.Attributes,
     * containing the information necessary to create an LDAP node.
     * key: "password" - necessary for the authentication operation only;
     * key: "modificationItems" - necessary for the modify_attributes operation only;
     * key: "function" - necessary for the function_driven operation only; provides a flexible hook into the {@link LdapTemplate} to call any method
     * key: "request" - necessary for the function_driven operation only; passed into the "function" to enable the client to bind parameters that need to be passed into the {@link LdapTemplate}
     * </pre>
     * 
     * The keys are defined as final fields above.
     */
@Override
public void process(Exchange exchange) throws Exception {
    @SuppressWarnings("unchecked") Map<String, Object> body = exchange.getIn().getBody(Map.class);
    LdapOperation operation = endpoint.getOperation();
    if (null == operation) {
        throw new UnsupportedOperationException("LDAP operation must not be empty, but you provided an empty operation");
    }
    String dn = (String) body.get(DN);
    if (operation != LdapOperation.FUNCTION_DRIVEN && (StringUtils.isBlank(dn))) {
        throw new UnsupportedOperationException("DN must not be empty, but you provided an empty DN");
    }
    LdapOperations ldapTemplate = endpoint.getLdapTemplate();
    switch(operation) {
        case SEARCH:
            String filter = (String) body.get(FILTER);
            exchange.getIn().setBody(ldapTemplate.search(dn, filter, endpoint.scopeValue(), mapper));
            break;
        case BIND:
            Attributes attributes = (Attributes) body.get(ATTRIBUTES);
            ldapTemplate.bind(dn, null, attributes);
            break;
        case UNBIND:
            ldapTemplate.unbind(dn);
            break;
        case AUTHENTICATE:
            ldapTemplate.authenticate(LdapQueryBuilder.query().base(dn).filter((String) body.get(FILTER)), (String) body.get(PASSWORD));
            break;
        case MODIFY_ATTRIBUTES:
            ModificationItem[] modificationItems = (ModificationItem[]) body.get(MODIFICATION_ITEMS);
            ldapTemplate.modifyAttributes(dn, modificationItems);
            break;
        case FUNCTION_DRIVEN:
            BiFunction<LdapOperations, Object, ?> ldapOperationFunction = (BiFunction<LdapOperations, Object, ?>) body.get(FUNCTION);
            Object ldapOperationRequest = body.get(REQUEST);
            exchange.getIn().setBody(ldapOperationFunction.apply(ldapTemplate, ldapOperationRequest));
            break;
        default:
            throw new UnsupportedOperationException("Bug in the Spring-LDAP component. Despite of all assertions, you managed to call an unsupported operation '" + operation + "'");
    }
}
Also used : ModificationItem(javax.naming.directory.ModificationItem) BiFunction(java.util.function.BiFunction) LdapOperations(org.springframework.ldap.core.LdapOperations) Attributes(javax.naming.directory.Attributes)

Example 20 with ModificationItem

use of javax.naming.directory.ModificationItem in project fess by codelibs.

the class LdapManager method modifyDeleteEntry.

protected void modifyDeleteEntry(final List<ModificationItem> modifyList, final String name, final Object value) {
    final Attribute attr = new BasicAttribute(name, value);
    final ModificationItem mod = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr);
    modifyList.add(mod);
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) ModificationItem(javax.naming.directory.ModificationItem) BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute)

Aggregations

ModificationItem (javax.naming.directory.ModificationItem)24 BasicAttribute (javax.naming.directory.BasicAttribute)20 Attribute (javax.naming.directory.Attribute)12 ArrayList (java.util.ArrayList)5 NamingException (javax.naming.NamingException)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 DirContext (javax.naming.directory.DirContext)4 CaseInsensitiveHashSet (com.sun.identity.common.CaseInsensitiveHashSet)3 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)3 SMSException (com.sun.identity.sm.SMSException)3 Hashtable (java.util.Hashtable)3 LinkedHashSet (java.util.LinkedHashSet)3 Attributes (javax.naming.directory.Attributes)3 InitialDirContext (javax.naming.directory.InitialDirContext)3 LdapOperationException (org.codelibs.fess.exception.LdapOperationException)3 Base64 (java.util.Base64)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2