Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ldap.core.support;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ldap.core.IncrementalAttributesMapper;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.support.LdapUtils;
import javax.naming.Name;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Utility class that helps with reading all attribute values from Active Directory using Incremental Retrieval of
* Multi-valued Properties.
*
Example usage of this attribute mapper:
*
* List values = DefaultIncrementalAttributeMapper.lookupAttributeValues(ldapTemplate, theDn, "oneAttribute");
* Attributes attrs = DefaultIncrementalAttributeMapper.lookupAttributeValues(ldapTemplate, theDn, new Object[]{"oneAttribute", "anotherAttribute"});
*
* For greater control, e.g. explicitly specifying the requested page size, create and use an instance yourself:
*
*
* IncrementalAttributesMapper incrementalAttributeMapper = new DefaultIncrementalAttributeMapper(10, "someAttribute");
* while (incrementalAttributeMapper.hasMore()) {
* ldap.lookup(entrDn, incrementalAttributeMapper.getAttributesForLookup(), incrementalAttributeMapper);
* }
*
* List values = incrementalAttributeMapper.getValues("someAttribute");
*
*
* NOTE: Instances of this class are highly stateful and must not be reused or shared between threads in any way.
*
* NOTE: Instances of this class can only be used with lookups. No support is given for searches.
*
*
* @author Marius Scurtescu
* @author Mattias Hellborg Arthursson
* @see Incremental Retrieval of Multi-valued Properties
* @see #lookupAttributes(org.springframework.ldap.core.LdapOperations, javax.naming.Name, String[])
* @see #lookupAttributeValues(org.springframework.ldap.core.LdapOperations, javax.naming.Name, String)
* @since 1.3.2
*/
public class DefaultIncrementalAttributesMapper implements IncrementalAttributesMapper {
private final static Logger LOG = LoggerFactory.getLogger(DefaultIncrementalAttributesMapper.class);
private Map stateMap = new LinkedHashMap();
private Set rangedAttributesInNextIteration = new LinkedHashSet();
/**
* This guy will be used when an unmapped attribute is encountered. This really should never happen,
* but this saves us a number of null checks.
*/
private static final IncrementalAttributeState NOT_FOUND_ATTRIBUTE_STATE = new IncrementalAttributeState() {
@Override
public String getRequestedAttributeName() {
throw new UnsupportedOperationException("This method should never be called");
}
@Override
public boolean hasMore() {
return false;
}
@Override
public void calculateNextRange(RangeOption responseRange) {
// Nothing to do here
}
@Override
public String getAttributeNameForQuery() {
throw new UnsupportedOperationException("This method should never be called");
}
@Override
public void processValues(Attributes attributes, String attributeName) throws NamingException {
// Nothing to do here
}
@Override
public List