Converted opendj3 code to use SearchRequest like API
InternalSearchOperation.java:
Added 2 constructors using SearchRequest.
Made one constructor private.
| | |
| | | InternalSearchOperation search; |
| | | try |
| | | { |
| | | SearchRequest request = Requests.newSearchRequest(baseDN, SearchScope.BASE_OBJECT, "objectclass=*") |
| | | SearchRequest request = Requests.newSearchRequest(DN.valueOf(baseDN), SearchScope.BASE_OBJECT) |
| | | .addAttribute(attrName); |
| | | search = internalConnection.processSearch(request); |
| | | if (search.getResultCode() != ResultCode.SUCCESS) |
| | |
| | | */ |
| | | package org.opends.server.authorization.dseecompat; |
| | | |
| | | import java.util.*; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.SortedSet; |
| | | import java.util.concurrent.locks.Lock; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.api.ConfigHandler; |
| | | import org.opends.server.backends.jeb.EntryContainer; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.opends.server.controls.GetEffectiveRightsRequestControl; |
| | | import org.opends.server.core.*; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.workflowelement.localbackend.*; |
| | |
| | | import static org.opends.server.authorization.dseecompat.Aci.*; |
| | | import static org.opends.server.authorization.dseecompat.EnumEvalReason.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.schema.SchemaConstants.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | |
| | | */ |
| | | private void processConfigAcis() throws InitializationException |
| | | { |
| | | Set<String> requestAttrs = new LinkedHashSet<String>(1); |
| | | requestAttrs.add("aci"); |
| | | LinkedList<LocalizableMessage> failedACIMsgs = new LinkedList<LocalizableMessage>(); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | ConfigHandler configBackend = DirectoryServer.getConfigHandler(); |
| | | ConfigHandler<?> configBackend = DirectoryServer.getConfigHandler(); |
| | | for (DN baseDN : configBackend.getBaseDNs()) |
| | | { |
| | | try |
| | |
| | | } |
| | | |
| | | try { |
| | | InternalSearchOperation internalSearch = new InternalSearchOperation( |
| | | conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | null, baseDN, SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("aci=*"), requestAttrs, null); |
| | | LocalBackendSearchOperation localSearch = |
| | | new LocalBackendSearchOperation(internalSearch); |
| | | SearchRequest request = newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, "aci=*").addAttribute("aci"); |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request); |
| | | LocalBackendSearchOperation localSearch = new LocalBackendSearchOperation(internalSearch); |
| | | |
| | | configBackend.search(localSearch); |
| | | |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.api.AlertGenerator; |
| | | import org.opends.server.api.Backend; |
| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.types.*; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.types.operation.*; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendSearchOperation; |
| | | |
| | | import static org.opends.messages.AccessControlMessages.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | /** |
| | |
| | | logger.warn(WARN_ACI_ATTRIBUTE_NOT_INDEXED, backend.getBackendID(), "aci"); |
| | | } |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | LinkedList<LocalizableMessage> failedACIMsgs = new LinkedList<LocalizableMessage>(); |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | // Add manageDsaIT control so any ACIs in referral entries will be |
| | | // picked up. |
| | | ArrayList<Control> controls = new ArrayList<Control>(1); |
| | | controls.add(new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true)); |
| | | LDAPControl c1 = new LDAPControl(OID_MANAGE_DSAIT_CONTROL, true); |
| | | // Add group membership control to let a backend look for it and |
| | | // decide if it would abort searches. |
| | | controls.add(new LDAPControl(OID_INTERNAL_GROUP_MEMBERSHIP_UPDATE, |
| | | false)); |
| | | LDAPControl c2 = new LDAPControl(OID_INTERNAL_GROUP_MEMBERSHIP_UPDATE, false); |
| | | |
| | | for (DN baseDN : backend.getBaseDNs()) |
| | | { |
| | | try |
| | |
| | | logger.traceException(e); |
| | | continue; |
| | | } |
| | | SearchRequest request = newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, aciFilter) |
| | | .addControl(c1) |
| | | .addControl(c2) |
| | | .addAttribute(attrs); |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection |
| | | .nextOperationID(), InternalClientConnection |
| | | .nextMessageID(), controls, baseDN, |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | aciFilter, attrs, null); |
| | | new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request); |
| | | LocalBackendSearchOperation localInternalSearch = |
| | | new LocalBackendSearchOperation(internalSearch); |
| | | try |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.admin.ClassPropertyDefinition; |
| | |
| | | import org.opends.server.api.plugin.PluginResult; |
| | | import org.opends.server.api.plugin.PluginResult.PostOperation; |
| | | import org.opends.server.api.plugin.PluginType; |
| | | import org.forgerock.opendj.config.server.ConfigException; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.types.*; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.types.operation.*; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendSearchOperation; |
| | | |
| | | import static org.opends.messages.ConfigMessages.*; |
| | | import static org.opends.messages.CoreMessages.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | |
| | | * A mapping between the DNs of the config entries and the associated group |
| | | * implementations. |
| | | */ |
| | | private ConcurrentHashMap<DN, Group> groupImplementations; |
| | | private ConcurrentHashMap<DN, Group<?>> groupImplementations; |
| | | |
| | | /** |
| | | * A mapping between the DNs of all group entries and the corresponding group |
| | | * instances. |
| | | */ |
| | | private DITCacheMap<Group> groupInstances; |
| | | private DITCacheMap<Group<?>> groupInstances; |
| | | |
| | | /** Lock to protect internal data structures. */ |
| | | private final ReentrantReadWriteLock lock; |
| | |
| | | PluginType.POST_SYNCHRONIZATION_MODIFY_DN), true); |
| | | this.serverContext = serverContext; |
| | | |
| | | groupImplementations = new ConcurrentHashMap<DN, Group>(); |
| | | groupInstances = new DITCacheMap<Group>(); |
| | | groupImplementations = new ConcurrentHashMap<DN, Group<?>>(); |
| | | groupInstances = new DITCacheMap<Group<?>>(); |
| | | |
| | | lock = new ReentrantReadWriteLock(); |
| | | |
| | |
| | | { |
| | | try |
| | | { |
| | | Group group = loadGroup(groupConfiguration.getJavaClass(), |
| | | groupConfiguration, true); |
| | | Group<?> group = loadGroup(groupConfiguration.getJavaClass(), groupConfiguration, true); |
| | | groupImplementations.put(groupConfiguration.dn(), group); |
| | | } |
| | | catch (InitializationException ie) |
| | |
| | | return new ConfigChangeResult(resultCode, false, messages); |
| | | } |
| | | |
| | | Group group = null; |
| | | Group<?> group = null; |
| | | try |
| | | { |
| | | group = loadGroup(configuration.getJavaClass(), configuration, true); |
| | |
| | | ResultCode resultCode = ResultCode.SUCCESS; |
| | | List<LocalizableMessage> messages = new ArrayList<LocalizableMessage>(); |
| | | |
| | | Group group = groupImplementations.remove(configuration.dn()); |
| | | Group<?> group = groupImplementations.remove(configuration.dn()); |
| | | if (group != null) |
| | | { |
| | | lock.writeLock().lock(); |
| | | try |
| | | { |
| | | Iterator<Group> iterator = groupInstances.values().iterator(); |
| | | Iterator<Group<?>> iterator = groupInstances.values().iterator(); |
| | | while (iterator.hasNext()) |
| | | { |
| | | Group g = iterator.next(); |
| | | Group<?> g = iterator.next(); |
| | | if (g.getClass().getName().equals(group.getClass().getName())) |
| | | { |
| | | iterator.remove(); |
| | |
| | | boolean adminActionRequired = false; |
| | | List<LocalizableMessage> messages = new ArrayList<LocalizableMessage>(); |
| | | // Get the existing group implementation if it's already enabled. |
| | | Group existingGroup = groupImplementations.get(configuration.dn()); |
| | | Group<?> existingGroup = groupImplementations.get(configuration.dn()); |
| | | |
| | | // If the new configuration has the group implementation disabled, then |
| | | // disable it if it is enabled, or do nothing if it's already disabled. |
| | |
| | | { |
| | | if (existingGroup != null) |
| | | { |
| | | Group group = groupImplementations.remove(configuration.dn()); |
| | | Group<?> group = groupImplementations.remove(configuration.dn()); |
| | | if (group != null) |
| | | { |
| | | lock.writeLock().lock(); |
| | | try |
| | | { |
| | | Iterator<Group> iterator = groupInstances.values().iterator(); |
| | | Iterator<Group<?>> iterator = groupInstances.values().iterator(); |
| | | while (iterator.hasNext()) |
| | | { |
| | | Group g = iterator.next(); |
| | | Group<?> g = iterator.next(); |
| | | if (g.getClass().getName().equals(group.getClass().getName())) |
| | | { |
| | | iterator.remove(); |
| | |
| | | return new ConfigChangeResult(resultCode, adminActionRequired, messages); |
| | | } |
| | | |
| | | Group group = null; |
| | | Group<?> group = null; |
| | | try |
| | | { |
| | | group = loadGroup(className, configuration, true); |
| | |
| | | * @throws InitializationException If a problem occurred while attempting to |
| | | * initialize the group implementation. |
| | | */ |
| | | private Group loadGroup(String className, |
| | | private Group<?> loadGroup(String className, |
| | | GroupImplementationCfg configuration, |
| | | boolean initialize) |
| | | throws InitializationException |
| | |
| | | |
| | | deregisterAllGroups(); |
| | | |
| | | for (Group groupImplementation : groupImplementations.values()) |
| | | for (Group<?> groupImplementation : groupImplementations.values()) |
| | | { |
| | | groupImplementation.finalizeGroupImplementation(); |
| | | } |
| | |
| | | * @return An {@code Iterable} object that may be used to cursor across the |
| | | * group implementations defined in the server. |
| | | */ |
| | | public Iterable<Group> getGroupImplementations() |
| | | public Iterable<Group<?>> getGroupImplementations() |
| | | { |
| | | return groupImplementations.values(); |
| | | } |
| | |
| | | * @return An {@code Iterable} object that may be used to cursor across the |
| | | * group instances defined in the server. |
| | | */ |
| | | public Iterable<Group> getGroupInstances() |
| | | public Iterable<Group<?>> getGroupInstances() |
| | | { |
| | | lock.readLock().lock(); |
| | | try |
| | | { |
| | | // Return a copy to protect from structural changes. |
| | | ArrayList<Group> values = new ArrayList<Group>(); |
| | | values.addAll(groupInstances.values()); |
| | | return values; |
| | | return new ArrayList<Group<?>>(groupInstances.values()); |
| | | } |
| | | finally |
| | | { |
| | |
| | | * @return The group instance defined in the entry with the specified DN, or |
| | | * {@code null} if no such group is currently defined. |
| | | */ |
| | | public Group getGroupInstance(DN entryDN) |
| | | public Group<?> getGroupInstance(DN entryDN) |
| | | { |
| | | lock.readLock().lock(); |
| | | try |
| | |
| | | @Override |
| | | public void performBackendInitializationProcessing(Backend backend) |
| | | { |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | LinkedList<Control> requestControls = new LinkedList<Control>(); |
| | | requestControls.add(new LDAPControl(OID_INTERNAL_GROUP_MEMBERSHIP_UPDATE, |
| | | false)); |
| | | LDAPControl control = new LDAPControl(OID_INTERNAL_GROUP_MEMBERSHIP_UPDATE, false); |
| | | for (DN configEntryDN : groupImplementations.keySet()) |
| | | { |
| | | SearchFilter filter; |
| | | Group groupImplementation = groupImplementations.get(configEntryDN); |
| | | Group<?> groupImplementation = groupImplementations.get(configEntryDN); |
| | | try |
| | | { |
| | | filter = groupImplementation.getGroupDefinitionFilter(); |
| | |
| | | } |
| | | |
| | | |
| | | SearchRequest request = newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, filter) |
| | | .addControl(control); |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, nextOperationID(), |
| | | nextMessageID(), requestControls, |
| | | baseDN, |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, |
| | | 0, 0, false, filter, null, null); |
| | | new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request); |
| | | LocalBackendSearchOperation localSearch = |
| | | new LocalBackendSearchOperation(internalSearch); |
| | | try |
| | |
| | | { |
| | | try |
| | | { |
| | | Group groupInstance = groupImplementation.newInstance(entry); |
| | | Group<?> groupInstance = groupImplementation.newInstance(entry); |
| | | groupInstances.put(entry.getName(), groupInstance); |
| | | refreshToken++; |
| | | } |
| | |
| | | lock.writeLock().lock(); |
| | | try |
| | | { |
| | | Iterator<Map.Entry<DN,Group>> iterator = |
| | | groupInstances.entrySet().iterator(); |
| | | Iterator<Map.Entry<DN, Group<?>>> iterator = groupInstances.entrySet().iterator(); |
| | | while (iterator.hasNext()) |
| | | { |
| | | Map.Entry<DN,Group> mapEntry = iterator.next(); |
| | | Map.Entry<DN, Group<?>> mapEntry = iterator.next(); |
| | | DN groupEntryDN = mapEntry.getKey(); |
| | | if (backend.handlesEntry(groupEntryDN)) |
| | | { |
| | |
| | | lock.writeLock().lock(); |
| | | try |
| | | { |
| | | Set<Group> groupSet = new HashSet<Group>(); |
| | | Set<Group<?>> groupSet = new HashSet<Group<?>>(); |
| | | groupInstances.removeSubtree(oldEntry.getName(), groupSet); |
| | | String oldDNString = oldEntry.getName().toNormalizedString(); |
| | | String newDNString = newEntry.getName().toNormalizedString(); |
| | | for (Group group : groupSet) |
| | | for (Group<?> group : groupSet) |
| | | { |
| | | StringBuilder builder = new StringBuilder( |
| | | group.getGroupDN().toNormalizedString()); |
| | |
| | | */ |
| | | private void createAndRegisterGroup(Entry entry) |
| | | { |
| | | for (Group groupImplementation : groupImplementations.values()) |
| | | for (Group<?> groupImplementation : groupImplementations.values()) |
| | | { |
| | | try |
| | | { |
| | | if (groupImplementation.isGroupDefinition(entry)) |
| | | { |
| | | Group groupInstance = groupImplementation.newInstance(entry); |
| | | Group<?> groupInstance = groupImplementation.newInstance(entry); |
| | | |
| | | lock.writeLock().lock(); |
| | | try |
| | |
| | | import java.util.concurrent.locks.ReentrantReadWriteLock; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.api.Backend; |
| | | import org.opends.server.api.BackendInitializationListener; |
| | | import org.opends.server.api.ClientConnection; |
| | | import org.opends.server.api.DITCacheMap; |
| | | import org.opends.server.api.SubentryChangeListener; |
| | | import org.opends.server.api.plugin.InternalDirectoryServerPlugin; |
| | |
| | | import org.opends.server.controls.SubentriesControl; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.types.*; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.types.operation.PostOperationAddOperation; |
| | | import org.opends.server.types.operation.PostOperationDeleteOperation; |
| | | import org.opends.server.types.operation.PostOperationModifyDNOperation; |
| | |
| | | |
| | | import static org.opends.messages.CoreMessages.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public void performBackendInitializationProcessing(Backend backend) |
| | | { |
| | | InternalClientConnection conn = InternalClientConnection.getRootConnection(); |
| | | |
| | | LinkedList<Control> requestControls = new LinkedList<Control>(); |
| | | requestControls.add(new SubentriesControl(true, true)); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | SubentriesControl control = new SubentriesControl(true, true); |
| | | |
| | | SearchFilter filter = null; |
| | | try |
| | |
| | | continue; |
| | | } |
| | | |
| | | InternalSearchOperation internalSearch = new InternalSearchOperation( |
| | | conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | requestControls, baseDN, SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | filter, requestAttrs, null); |
| | | LocalBackendSearchOperation localSearch = |
| | | new LocalBackendSearchOperation(internalSearch); |
| | | SearchRequest request = newSearchRequest(baseDN, SearchScope.WHOLE_SUBTREE, filter) |
| | | .addAttribute(requestAttrs) |
| | | .addControl(control); |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request); |
| | | LocalBackendSearchOperation localSearch = new LocalBackendSearchOperation(internalSearch); |
| | | |
| | | try |
| | | { |
| | |
| | | */ |
| | | package org.opends.server.crypto; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.EnumSet; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.admin.ads.ADSContext; |
| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | |
| | | import static org.opends.server.api.plugin.PluginType.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | |
| | |
| | | |
| | | private void searchAdminSuffix() |
| | | { |
| | | LinkedHashSet<String> attributes = new LinkedHashSet<String>(0); |
| | | |
| | | ArrayList<Control> controls = new ArrayList<Control>(0); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(getRootConnection(), |
| | | nextOperationID(), |
| | | nextMessageID(), |
| | | controls, |
| | | adminSuffixDN, SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, |
| | | 0, 0, |
| | | false, keySearchFilter, attributes, |
| | | null); |
| | | |
| | | searchOperation.run(); |
| | | |
| | | SearchRequest request = newSearchRequest(adminSuffixDN, SearchScope.WHOLE_SUBTREE, keySearchFilter); |
| | | InternalSearchOperation searchOperation = getRootConnection().processSearch(request); |
| | | ResultCode resultCode = searchOperation.getResultCode(); |
| | | if (resultCode != ResultCode.SUCCESS) |
| | | { |
| | |
| | | logger.error(ERR_TRUSTSTORESYNC_EXCEPTION, stackTraceToSingleLineString(e)); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | // filter = Filter.alwaysTrue(); |
| | | // } |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(this, nextOperationID(), nextMessageID(), |
| | | request.getControls(), request.getName(), request.getScope(), |
| | | request.getDereferenceAliasesPolicy(), request.getSizeLimit(), |
| | | request.getTimeLimit(), request.isTypesOnly(), request.getFilter(), |
| | | request.getAttributes(), searchListener); |
| | | new InternalSearchOperation(this, nextOperationID(), nextMessageID(), request, searchListener); |
| | | searchOperation.run(); |
| | | return searchOperation; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Creates a new internal search operation with the provided information. |
| | | * |
| | | * @param internalConnection |
| | | * The internal client connection with which this internal search |
| | | * operation is associated. |
| | | * @param operationID |
| | | * The operation ID for this internal search. |
| | | * @param messageID |
| | | * The message ID for this internal search. |
| | | * @param request |
| | | * The search request |
| | | */ |
| | | public InternalSearchOperation(ClientConnection internalConnection, long operationID, int messageID, |
| | | SearchRequest request) |
| | | { |
| | | this(internalConnection, operationID, messageID, request, null); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new internal search operation with the provided |
| | | * information. |
| | | * Creates a new internal search operation with the provided information. |
| | | * |
| | | * @param internalConnection The internal client connection with |
| | | * which this internal search operation |
| | |
| | | * search. |
| | | * @param messageID The message ID for this internal |
| | | * search. |
| | | * @param requestControls The set of request controls for this |
| | | * internal search. |
| | | * @param baseDN The base DN for this internal search. |
| | | * @param scope The scope for this internal search. |
| | | * @param derefPolicy The alias dereferencing policy for |
| | | * this internal search. |
| | | * @param sizeLimit The size limit for this internal |
| | | * search. |
| | | * @param timeLimit The time limit for this internal |
| | | * search. |
| | | * @param typesOnly The typesOnly flag for this internal |
| | | * search. |
| | | * @param filter The filter for this internal search. |
| | | * @param attributes The names of the requested attributes |
| | | * for this internal search. |
| | | * @param request The search request |
| | | * @param searchListener The internal search listener that |
| | | * should be used to process the |
| | | * results, or <CODE>null</CODE> if |
| | | * they should be collected internally. |
| | | */ |
| | | public InternalSearchOperation( |
| | | public InternalSearchOperation(ClientConnection internalConnection, long operationID, int messageID, |
| | | SearchRequest request, InternalSearchListener searchListener) |
| | | { |
| | | this(internalConnection, operationID, messageID, |
| | | request.getControls(), |
| | | request.getName(), request.getScope(), |
| | | request.getDereferenceAliasesPolicy(), |
| | | request.getSizeLimit(), request.getTimeLimit(), request.isTypesOnly(), |
| | | request.getFilter(), request.getAttributes(), |
| | | searchListener); |
| | | } |
| | | |
| | | // TODO JNR remove?? |
| | | private InternalSearchOperation( |
| | | ClientConnection internalConnection, |
| | | long operationID, int messageID, |
| | | List<Control> requestControls, DN baseDN, |
| | |
| | | setInternalOperation(true); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Retrieves the set of search result entries returned for this |
| | | * search. |
| | |
| | | final String filter, final String... attributeDescriptions) |
| | | throws NullPointerException, LocalizedIllegalArgumentException, DirectoryException { |
| | | Reject.ifNull(name, scope, filter); |
| | | SearchFilter f = SearchFilter.createFilterFromString(filter); |
| | | SearchFilter f = "(objectclass=*)".equals(filter.toLowerCase()) |
| | | ? SearchFilter.objectClassPresent() |
| | | : SearchFilter.createFilterFromString(filter); |
| | | final SearchRequest request = new SearchRequest(DN.valueOf(name), scope, f); |
| | | for (final String attributeDescription : attributeDescriptions) { |
| | | request.addAttribute(attributeDescription); |
| | |
| | | */ |
| | | public InternalSearchOperation processSearch(SearchRequest request) |
| | | { |
| | | InternalSearchOperation searchOperation = new InternalSearchOperation( |
| | | this, nextOperationID(), nextMessageID(), |
| | | request.getControls(), |
| | | request.getName(), request.getScope(), |
| | | request.getDereferenceAliasesPolicy(), |
| | | request.getSizeLimit(), request.getTimeLimit(), request.isTypesOnly(), |
| | | request.getFilter(), request.getAttributes(), null); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(this, nextOperationID(), nextMessageID(), request); |
| | | |
| | | if (! hasPrivilege(Privilege.JMX_READ, null)) |
| | | { |
| | |
| | | import org.opends.server.core.ModifyOperationBasis; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import org.opends.server.protocols.ldap.LDAPAttribute; |
| | | import org.opends.server.protocols.ldap.LDAPModification; |
| | | import org.opends.server.replication.common.CSN; |
| | |
| | | |
| | | import static org.opends.messages.ReplicationMessages.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | |
| | | /** |
| | | * This class implements a ServerState that is stored in the backend |
| | |
| | | */ |
| | | private SearchResultEntry searchBaseEntry() |
| | | { |
| | | try |
| | | // Search the database entry that is used to periodically save the ServerState |
| | | final SearchRequest request = newSearchRequest(baseDN, SearchScope.BASE_OBJECT).addAttribute(REPLICATION_STATE); |
| | | final InternalSearchOperation search = getRootConnection().processSearch(request); |
| | | final ResultCode resultCode = search.getResultCode(); |
| | | if (resultCode != ResultCode.SUCCESS |
| | | && resultCode != ResultCode.NO_SUCH_OBJECT) |
| | | { |
| | | final SearchRequest request = |
| | | newSearchRequest(baseDN, SearchScope.BASE_OBJECT, "objectclass=*").addAttribute(REPLICATION_STATE); |
| | | /* |
| | | * Search the database entry that is used to periodically |
| | | * save the ServerState |
| | | */ |
| | | final InternalSearchOperation search = getRootConnection().processSearch(request); |
| | | final ResultCode resultCode = search.getResultCode(); |
| | | if (resultCode != ResultCode.SUCCESS |
| | | && resultCode != ResultCode.NO_SUCH_OBJECT) |
| | | { |
| | | logger.error(ERR_ERROR_SEARCHING_RUV, search.getResultCode().getName(), search, |
| | | search.getErrorMessage(), baseDN); |
| | | return null; |
| | | } |
| | | return getFirstResult(search); |
| | | } |
| | | catch (DirectoryException e) |
| | | { |
| | | // cannot happen |
| | | logger.error(ERR_ERROR_SEARCHING_RUV, search.getResultCode().getName(), search, search.getErrorMessage(), baseDN); |
| | | return null; |
| | | } |
| | | return getFirstResult(search); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | package org.opends.server.controls; |
| | | |
| | | |
| | | |
| | | import static org.testng.Assert.assertEquals; |
| | | import static org.testng.Assert.assertFalse; |
| | | import static org.testng.Assert.assertNotNull; |
| | | import static org.testng.Assert.assertNull; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.types.SortKey; |
| | | import org.opends.server.types.SortOrder; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * This class contains a number of test cases for the server side sort request |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass() |
| | | public void startServer() |
| | | throws Exception |
| | | @BeforeClass |
| | | public void startServer() throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private void populateDB() |
| | | throws Exception |
| | | private void populateDB() throws Exception |
| | | { |
| | | TestCaseUtils.clearJEBackend(true, "userRoot", "dc=example,dc=com"); |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testRequestConstructor1() |
| | | throws Exception |
| | | @Test |
| | | public void testRequestConstructor1() throws Exception |
| | | { |
| | | SortKey sortKey = new SortKey(givenNameType, true); |
| | | SortOrder sortOrder = new SortOrder(sortKey); |
| | |
| | | sortKey.toString(); |
| | | sortOrder.toString(); |
| | | |
| | | SortKey[] sortKeys = |
| | | { |
| | | sortOrder = new SortOrder( |
| | | new SortKey(snType, true), |
| | | new SortKey(givenNameType, true) |
| | | }; |
| | | sortOrder = new SortOrder(sortKeys); |
| | | new SortKey(givenNameType, true)); |
| | | new ServerSideSortRequestControl(sortOrder).toString(); |
| | | sortOrder.toString(); |
| | | } |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testRequestConstructor2() |
| | | throws Exception |
| | | @Test |
| | | public void testRequestConstructor2() throws Exception |
| | | { |
| | | new ServerSideSortRequestControl("givenName").toString(); |
| | | new ServerSideSortRequestControl("givenName:caseIgnoreOrderingMatch"). |
| | | toString(); |
| | | new ServerSideSortRequestControl("givenName:caseIgnoreOrderingMatch").toString(); |
| | | new ServerSideSortRequestControl("+givenName").toString(); |
| | | new ServerSideSortRequestControl("-givenName").toString(); |
| | | new ServerSideSortRequestControl("givenName,sn").toString(); |
| | |
| | | new ServerSideSortRequestControl("-givenName").toString(); |
| | | new ServerSideSortRequestControl("-givenName,+sn").toString(); |
| | | new ServerSideSortRequestControl("-givenName,-sn").toString(); |
| | | new ServerSideSortRequestControl("-givenName,-sn:caseExactOrderingMatch"). |
| | | toString(); |
| | | new ServerSideSortRequestControl("-givenName,-sn:caseExactOrderingMatch").toString(); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchGivenNameAscending() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")); |
| | | InternalSearchOperation internalSearch = conn.processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(samZweckDN); // Sam |
| | | expectedDNOrder.add(zorroDN); // No first name |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | assertEquals(responseControls.size(), 1); |
| | | |
| | | ServerSideSortResponseControl responseControl; |
| | | Control c = responseControls.get(0); |
| | | if(c instanceof ServerSideSortResponseControl) |
| | | { |
| | | responseControl = (ServerSideSortResponseControl)c; |
| | | } |
| | | else |
| | | { |
| | | responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | assertEquals(responseControl.getResultCode(), 0); |
| | | assertNull(responseControl.getAttributeType()); |
| | | responseControl.toString(); |
| | | assertNoAttributeTypeForSort(internalSearch); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests performing an internal search using the server-side sort control to |
| | | * sort the entries in order of ascending givenName values using a specific |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchGivenNameAscendingCaseExact() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchGivenNameAscendingCaseExact() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl( |
| | | "givenName:caseExactOrderingMatch")); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName:caseExactOrderingMatch")); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(lowercaseMcGeeDN); // lowercase |
| | | expectedDNOrder.add(zorroDN); // No first name |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | assertEquals(responseControls.size(), 1); |
| | | |
| | | ServerSideSortResponseControl responseControl; |
| | | Control c = responseControls.get(0); |
| | | if(c instanceof ServerSideSortResponseControl) |
| | | { |
| | | responseControl = (ServerSideSortResponseControl)c; |
| | | } |
| | | else |
| | | { |
| | | responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | assertEquals(responseControl.getResultCode(), 0); |
| | | assertNull(responseControl.getAttributeType()); |
| | | responseControl.toString(); |
| | | assertNoAttributeTypeForSort(internalSearch); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests performing an internal search using the server-side sort control to |
| | | * sort the entries in order of descending givenName values. |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchGivenNameDescending() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchGivenNameDescending() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("-givenName")); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("-givenName")); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(aaccfJohnsonDN); // Aaccf |
| | | expectedDNOrder.add(zorroDN); // No first name |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | assertEquals(responseControls.size(), 1); |
| | | |
| | | ServerSideSortResponseControl responseControl; |
| | | Control c = responseControls.get(0); |
| | | if(c instanceof ServerSideSortResponseControl) |
| | | { |
| | | responseControl = (ServerSideSortResponseControl)c; |
| | | } |
| | | else |
| | | { |
| | | responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | assertEquals(responseControl.getResultCode(), 0); |
| | | assertNull(responseControl.getAttributeType()); |
| | | responseControl.toString(); |
| | | assertNoAttributeTypeForSort(internalSearch); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchGivenNameDescendingCaseExact() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchGivenNameDescendingCaseExact() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("-givenName:caseExactOrderingMatch")); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl( |
| | | "-givenName:caseExactOrderingMatch")); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(aaccfJohnsonDN); // Aaccf |
| | | expectedDNOrder.add(zorroDN); // No first name |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | assertEquals(responseControls.size(), 1); |
| | | |
| | | ServerSideSortResponseControl responseControl; |
| | | Control c = responseControls.get(0); |
| | | if(c instanceof ServerSideSortResponseControl) |
| | | { |
| | | responseControl = (ServerSideSortResponseControl)c; |
| | | } |
| | | else |
| | | { |
| | | responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | assertEquals(responseControl.getResultCode(), 0); |
| | | assertNull(responseControl.getAttributeType()); |
| | | responseControl.toString(); |
| | | assertNoAttributeTypeForSort(internalSearch); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchGivenNameAscendingSnAscending() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchGivenNameAscendingSnAscending() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName,sn")); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName,sn")); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(samZweckDN); // Sam |
| | | expectedDNOrder.add(zorroDN); // No first name |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | assertEquals(responseControls.size(), 1); |
| | | |
| | | ServerSideSortResponseControl responseControl; |
| | | Control c = responseControls.get(0); |
| | | if(c instanceof ServerSideSortResponseControl) |
| | | { |
| | | responseControl = (ServerSideSortResponseControl)c; |
| | | } |
| | | else |
| | | { |
| | | responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | assertEquals(responseControl.getResultCode(), 0); |
| | | assertNull(responseControl.getAttributeType()); |
| | | responseControl.toString(); |
| | | assertNoAttributeTypeForSort(internalSearch); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests performing an internal search using the server-side sort control to |
| | | * sort the entries in order of ascending givenName and descending sn values. |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchGivenNameAscendingSnDescending() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName,-sn")); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName,-sn")); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(samZweckDN); // Sam |
| | | expectedDNOrder.add(zorroDN); // No first name |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | assertEquals(responseControls.size(), 1); |
| | | |
| | | ServerSideSortResponseControl responseControl; |
| | | Control c = responseControls.get(0); |
| | | if(c instanceof ServerSideSortResponseControl) |
| | | { |
| | | responseControl = (ServerSideSortResponseControl)c; |
| | | } |
| | | else |
| | | { |
| | | responseControl = ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | assertEquals(responseControl.getResultCode(), 0); |
| | | assertNull(responseControl.getAttributeType()); |
| | | responseControl.toString(); |
| | | assertNoAttributeTypeForSort(internalSearch); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests performing an internal search using the CRITICAL server-side sort control with |
| | | * an undefined attribute type. |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testCriticalSortWithUndefinedAttribute() |
| | | throws Exception |
| | | @Test |
| | | public void testCriticalSortWithUndefinedAttribute() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl(true, "undefined")); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl(true, "undefined")); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.UNAVAILABLE_CRITICAL_EXTENSION); |
| | | } |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchUndefinedOrderingRule() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchUndefinedOrderingRule() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl(true, |
| | | "givenName:undefinedOrderingMatch")); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl(true, "givenName:undefinedOrderingMatch")); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertFalse(internalSearch.getResultCode() == ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testNonCriticalSortWithUndefinedAttribute() |
| | | throws Exception |
| | | @Test |
| | | public void testNonCriticalSortWithUndefinedAttribute() throws Exception |
| | | { |
| | | populateDB(); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl(false, |
| | | "bad_sort:caseExactOrderingMatch")); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl(false, "bad_sort:caseExactOrderingMatch")); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | ServerSideSortResponseControl responseControl = getServerSideSortResponseControl(internalSearch); |
| | | assertEquals(responseControl.getResultCode(), 16); |
| | | } |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | private void assertNoAttributeTypeForSort(InternalSearchOperation internalSearch) throws Exception |
| | | { |
| | | ServerSideSortResponseControl responseControl = getServerSideSortResponseControl(internalSearch); |
| | | assertEquals(responseControl.getResultCode(), ResultCode.SUCCESS.intValue()); |
| | | assertNull(responseControl.getAttributeType()); |
| | | responseControl.toString(); |
| | | } |
| | | |
| | | internalSearch.run(); |
| | | assertEquals(internalSearch.getResultCode(), |
| | | ResultCode.SUCCESS); |
| | | private ServerSideSortResponseControl getServerSideSortResponseControl(InternalSearchOperation internalSearch) |
| | | throws Exception |
| | | { |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | assertEquals(responseControls.size(), 1); |
| | | |
| | | ServerSideSortResponseControl responseControl; |
| | | return getServerSideSortResponseControl(responseControls); |
| | | } |
| | | |
| | | private ServerSideSortResponseControl getServerSideSortResponseControl(List<Control> responseControls) |
| | | throws DirectoryException |
| | | { |
| | | Control c = responseControls.get(0); |
| | | if(c instanceof ServerSideSortResponseControl) |
| | | if (c instanceof ServerSideSortResponseControl) |
| | | { |
| | | responseControl = (ServerSideSortResponseControl)c; |
| | | return (ServerSideSortResponseControl) c; |
| | | } |
| | | else |
| | | return ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl) c).getValue()); |
| | | } |
| | | |
| | | private ArrayList<DN> getDNs(LinkedList<SearchResultEntry> searchEntries) |
| | | { |
| | | ArrayList<DN> results = new ArrayList<DN>(); |
| | | for (Entry e : searchEntries) |
| | | { |
| | | responseControl = ServerSideSortResponseControl.DECODER.decode( |
| | | c.isCritical(), ((LDAPControl)c).getValue()); |
| | | results.add(e.getName()); |
| | | } |
| | | assertEquals(responseControl.getResultCode(), 16); |
| | | return results; |
| | | } |
| | | } |
| | | |
| | |
| | | package org.opends.server.controls; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.io.ASN1; |
| | |
| | | import org.forgerock.opendj.io.ASN1Writer; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ByteStringBuilder; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import org.opends.server.types.*; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testRequestConstructor1() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testRequestConstructor2NullContextID() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testRequestConstructor2NonNullContextID() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testRequestConstructor3() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testRequestConstructor4NullContextID() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testRequestConstructor4NonNullContextID() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testASN1ValueEncoding() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testResponseConstructor1() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testResponseConstructor2NullContextID() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testResponseConstructor2NonNullContextID() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchByOffsetOneOffset() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchByOffsetOneOffset() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(0, 3, 1, 0)); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(0, 3, 1, 0)); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID |
| | | expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | |
| | | { |
| | | if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | sortResponse = |
| | | ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | sortResponse = (ServerSideSortResponseControl)c; |
| | | } |
| | | sortResponse = getServerSideSortResponseControl(c); |
| | | } |
| | | else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | vlvResponse = getVLVResponseControl(c); |
| | | } |
| | | else |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchByOffsetZeroOffset() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(0, 3, 0, 0)); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(0, 3, 0, 0)); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID |
| | | expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | |
| | | { |
| | | if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | sortResponse = |
| | | ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | sortResponse = (ServerSideSortResponseControl)c; |
| | | } |
| | | sortResponse = getServerSideSortResponseControl(c); |
| | | } |
| | | else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | vlvResponse = getVLVResponseControl(c); |
| | | } |
| | | else |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchByOffsetThreeOffset() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(0, 3, 3, 0)); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(0, 3, 3, 0)); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(lowercaseMcGeeDN); // lowercase |
| | | expectedDNOrder.add(margaretJonesDN); // Maggie |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | |
| | | { |
| | | if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | sortResponse = |
| | | ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | sortResponse = (ServerSideSortResponseControl)c; |
| | | } |
| | | sortResponse = getServerSideSortResponseControl(c); |
| | | } |
| | | else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | vlvResponse = getVLVResponseControl(c); |
| | | } |
| | | else |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchByOffsetNegativeOffset() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(0, 3, -1, 0)); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(0, 3, -1, 0)); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | |
| | | // It will be successful because it's not a critical control. |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | |
| | | VLVResponseControl vlvResponse = null; |
| | | for (Control c : responseControls) |
| | | { |
| | | if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | } |
| | | } |
| | | |
| | | assertNotNull(vlvResponse); |
| | | VLVResponseControl vlvResponse = getVLVResponseControl(responseControls); |
| | | assertEquals(vlvResponse.getVLVResultCode(), |
| | | LDAPResultCode.OFFSET_RANGE_ERROR); |
| | | } |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchByOffsetNegativeStartPosition() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(3, 3, 1, 0)); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(3, 3, 1, 0)); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | |
| | | // It will be successful because it's not a critical control. |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | |
| | | VLVResponseControl vlvResponse = null; |
| | | for (Control c : responseControls) |
| | | { |
| | | if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | } |
| | | } |
| | | |
| | | assertNotNull(vlvResponse); |
| | | VLVResponseControl vlvResponse = getVLVResponseControl(responseControls); |
| | | assertEquals(vlvResponse.getVLVResultCode(), LDAPResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchByOffsetStartPositionTooHigh() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchByOffsetStartPositionTooHigh() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(3, 3, 30, 0)); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(3, 3, 30, 0)); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(samZweckDN); // Sam |
| | | expectedDNOrder.add(zorroDN); // No first name |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | |
| | | VLVResponseControl vlvResponse = null; |
| | | for (Control c : responseControls) |
| | | { |
| | | if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | } |
| | | } |
| | | |
| | | assertNotNull(vlvResponse); |
| | | VLVResponseControl vlvResponse = getVLVResponseControl(responseControls); |
| | | assertEquals(vlvResponse.getVLVResultCode(), LDAPResultCode.SUCCESS); |
| | | assertEquals(vlvResponse.getTargetPosition(), 10); |
| | | assertEquals(vlvResponse.getContentCount(), 9); |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchByOffsetIncompleteAfterCount() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchByOffsetIncompleteAfterCount() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(0, 3, 7, 0)); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(0, 3, 7, 0)); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(samZweckDN); // Sam |
| | | expectedDNOrder.add(zorroDN); // No first name |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | |
| | | { |
| | | if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | sortResponse = |
| | | ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | sortResponse = (ServerSideSortResponseControl)c; |
| | | } |
| | | sortResponse = getServerSideSortResponseControl(c); |
| | | } |
| | | else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | vlvResponse = getVLVResponseControl(c); |
| | | } |
| | | else |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchByValueBeforeAll() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(0, 3, ByteString.valueOf("a"))); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(0, 3, ByteString.valueOf("a"))); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID |
| | | expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | |
| | | { |
| | | if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | sortResponse = |
| | | ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | sortResponse = (ServerSideSortResponseControl)c; |
| | | } |
| | | sortResponse = getServerSideSortResponseControl(c); |
| | | } |
| | | else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | vlvResponse = getVLVResponseControl(c); |
| | | } |
| | | else |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchByValueMatchesFirst() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(0, 3, |
| | | ByteString.valueOf("aaccf"))); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(0, 3, ByteString.valueOf("aaccf"))); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(albertZimmermanDN); // Albert, lower entry ID |
| | | expectedDNOrder.add(albertSmithDN); // Albert, higher entry ID |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | ArrayList<DN> returnedDNOrder = getDNs(internalSearch.getSearchEntries()); |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | |
| | |
| | | { |
| | | if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | sortResponse = |
| | | ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | sortResponse = (ServerSideSortResponseControl)c; |
| | | } |
| | | sortResponse = getServerSideSortResponseControl(c); |
| | | } |
| | | else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | vlvResponse = getVLVResponseControl(c); |
| | | } |
| | | else |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchByValueMatchesThird() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(0, 3, |
| | | ByteString.valueOf("albert"))); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(0, 3, ByteString.valueOf("albert"))); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(lowercaseMcGeeDN); // lowercase |
| | | expectedDNOrder.add(margaretJonesDN); // Maggie |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | ArrayList<DN> returnedDNOrder = getDNs(internalSearch.getSearchEntries()); |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | |
| | |
| | | { |
| | | if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | sortResponse = |
| | | ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | sortResponse = (ServerSideSortResponseControl)c; |
| | | } |
| | | sortResponse = getServerSideSortResponseControl(c); |
| | | } |
| | | else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | vlvResponse = getVLVResponseControl(c); |
| | | } |
| | | else |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testInternalSearchByValueMatchesThirdWithBeforeCount() |
| | | throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("givenName")); |
| | | requestControls.add(new VLVRequestControl(1, 3, |
| | | ByteString.valueOf("albert"))); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("givenName")) |
| | | .addControl(new VLVRequestControl(1, 3, ByteString.valueOf("albert"))); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | ArrayList<DN> expectedDNOrder = new ArrayList<DN>(); |
| | |
| | | expectedDNOrder.add(lowercaseMcGeeDN); // lowercase |
| | | expectedDNOrder.add(margaretJonesDN); // Maggie |
| | | |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | assertEquals(getDNs(internalSearch.getSearchEntries()), expectedDNOrder); |
| | | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | |
| | | { |
| | | if (c.getOID().equals(OID_SERVER_SIDE_SORT_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | sortResponse = |
| | | ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | sortResponse = (ServerSideSortResponseControl)c; |
| | | } |
| | | sortResponse = getServerSideSortResponseControl(c); |
| | | } |
| | | else if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | vlvResponse = getVLVResponseControl(c); |
| | | } |
| | | else |
| | | { |
| | |
| | | assertEquals(vlvResponse.getContentCount(), 9); |
| | | } |
| | | |
| | | |
| | | private ArrayList<DN> getDNs(LinkedList<SearchResultEntry> entries) |
| | | { |
| | | ArrayList<DN> results = new ArrayList<DN>(); |
| | | for (Entry e : entries) |
| | | { |
| | | results.add(e.getName()); |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | /** |
| | | * Tests performing an internal search using the VLV control to retrieve a |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurred. |
| | | */ |
| | | @Test() |
| | | public void testInternalSearchByValueAfterAll() |
| | | throws Exception |
| | | @Test |
| | | public void testInternalSearchByValueAfterAll() throws Exception |
| | | { |
| | | populateDB(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("sn")); |
| | | requestControls.add(new VLVRequestControl(0, 3, ByteString.valueOf("zz"))); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(objectClass=person)"), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(objectClass=person)") |
| | | .addControl(new ServerSideSortRequestControl("sn")) |
| | | .addControl(new VLVRequestControl(0, 3, ByteString.valueOf("zz"))); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | |
| | | // It will be successful because the control isn't critical. |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | |
| | | List<Control> responseControls = internalSearch.getResponseControls(); |
| | | assertNotNull(responseControls); |
| | | |
| | | VLVResponseControl vlvResponse = null; |
| | | for (Control c : responseControls) |
| | | { |
| | | if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | if(c instanceof LDAPControl) |
| | | { |
| | | vlvResponse = VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl)c).getValue()); |
| | | } |
| | | else |
| | | { |
| | | vlvResponse = (VLVResponseControl)c; |
| | | } |
| | | } |
| | | } |
| | | |
| | | assertNotNull(vlvResponse); |
| | | VLVResponseControl vlvResponse = getVLVResponseControl(responseControls); |
| | | assertEquals(vlvResponse.getVLVResultCode(), |
| | | LDAPResultCode.SUCCESS); |
| | | assertEquals(vlvResponse.getTargetPosition(), 10); |
| | | assertEquals(vlvResponse.getContentCount(), 9); |
| | | } |
| | | } |
| | | |
| | | private ServerSideSortResponseControl getServerSideSortResponseControl(Control c) throws DirectoryException |
| | | { |
| | | if (c instanceof LDAPControl) |
| | | { |
| | | return ServerSideSortResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl) c).getValue()); |
| | | } |
| | | return (ServerSideSortResponseControl) c; |
| | | } |
| | | |
| | | private VLVResponseControl getVLVResponseControl(List<Control> responseControls) throws DirectoryException |
| | | { |
| | | for (Control c : responseControls) |
| | | { |
| | | if (c.getOID().equals(OID_VLV_RESPONSE_CONTROL)) |
| | | { |
| | | return getVLVResponseControl(c); |
| | | } |
| | | } |
| | | fail("Expected to find VLVResponseControl"); |
| | | return null; |
| | | } |
| | | |
| | | private VLVResponseControl getVLVResponseControl(Control c) throws DirectoryException |
| | | { |
| | | if (c instanceof LDAPControl) |
| | | { |
| | | return VLVResponseControl.DECODER.decode(c.isCritical(), ((LDAPControl) c).getValue()); |
| | | } |
| | | return (VLVResponseControl) c; |
| | | } |
| | | } |
| | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | import org.testng.annotations.AfterClass; |
| | | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.std.server.GroupImplementationCfg; |
| | | import org.opends.server.api.Group; |
| | |
| | | import org.opends.server.extensions.VirtualStaticGroup; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.tools.LDAPDelete; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.Attributes; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.MemberList; |
| | | import org.opends.server.types.MembershipException; |
| | | import org.opends.server.types.Modification; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.opends.server.types.RDN; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | |
| | | /** |
| | | * A set of test cases that involve the use of groups and the Directory Server |
| | | * Group Manager. |
| | |
| | | Entry user4Entry = DirectoryServer.getEntry(user4DN); |
| | | Entry user5Entry = DirectoryServer.getEntry(user5DN); |
| | | Group<? extends GroupImplementationCfg> group1Instance = |
| | | (Group<? extends GroupImplementationCfg>) |
| | | groupManager.getGroupInstance(group1DN); |
| | | groupManager.getGroupInstance(group1DN); |
| | | assertNotNull(group1Instance); |
| | | //Add even numbered groups. |
| | | group1Instance.addNestedGroup(group2DN); |
| | |
| | | addNestedGroupTestEntries(); |
| | | DN group1DN = DN.valueOf("cn=group 1,ou=Groups,o=test"); |
| | | DN group2DN = DN.valueOf("cn=group 2,ou=Groups,o=test"); |
| | | DN group3DN = DN.valueOf("cn=group 3,ou=Groups,o=test"); |
| | | DN group4DN = DN.valueOf("cn=group 4,ou=Groups,o=test"); |
| | | DN user1DN = DN.valueOf("uid=user.1,ou=People,o=test"); |
| | | Entry user1Entry = DirectoryServer.getEntry(user1DN); |
| | | Group<? extends GroupImplementationCfg> group1Instance = |
| | | (Group<? extends GroupImplementationCfg>) |
| | | groupManager.getGroupInstance(group1DN); |
| | | Group<? extends GroupImplementationCfg> group2Instance = |
| | | (Group<? extends GroupImplementationCfg>) |
| | | groupManager.getGroupInstance(group2DN); |
| | | groupManager.getGroupInstance(group1DN); |
| | | groupManager.getGroupInstance(group2DN); |
| | | assertNotNull(group1Instance); |
| | | //Add some nested groups and members. |
| | | group1Instance.addNestedGroup(group2DN); |
| | |
| | | assertTrue(nestedGroups.isEmpty()); |
| | | try |
| | | { |
| | | MemberList memberList=group1Instance.getMembers(); |
| | | throw new AssertionError("Expected getMembers to fail but " + |
| | | "it didn't"); |
| | | group1Instance.getMembers(); |
| | | fail("getMembers)() should have thrown a DirectoryException"); |
| | | } catch (DirectoryException ex) {} |
| | | } |
| | | |
| | |
| | | //compile warning in the getNestedGroupDNs calls below. Some IDEs |
| | | //will give a unchecked cast warning. |
| | | Group<? extends GroupImplementationCfg> group1Instance = |
| | | (Group<? extends GroupImplementationCfg>) |
| | | groupManager.getGroupInstance(group1DN); |
| | | groupManager.getGroupInstance(group1DN); |
| | | Group<? extends GroupImplementationCfg> group2Instance = |
| | | (Group<? extends GroupImplementationCfg>) |
| | | groupManager.getGroupInstance(group2DN); |
| | | groupManager.getGroupInstance(group2DN); |
| | | Group group3Instance = groupManager.getGroupInstance(group3DN); |
| | | assertNotNull(group1Instance); |
| | | assertNotNull(group2Instance); |
| | |
| | | // Get a client connection authenticated as user1 and make sure it handles |
| | | // group operations correctly. |
| | | InternalClientConnection conn0 = new InternalClientConnection(DN.rootDN()); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn0, nextOperationID(), nextMessageID(), null, |
| | | DN.rootDN(), SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), null, null); |
| | | InternalSearchOperation searchOperation = createSearchOperation(conn0); |
| | | |
| | | assertFalse(conn0.isMemberOf(group1, null)); |
| | | assertFalse(conn0.isMemberOf(group2, null)); |
| | |
| | | // Get a client connection authenticated as user1 and make sure it handles |
| | | // group operations correctly. |
| | | InternalClientConnection conn1 = new InternalClientConnection(user1DN); |
| | | searchOperation = |
| | | new InternalSearchOperation(conn1, nextOperationID(), |
| | | nextMessageID(), null, DN.rootDN(), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), null, null); |
| | | searchOperation = createSearchOperation(conn1); |
| | | |
| | | assertTrue(conn1.isMemberOf(group1, null)); |
| | | assertFalse(conn1.isMemberOf(group2, null)); |
| | |
| | | // Get a client connection authenticated as user2 and make sure it handles |
| | | // group operations correctly. |
| | | InternalClientConnection conn2 = new InternalClientConnection(user2DN); |
| | | searchOperation = |
| | | new InternalSearchOperation(conn2, nextOperationID(), |
| | | nextMessageID(), null, DN.rootDN(), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), null, null); |
| | | searchOperation = createSearchOperation(conn2); |
| | | |
| | | assertTrue(conn2.isMemberOf(group1, null)); |
| | | assertTrue(conn2.isMemberOf(group2, null)); |
| | |
| | | // Get a client connection authenticated as user3 and make sure it handles |
| | | // group operations correctly. |
| | | InternalClientConnection conn3 = new InternalClientConnection(user3DN); |
| | | searchOperation = |
| | | new InternalSearchOperation(conn3, nextOperationID(), |
| | | nextMessageID(), null, DN.rootDN(), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), null, null); |
| | | searchOperation = createSearchOperation(conn3); |
| | | |
| | | assertFalse(conn3.isMemberOf(group1, null)); |
| | | assertTrue(conn3.isMemberOf(group2, null)); |
| | |
| | | assertNull(groupManager.getGroupInstance(group3DN)); |
| | | } |
| | | |
| | | |
| | | private InternalSearchOperation createSearchOperation(InternalClientConnection conn) |
| | | { |
| | | final SearchRequest request = newSearchRequest(DN.rootDN(), SearchScope.BASE_OBJECT); |
| | | return new InternalSearchOperation(conn, nextOperationID(), nextMessageID(), request); |
| | | } |
| | | |
| | | /** |
| | | * Tests operations involving static group member lists. |
| | |
| | | |
| | | DN groupDN = DN.valueOf("cn=Test Group of URLs,ou=Groups,o=test"); |
| | | DN user1DN = DN.valueOf("uid=user.1,ou=People,o=test"); |
| | | DN user2DN = DN.valueOf("uid=user.2,ou=People,o=test"); |
| | | |
| | | Group groupInstance = groupManager.getGroupInstance(groupDN); |
| | | assertNotNull(groupInstance); |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.std.meta.VirtualAttributeCfgDefn; |
| | | import org.opends.server.api.VirtualAttributeProvider; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.workflowelement.localbackend.LocalBackendSearchOperation; |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | |
| | | |
| | | VirtualAttributeRule rule = getRule(provider); |
| | | |
| | | SearchFilter filter = SearchFilter.createFilterFromString(filterString); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filterString); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), null, |
| | | DN.valueOf("o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, filter, null, null); |
| | | new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request); |
| | | // This attribute is searchable for either pre-indexed or not |
| | | assertEquals(provider.isSearchable(rule, searchOperation, false), |
| | | isSearchable); |
| | |
| | | |
| | | VirtualAttributeRule rule = getRule(provider); |
| | | |
| | | SearchFilter filter = SearchFilter.createFilterFromString(filterString); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filterString); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), null, |
| | | DN.valueOf("o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, filter, null, null); |
| | | LocalBackendSearchOperation localSearch = |
| | | new LocalBackendSearchOperation(searchOperation); |
| | | |
| | | new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request); |
| | | LocalBackendSearchOperation localSearch = new LocalBackendSearchOperation(searchOperation); |
| | | provider.processSearch(rule, localSearch); |
| | | |
| | | if (shouldMatch) |
| | | { |
| | | assertEquals(searchOperation.getSearchEntries().size(), 1); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(searchOperation.getSearchEntries().size(), 0); |
| | | } |
| | | assertEquals(searchOperation.getSearchEntries().size(), shouldMatch ? 1 : 0); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.DirectoryServerTestCase; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.Requests; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.opends.server.util.StaticUtils.*; |
| | | import static org.testng.Assert.*; |
| | |
| | | public void testSearchhasSubordinatesAttrVirtualAttrsOnly(DN entryDN, boolean hasSubs) |
| | | throws Exception |
| | | { |
| | | SearchFilter filter = SearchFilter.objectClassPresent(); |
| | | LinkedHashSet<String> attrList = new LinkedHashSet<String>(1); |
| | | attrList.add("hasSubordinates"); |
| | | SearchRequest request = Requests.newSearchRequest(entryDN, SearchScope.BASE_OBJECT) |
| | | .addAttribute("hasSubordinates") |
| | | .addControl(new LDAPControl(OID_VIRTUAL_ATTRS_ONLY, true)); |
| | | |
| | | LinkedList<Control> requestControls = new LinkedList<Control>(); |
| | | requestControls.add(new LDAPControl(OID_VIRTUAL_ATTRS_ONLY, true)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | entryDN, SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, filter, attrList, null); |
| | | searchOperation.run(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | InternalSearchOperation searchOperation = conn.processSearch(request); |
| | | assertEquals(searchOperation.getSearchEntries().size(), 1); |
| | | |
| | | Entry e = searchOperation.getSearchEntries().get(0); |
| | |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | | import java.util.*; |
| | | import java.util.Collections; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.std.meta.VirtualAttributeCfgDefn; |
| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.ldap.LDAPFilter; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.opends.server.types.Entry; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.types.VirtualAttributeRule; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * A set of test cases for the isMemberOf virtual attribute provider. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | public class IsMemberOfVirtualAttributeProviderTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | | // The attribute type for the isMemberOf attribute. |
| | | /** The attribute type for the isMemberOf attribute. */ |
| | | private AttributeType isMemberOfType; |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass() |
| | | public void startServer() |
| | | throws Exception |
| | | @BeforeClass |
| | | public void startServer() throws Exception |
| | | { |
| | | TestCaseUtils.restartServer(); |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testStaticGroupMembershipMember() |
| | | throws Exception |
| | | { |
| | |
| | | assertFalse(a.contains(ByteString.valueOf("invalid"))); |
| | | } |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete(DN.valueOf("cn=test static group,ou=groups,o=test")); |
| | | getRootConnection().processDelete(DN.valueOf("cn=test static group,ou=groups,o=test")); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testStaticGroupMembershipUniqueMember() |
| | | throws Exception |
| | | @Test |
| | | public void testStaticGroupMembershipUniqueMember() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | |
| | | assertFalse(a.contains(ByteString.valueOf("invalid"))); |
| | | } |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete(DN.valueOf("cn=test static group,ou=groups,o=test")); |
| | | getRootConnection().processDelete(DN.valueOf("cn=test static group,ou=groups,o=test")); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testDynamicGroupMembership() |
| | | throws Exception |
| | | @Test |
| | | public void testDynamicGroupMembership() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | |
| | | assertFalse(a.contains(ByteString.valueOf("invalid"))); |
| | | } |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete( |
| | | DN.valueOf("cn=test dynamic group,ou=groups,o=test")); |
| | | getRootConnection().processDelete(DN.valueOf("cn=test dynamic group,ou=groups,o=test")); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testMultipleStaticGroups() |
| | | throws Exception |
| | | @Test |
| | | public void testMultipleStaticGroups() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | |
| | | assertFalse(a.contains(ByteString.valueOf("invalid"))); |
| | | } |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete(DN.valueOf("cn=test group 1,ou=groups,o=test")); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testMultipleGroups() |
| | | throws Exception |
| | | @Test |
| | | public void testMultipleGroups() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | |
| | | assertFalse(a.contains(ByteString.valueOf("invalid"))); |
| | | } |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete(DN.valueOf("cn=test group 1,ou=groups,o=test")); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | |
| | | /** |
| | | * Tests the {@code isMultiValued} method. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testIsMultiValued() |
| | | { |
| | | IsMemberOfVirtualAttributeProvider provider = |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testMatchesSubstring() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testGreaterThanOrEqualTo() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testLessThanOrEqualTo() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testApproximatelyEqualTo() |
| | | throws Exception |
| | | { |
| | |
| | | new Object[] { "(isMemberOf=*)", false, false }, |
| | | new Object[] { "(isMemberOf=cn*)", false, false }, |
| | | new Object[] { "(isMemberOf=invalid)", true, false }, |
| | | new Object[] { "(&(isMemberOf=invalid1)(isMemberOf=invalid2))", |
| | | true, false }, |
| | | new Object[] { "(isMemberOf>=cn=Test Group 1,ou=Groups,o=test)", |
| | | false, false }, |
| | | new Object[] { "(isMemberOf<=cn=Test Group 1,ou=Groups,o=test)", |
| | | false, false }, |
| | | new Object[] { "(isMemberOf~=cn=Test Group 1,ou=Groups,o=test)", |
| | | false, false }, |
| | | new Object[] { "(isMemberOf=cn=Test Group 1,ou=Groups,o=test)", |
| | | true, true }, |
| | | new Object[] { "(isMemberOf=cn=Test Group 2,ou=Groups,o=test)", |
| | | true, false }, |
| | | new Object[] { "(&(isMemberOf=invalid1)(isMemberOf=invalid2))", true, false }, |
| | | new Object[] { "(isMemberOf>=cn=Test Group 1,ou=Groups,o=test)", false, false }, |
| | | new Object[] { "(isMemberOf<=cn=Test Group 1,ou=Groups,o=test)", false, false }, |
| | | new Object[] { "(isMemberOf~=cn=Test Group 1,ou=Groups,o=test)", false, false }, |
| | | new Object[] { "(isMemberOf=cn=Test Group 1,ou=Groups,o=test)", true, true }, |
| | | new Object[] { "(isMemberOf=cn=Test Group 2,ou=Groups,o=test)", true, false }, |
| | | new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" + |
| | | "(givenName=test))", |
| | | true, true }, |
| | | "(givenName=test))", true, true }, |
| | | new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" + |
| | | "(isMemberOf=invalid))", |
| | | true, false }, |
| | | "(isMemberOf=invalid))", true, false }, |
| | | new Object[] { "(&(isMemberOf=invalid)" + |
| | | "(isMemberOf=cn=Test Group 1,ou=Groups,o=test))", |
| | | true, false }, |
| | | "(isMemberOf=cn=Test Group 1,ou=Groups,o=test))", true, false }, |
| | | new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" + |
| | | "(givenName=not test))", |
| | | true, false }, |
| | | "(givenName=not test))", true, false }, |
| | | new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" + |
| | | "(isMemberOf=cn=Test Group 2,ou=Groups,o=test))", |
| | | true, false }, |
| | | "(isMemberOf=cn=Test Group 2,ou=Groups,o=test))", true, false }, |
| | | new Object[] { "(&(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" + |
| | | "(isMemberOf=cn=Test Group 3,ou=Groups,o=test))", |
| | | true, true }, |
| | | "(isMemberOf=cn=Test Group 3,ou=Groups,o=test))", true, true }, |
| | | new Object[] { "(&(isMemberOf=cn=Test Group 2,ou=Groups,o=test)" + |
| | | "(isMemberOf=cn=Test Group 4,ou=Groups,o=test))", |
| | | true, false }, |
| | | "(isMemberOf=cn=Test Group 4,ou=Groups,o=test))", true, false }, |
| | | new Object[] { "(|(isMemberOf=cn=Test Group 1,ou=Groups,o=test)" + |
| | | "(isMemberOf=cn=Test Group 3,ou=Groups,o=test))", |
| | | false, false }, |
| | | "(isMemberOf=cn=Test Group 3,ou=Groups,o=test))", false, false }, |
| | | }; |
| | | } |
| | | |
| | |
| | | VirtualAttributeCfgDefn.ConflictBehavior. |
| | | VIRTUAL_OVERRIDES_REAL); |
| | | |
| | | SearchFilter filter = SearchFilter.createFilterFromString(filterString); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | null, |
| | | DN.valueOf("o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, filter, null, null); |
| | | |
| | | SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filterString); |
| | | InternalSearchOperation searchOperation = new InternalSearchOperation( |
| | | getRootConnection(), nextOperationID(), nextMessageID(), request, null); |
| | | assertEquals(provider.isSearchable(rule, |
| | | new LocalBackendSearchOperation(searchOperation), false), isSearchable); |
| | | // isMemberOf is not searchable with preIndexed set to true |
| | |
| | | VirtualAttributeCfgDefn.ConflictBehavior. |
| | | VIRTUAL_OVERRIDES_REAL); |
| | | |
| | | SearchFilter filter = SearchFilter.createFilterFromString(filterString); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | null, |
| | | DN.valueOf("o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, filter, null, null); |
| | | SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filterString); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | InternalSearchOperation searchOperation = new InternalSearchOperation( |
| | | conn, nextOperationID(), nextMessageID(), request, null); |
| | | provider.processSearch(rule, new LocalBackendSearchOperation(searchOperation)); |
| | | |
| | | boolean matchFound = false; |
| | |
| | | * Tests if a search using ismemberof works for a dynamic group with large |
| | | * number of entries to simulate unindexed searches. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testLargeDynamicGroupMembership() throws Exception |
| | | { |
| | | String SUFFIX=",dc=example,dc=com"; |
| | |
| | | DirectoryServer.getEntry(DN.valueOf("cn=user.0,ou=People"+SUFFIX)); |
| | | assertNotNull(e); |
| | | //Do an ldapsearch. |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | new ArrayList<Control>(), |
| | | ByteString.valueOf("dc=example,dc=com"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, |
| | | Integer.MAX_VALUE, |
| | | Integer.MAX_VALUE, |
| | | false, |
| | | LDAPFilter.decode("(&(objectclass=Person)" + |
| | | "(isMemberOf=cn=MyDGrp,ou=groups,dc=example,dc=com))"), |
| | | null, null); |
| | | |
| | | searchOperation.run(); |
| | | String filter = "(&(objectclass=Person)" |
| | | + "(isMemberOf=cn=MyDGrp,ou=groups,dc=example,dc=com))"; |
| | | SearchRequest request = newSearchRequest("dc=example,dc=com", SearchScope.WHOLE_SUBTREE, filter) |
| | | .setTimeLimit(Integer.MAX_VALUE) |
| | | .setSizeLimit(Integer.MAX_VALUE); |
| | | |
| | | InternalSearchOperation searchOperation = getRootConnection().processSearch(request); |
| | | assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS); |
| | | List<SearchResultEntry> entries = searchOperation.getSearchEntries(); |
| | | assertTrue(entries.size()>4000); |
| | |
| | | package org.opends.server.extensions; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.admin.std.meta.VirtualAttributeCfgDefn; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import org.opends.server.protocols.ldap.LDAPControl; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.SearchFilter; |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | |
| | | public void testSearchStructuralOCAttrRealAttrsOnly(DN entryDN) |
| | | throws Exception |
| | | { |
| | | SearchFilter filter = SearchFilter.objectClassPresent(); |
| | | LinkedHashSet<String> attrList = new LinkedHashSet<String>(1); |
| | | attrList.add("structuralObjectClass"); |
| | | |
| | | LinkedList<Control> requestControls = new LinkedList<Control>(); |
| | | requestControls.add(new LDAPControl(OID_REAL_ATTRS_ONLY, true)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection |
| | | .nextOperationID(), InternalClientConnection |
| | | .nextMessageID(), requestControls, entryDN, |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, filter, |
| | | attrList, null); |
| | | searchOperation.run(); |
| | | SearchRequest request = newSearchRequest(entryDN, SearchScope.BASE_OBJECT) |
| | | .addAttribute("structuralObjectClass") |
| | | .addControl(new LDAPControl(OID_REAL_ATTRS_ONLY, true)); |
| | | InternalSearchOperation searchOperation = getRootConnection().processSearch(request); |
| | | assertEquals(searchOperation.getSearchEntries().size(), 1); |
| | | |
| | | Entry e = searchOperation.getSearchEntries().get(0); |
| | |
| | | public void testSearchStructuralOCAttrVirtualAttrsOnly(DN entryDN) |
| | | throws Exception |
| | | { |
| | | SearchFilter filter = SearchFilter.objectClassPresent(); |
| | | LinkedHashSet<String> attrList = new LinkedHashSet<String>(1); |
| | | attrList.add("structuralObjectClass"); |
| | | SearchRequest request = newSearchRequest(entryDN, SearchScope.BASE_OBJECT) |
| | | .addAttribute("structuralObjectClass") |
| | | .addControl(new LDAPControl(OID_VIRTUAL_ATTRS_ONLY, true)); |
| | | |
| | | LinkedList<Control> requestControls = new LinkedList<Control>(); |
| | | requestControls.add(new LDAPControl(OID_VIRTUAL_ATTRS_ONLY, true)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection |
| | | .nextOperationID(), InternalClientConnection |
| | | .nextMessageID(), requestControls, entryDN, |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, filter, |
| | | attrList, null); |
| | | searchOperation.run(); |
| | | InternalSearchOperation searchOperation = getRootConnection().processSearch(request); |
| | | assertEquals(searchOperation.getSearchEntries().size(), 1); |
| | | |
| | | Entry e = searchOperation.getSearchEntries().get(0); |
| | |
| | | /** |
| | | * Tests the {@code isMultiValued} method. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testIsMultiValued() |
| | | { |
| | | StructuralObjectClassVirtualAttributeProvider provider = |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testGetValues() throws Exception |
| | | { |
| | | StructuralObjectClassVirtualAttributeProvider provider = |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testHasAnyValue() |
| | | throws Exception |
| | | @Test |
| | | public void testHasAnyValue() throws Exception |
| | | { |
| | | StructuralObjectClassVirtualAttributeProvider provider = |
| | | new StructuralObjectClassVirtualAttributeProvider(); |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testHasMatchingValue() |
| | | throws Exception |
| | | @Test |
| | | public void testHasMatchingValue() throws Exception |
| | | { |
| | | StructuralObjectClassVirtualAttributeProvider provider = |
| | | new StructuralObjectClassVirtualAttributeProvider(); |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testHasNonMatchingValue() |
| | | throws Exception |
| | | @Test |
| | | public void testHasNonMatchingValue() throws Exception |
| | | { |
| | | StructuralObjectClassVirtualAttributeProvider provider = |
| | | new StructuralObjectClassVirtualAttributeProvider(); |
| | |
| | | |
| | | |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.api.WorkQueue; |
| | | import org.opends.server.core.DirectoryServer; |
| | |
| | | import org.opends.server.plugins.DelayPreOpPlugin; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.schema.SchemaConstants; |
| | | import org.opends.server.tools.LDAPSearch; |
| | | import org.opends.server.types.Attributes; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.opends.server.types.Modification; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * A set of test cases for the traditional work queue. |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @BeforeClass() |
| | | public void startServer() |
| | | throws Exception |
| | | @BeforeClass |
| | | public void startServer() throws Exception |
| | | { |
| | | TestCaseUtils.startServer(); |
| | | } |
| | |
| | | * Tests to ensure that the work queue is configured and enabled within the |
| | | * Directory Server. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testWorkQueueEnabled() |
| | | { |
| | | WorkQueue workQueue = DirectoryServer.getWorkQueue(); |
| | | WorkQueue<?> workQueue = DirectoryServer.getWorkQueue(); |
| | | assertNotNull(workQueue); |
| | | assertTrue(workQueue instanceof TraditionalWorkQueue); |
| | | } |
| | |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create(attr, "30"))); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | ModifyOperation modifyOperation = conn.processModify(dn, mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | List<Control> requestControls = DelayPreOpPlugin.createDelayControlList(5000); |
| | | SearchFilter filter = SearchFilter.objectClassPresent(); |
| | | LinkedHashSet<String> attrs = new LinkedHashSet<String>(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.BASE_OBJECT) |
| | | .addControl(DelayPreOpPlugin.createDelayControlList(5000)); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(),requestControls, |
| | | DN.valueOf("o=test"), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, filter, attrs, null); |
| | | new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request); |
| | | DirectoryServer.getWorkQueue().submitOperation(searchOperation); |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | |
| | | assertTrue((stopTime - startTime) >= 4000); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the {@code WorkQueue.waitUntilIdle()} method for a case in which the |
| | | * work queue should not be idle for several seconds. |
| | |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | |
| | | List<Control> requestControls = DelayPreOpPlugin.createDelayControlList(5000); |
| | | SearchFilter filter = SearchFilter.objectClassPresent(); |
| | | LinkedHashSet<String> attrs = new LinkedHashSet<String>(); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.BASE_OBJECT) |
| | | .addControl(DelayPreOpPlugin.createDelayControlList(5000)); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("o=test"), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, |
| | | 0, false, filter, attrs, null); |
| | | new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request); |
| | | DirectoryServer.getWorkQueue().submitOperation(searchOperation); |
| | | |
| | | long startTime = System.currentTimeMillis(); |
| | |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.Requests; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Attribute; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.VirtualAttributeRule; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | public class UserDefinedVirtualAttributeProviderTestCase |
| | | extends ExtensionsTestCase |
| | | { |
| | | // The attribute type for the description attribute. |
| | | /** The attribute type for the description attribute. */ |
| | | private AttributeType descriptionType; |
| | | |
| | | // The attribute type for the ds-privilege-name attribute. |
| | | /** The attribute type for the ds-privilege-name attribute. */ |
| | | private AttributeType privNameType; |
| | | |
| | | // The attribute type for the ds-pwp-password-policy-dn attribute. |
| | | /** The attribute type for the ds-pwp-password-policy-dn attribute. */ |
| | | private AttributeType pwPolicyDNType; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Ensures that the Directory Server is running. |
| | | * |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testRuleAPISingleValued() |
| | | throws Exception |
| | | { |
| | |
| | | "ds-cfg-conflict-behavior: real-overrides-virtual", |
| | | "ds-cfg-value: single value"); |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | try |
| | | { |
| | | SearchRequest request = Requests.newSearchRequest(DN.valueOf(ruleDN), SearchScope.BASE_OBJECT); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection |
| | | .nextOperationID(), InternalClientConnection |
| | | .nextMessageID(), null, DN.valueOf(ruleDN), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), |
| | | null, null); |
| | | new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request); |
| | | |
| | | for (VirtualAttributeRule rule : DirectoryServer |
| | | .getVirtualAttributes()) |
| | | for (VirtualAttributeRule rule : DirectoryServer.getVirtualAttributes()) |
| | | { |
| | | if (rule.getAttributeType().equals(descriptionType)) |
| | | { |
| | |
| | | ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | } |
| | | |
| | | } |
| | | finally |
| | | { |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete(DN.valueOf(ruleDN)); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(DN.valueOf(ruleDN)); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testRuleAPIMultiValued() |
| | | throws Exception |
| | | { |
| | |
| | | "ds-cfg-value: first value", |
| | | "ds-cfg-value: second value"); |
| | | |
| | | InternalClientConnection conn = getRootConnection(); |
| | | try |
| | | { |
| | | SearchRequest request = Requests.newSearchRequest(DN.valueOf(ruleDN), SearchScope.BASE_OBJECT); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection |
| | | .nextOperationID(), InternalClientConnection |
| | | .nextMessageID(), null, DN.valueOf(ruleDN), |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), |
| | | null, null); |
| | | new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request); |
| | | |
| | | for (VirtualAttributeRule rule : DirectoryServer |
| | | .getVirtualAttributes()) |
| | | for (VirtualAttributeRule rule : DirectoryServer.getVirtualAttributes()) |
| | | { |
| | | if (rule.getAttributeType().equals(descriptionType)) |
| | | { |
| | |
| | | } |
| | | finally |
| | | { |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete(DN.valueOf(ruleDN)); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(DN.valueOf(ruleDN)); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the creation of a description virtual attribute when there is only a |
| | | * single virtual value and no real value. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testSingleDescriptionOnlyVirtual() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testMultipleDescriptionsOnlyVirtual() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testSingleDescriptionRealOverridesVirtual() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testSingleDescriptionVirtualOverridesReal() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testSingleDescriptionMergeRealAndVirtual() |
| | | throws Exception |
| | | { |
| | |
| | | * @throws Exception |
| | | * If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testSingleDescriptionMergeRealAndVirtualWithAttrList() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualPrivilege() |
| | | throws Exception |
| | | { |
| | |
| | | } |
| | | finally |
| | | { |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete(DN.valueOf(ruleDN)); |
| | | DeleteOperation deleteOperation = conn.processDelete(DN.valueOf(ruleDN)); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | deleteOperation = conn.processDelete(DN.valueOf(policyDN)); |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualPasswordPolicyDN() |
| | | throws Exception |
| | | { |
| | |
| | | } |
| | | finally |
| | | { |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete(DN.valueOf(ruleDN)); |
| | | DeleteOperation deleteOperation = getRootConnection().processDelete(DN.valueOf(ruleDN)); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | } |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.ConditionResult; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testCreateValidGroup() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testGroupAPI() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testGroupAPINonexistent() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualGroupDynamicGroupWithMember() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualGroupStaticGroupWithMember() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualGroupStaticGroupWithUniqueMember() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualAttributeAPI() |
| | | throws Exception |
| | | { |
| | |
| | | assertEquals(provider.approximatelyEqualTo(entry, rule, null), |
| | | ConditionResult.UNDEFINED); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | SearchFilter filter = SearchFilter.createFilterFromString("(member=" + u1 + ")"); |
| | | SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filter); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), null, DN.valueOf("o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(member=" + u1 + ")"), |
| | | null, null); |
| | | new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request); |
| | | assertFalse(provider.isSearchable(rule, searchOperation, false)); |
| | | assertFalse(provider.isSearchable(rule, searchOperation, true)); |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualAttributeAPINonexistent() |
| | | throws Exception |
| | | { |
| | |
| | | assertEquals(provider.approximatelyEqualTo(entry, rule, null), |
| | | ConditionResult.UNDEFINED); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | SearchFilter filter = SearchFilter.createFilterFromString("(member=" + u1 + ")"); |
| | | SearchRequest request = newSearchRequest(DN.valueOf("o=test"), SearchScope.WHOLE_SUBTREE, filter); |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), null, DN.valueOf("o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString("(member=" + u1 + ")"), |
| | | null, null); |
| | | new InternalSearchOperation(getRootConnection(), nextOperationID(), nextMessageID(), request); |
| | | assertFalse(provider.isSearchable(rule, searchOperation, false)); |
| | | assertFalse(provider.isSearchable(rule, searchOperation, false)); |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualAttrDynamicGroupWithMember() |
| | | throws Exception |
| | | { |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | @Test |
| | | public void testVirtualAttrDynamicGroupWithUpdatedMemberURLs() |
| | | throws Exception |
| | | { |
| | |
| | | ByteString v = ByteString.valueOf(u4.toString()); |
| | | assertTrue(a.contains(v)); |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | LinkedList<Modification> mods = new LinkedList<Modification>(); |
| | | mods.add(new Modification(ModificationType.ADD, |
| | | Attributes.create("memberurl", |
| | | "ldap:///o=test??sub?(objectClass=person)"))); |
| | | ModifyOperation modifyOperation = conn.processModify(d1, mods); |
| | | ModifyOperation modifyOperation = getRootConnection().processModify(d1, mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | a = e.getAttribute(memberType).get(0); |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testAllowRetrievingMembership() |
| | | throws Exception |
| | | @Test |
| | | public void testAllowRetrievingMembership() throws Exception |
| | | { |
| | | TestCaseUtils.initializeTestBackend(true); |
| | | TestCaseUtils.addEntries(LDIF_LINES); |
| | |
| | | assertTrue(a.contains(v)); |
| | | |
| | | |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | LinkedList<Modification> mods = new LinkedList<Modification>(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.protocols.ldap.LDAPFilter; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.opends.server.types.Entry; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.opends.server.types.SearchResultReference; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Tests the second constructor, which takes processed arguments, without |
| | | * providing an internal search listener. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testConstructor2WithoutListener() |
| | | throws Exception |
| | | { |
| | | InternalClientConnection conn = getRootConnection(); |
| | | new InternalSearchOperation(conn, nextOperationID(), |
| | | nextMessageID(), new ArrayList<Control>(), |
| | | DN.rootDN(), SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), |
| | | new LinkedHashSet<String>(), null); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the second constructor, which takes processed arguments, with an |
| | | * internal search listener. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test() |
| | | public void testConstructor2WithListener() |
| | | throws Exception |
| | | { |
| | | InternalClientConnection conn = getRootConnection(); |
| | | new InternalSearchOperation(conn, nextOperationID(), |
| | | nextMessageID(), new ArrayList<Control>(), |
| | | DN.rootDN(), SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, |
| | | false, SearchFilter.objectClassPresent(), |
| | | new LinkedHashSet<String>(), |
| | | new TestInternalSearchListener()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests the <CODE>getSearchEntries</CODE> and |
| | | * <CODE>getSearchReferences</CODE> methods. |
| | | * |
| | |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | * This class provides a set of test cases for the Directory Server JMX |
| | | * privilege subsystem. |
| | | */ |
| | | public class JmxPrivilegeTestCase |
| | | extends JmxTestCase |
| | | public class JmxPrivilegeTestCase extends JmxTestCase |
| | | { |
| | | // An array of boolean values that indicates whether config read operations |
| | | // should be successful for users in the corresponding slots of the |
| | | // connections array. |
| | | /** |
| | | * An array of boolean values that indicates whether config read operations |
| | | * should be successful for users in the corresponding slots of the |
| | | * connections array. |
| | | */ |
| | | private boolean[] successful; |
| | | |
| | | // The set of client connections that should be used when performing |
| | | // operations. |
| | | /** |
| | | * The set of client connections that should be used when performing |
| | | * operations. |
| | | */ |
| | | private JmxClientConnection[] connections; |
| | | |
| | | |
| | | |
| | | /** |
| | | * Make sure that the server is running and that an appropriate set of |
| | | * structures are in place. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Override |
| | | @BeforeClass(alwaysRun = true) |
| | | public void setUp() |
| | | throws Exception |
| | | @Override |
| | | public void setUp() throws Exception |
| | | { |
| | | super.setUp(); |
| | | |
| | |
| | | .valueOf("cn=test2 user,dc=unindexed,dc=jeb")); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | deleteOperation = conn.processDelete(DN |
| | | .valueOf("dc=unindexed,dc=jeb")); |
| | | deleteOperation = conn.processDelete(DN.valueOf("dc=unindexed,dc=jeb")); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | for (int i = 0; (connections != null) && (i < connections.length); i++) |
| | | for (int i = 0; connections != null && i < connections.length; i++) |
| | | { |
| | | connections[i].finalize(); |
| | | connections[i] = null; |
| | |
| | | } |
| | | |
| | | // Add JMX_READ privilege |
| | | InternalClientConnection rootConnection = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection rootConnection = getRootConnection(); |
| | | ArrayList<Modification> mods = new ArrayList<Modification>(); |
| | | mods.add(new Modification(ModificationType.ADD, Attributes.create( |
| | | "ds-privilege-name", "jmx-read"))); |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testProxyAuthV1Write(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | public void testProxyAuthV1Write(JmxClientConnection conn, boolean hasPrivilege) throws Exception |
| | | { |
| | | // We can't trust the value of hasPrivilege because root users don't get |
| | | // proxy privileges by default. So make the determination based on the |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testProxyAuthV1Read(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | public void testProxyAuthV1Read(JmxClientConnection conn, boolean hasPrivilege) throws Exception |
| | | { |
| | | // We can't trust the value of hasPrivilege because root users don't get |
| | | // proxy privileges by default. So make the determination based on the |
| | |
| | | |
| | | |
| | | // Test a search operation against the PWReset Target user. |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, conn.nextOperationID(), |
| | | conn.nextMessageID(), controls, targetDN, |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), null, |
| | | null); |
| | | SearchRequest request = newSearchRequest(targetDN, SearchScope.BASE_OBJECT).addControl(controls); |
| | | InternalSearchOperation searchOperation = new InternalSearchOperation( |
| | | conn, conn.nextOperationID(), conn.nextMessageID(), request, null); |
| | | searchOperation.run(); |
| | | |
| | | if (hasProxyPrivilege) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that the use of the Directory Server will properly respect |
| | | * the PROXIED_AUTH privilege for add, delete, modify and modify DN requests |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testProxyAuthV2Write(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | public void testProxyAuthV2Write(JmxClientConnection conn, boolean hasPrivilege) throws Exception |
| | | { |
| | | // We can't trust the value of hasPrivilege because root users don't get |
| | | // proxy privileges by default. So make the determination based on the |
| | |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testProxyAuthV2Read(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | public void testProxyAuthV2Read(JmxClientConnection conn, boolean hasPrivilege) throws Exception |
| | | { |
| | | // We can't trust the value of hasPrivilege because root users don't get |
| | | // proxy privileges by default. So make the determination based on the |
| | |
| | | |
| | | DN targetDN = DN.valueOf("cn=PWReset Target,o=test"); |
| | | ArrayList<Control> controls = new ArrayList<Control>(1); |
| | | controls.add(new ProxiedAuthV2Control( |
| | | ByteString.valueOf("dn:" + targetDN.toString()))); |
| | | controls.add(new ProxiedAuthV2Control(ByteString.valueOf("dn:" + targetDN))); |
| | | |
| | | |
| | | // Test a compare operation against the PWReset Target user. |
| | |
| | | |
| | | |
| | | // Test a search operation against the PWReset Target user. |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation(conn, conn.nextOperationID(), |
| | | conn.nextMessageID(), controls, targetDN, |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), null, |
| | | null); |
| | | SearchRequest request = newSearchRequest(targetDN, SearchScope.BASE_OBJECT).addControl(controls); |
| | | InternalSearchOperation searchOperation = new InternalSearchOperation( |
| | | conn, conn.nextOperationID(), conn.nextMessageID(), request, null); |
| | | searchOperation.run(); |
| | | |
| | | if (hasProxyPrivilege) |
| | |
| | | |
| | | |
| | | // Update the set of root privileges to include proxied auth. |
| | | InternalClientConnection internalRootConn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | ArrayList<Modification> mods = new ArrayList<Modification>(); |
| | | mods.add(new Modification(ModificationType.ADD, |
| | | Attributes.create("ds-cfg-default-root-privilege-name", |
| | | "proxied-auth"))); |
| | | ModifyOperation modifyOperation = |
| | | internalRootConn.processModify(DN.valueOf("cn=Root DNs,cn=config"), |
| | | mods); |
| | | conn.processModify(DN.valueOf("cn=Root DNs,cn=config"), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | |
| | | Attributes.create("ds-cfg-default-root-privilege-name", |
| | | "proxied-auth"))); |
| | | modifyOperation = |
| | | internalRootConn.processModify(DN.valueOf("cn=Root DNs,cn=config"), |
| | | mods); |
| | | conn.processModify(DN.valueOf("cn=Root DNs,cn=config"), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | |
| | |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | private Task getCompletedTask(DN taskEntryDN) |
| | | throws Exception |
| | | private Task getCompletedTask(DN taskEntryDN) throws Exception |
| | | { |
| | | TaskBackend taskBackend = |
| | | (TaskBackend) DirectoryServer.getBackend(DN.valueOf("cn=tasks")); |
| | |
| | | if (task == null) |
| | | { |
| | | long stopWaitingTime = System.currentTimeMillis() + 10000L; |
| | | while ((task == null) && (System.currentTimeMillis() < stopWaitingTime)) |
| | | while (task == null && System.currentTimeMillis() < stopWaitingTime) |
| | | { |
| | | Thread.sleep(10); |
| | | task = taskBackend.getScheduledTask(taskEntryDN); |
| | | } |
| | | } |
| | | |
| | | assertNotNull(task, "There is no such task " + taskEntryDN.toString()); |
| | | assertNotNull(task, "There is no such task " + taskEntryDN); |
| | | if (! TaskState.isDone(task.getTaskState())) |
| | | { |
| | | long stopWaitingTime = System.currentTimeMillis() + 20000L; |
| | | while ((! TaskState.isDone(task.getTaskState())) && |
| | | (System.currentTimeMillis() < stopWaitingTime)) |
| | | while (!TaskState.isDone(task.getTaskState()) |
| | | && System.currentTimeMillis() < stopWaitingTime) |
| | | { |
| | | Thread.sleep(10); |
| | | } |
| | | } |
| | | |
| | | assertTrue(TaskState.isDone(task.getTaskState()), |
| | | "Task " + taskEntryDN.toString() |
| | | + " did not complete in a timely manner."); |
| | | |
| | | "Task " + taskEntryDN + " did not complete in a timely manner."); |
| | | return task; |
| | | } |
| | | } |
| | |
| | | package org.opends.server.schema; |
| | | |
| | | import java.util.ArrayList; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.controls.ServerSideSortRequestControl; |
| | | import org.opends.server.controls.VLVRequestControl; |
| | | import org.opends.server.protocols.internal.InternalClientConnection; |
| | | import org.opends.server.protocols.internal.InternalSearchOperation; |
| | | import org.opends.server.protocols.internal.SearchRequest; |
| | | import org.opends.server.protocols.ldap.LDAPFilter; |
| | | import org.opends.server.tools.LDAPModify; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.opends.server.types.Control; |
| | | import org.opends.server.types.DN; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.opends.server.types.Entry; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.types.SearchFilter; |
| | | import org.opends.server.types.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.testng.annotations.BeforeClass; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.*; |
| | | import static org.opends.server.protocols.internal.Requests.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * This Test Class tests various collation matching rules. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | public final class CollationMatchingRuleTest |
| | | extends SchemaTestCase |
| | | { |
| | |
| | | public void searchCollationEqualityUsingOID() throws Exception |
| | | { |
| | | //Search the collation rule with OID of en and no suffix in the filter. |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | conn, nextOperationID(), nextMessageID(), |
| | | null, |
| | | ByteString.valueOf("uid=user,o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | |
| | | { |
| | | //Search the collation rule with language tag of en and no suffix |
| | | //in the filter. |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | conn, nextOperationID(), nextMessageID(), |
| | | null, |
| | | ByteString.valueOf("uid=user,o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | |
| | | public void searchCollationLTUsingOIDSuffix() throws Exception |
| | | { |
| | | //Search the collation rule with OID of es and suffix in the filter. |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | conn, nextOperationID(), nextMessageID(), |
| | | null, |
| | | ByteString.valueOf("uid=user,o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | |
| | | public void searchCollationLTEUsingLanguageSuffix() throws Exception |
| | | { |
| | | //Search the collation rule with tag of fr and suffix in the filter. |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | conn, nextOperationID(), nextMessageID(), |
| | | null, |
| | | ByteString.valueOf("uid=user,o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | |
| | | public void searchCollationGTUsingLanguage() throws Exception |
| | | { |
| | | //Search the collation rule with tag of fr in the filter. |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | conn, nextOperationID(), nextMessageID(), |
| | | null, |
| | | ByteString.valueOf("uid=user,o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | |
| | | public void searchCollationGTEUsingLanguage() throws Exception |
| | | { |
| | | //Search the collation rule with tag of es and suffix in the filter. |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | conn, nextOperationID(), nextMessageID(), |
| | | null, |
| | | ByteString.valueOf("uid=user,o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | |
| | | *It searches for string quebec against the value of sn which is |
| | | * Qu\u00e9bec. |
| | | */ |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | InternalClientConnection conn = getRootConnection(); |
| | | |
| | | InternalSearchOperation searchOperation = |
| | | new InternalSearchOperation( |
| | | conn, |
| | | InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), |
| | | conn, nextOperationID(), nextMessageID(), |
| | | null, |
| | | ByteString.valueOf("uid=user,o=test"), |
| | | SearchScope.WHOLE_SUBTREE, |
| | |
| | | expectedDNOrder.add(user1); |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("displayname:fr")); |
| | | ValidateSortControl(expectedDNOrder, |
| | | requestControls, |
| | | "displayname:fr-FR.6:=A*"); |
| | | ValidateSortControl("displayname:fr-FR.6:=A*", expectedDNOrder, requestControls); |
| | | } |
| | | |
| | | |
| | |
| | | expectedDNOrder.add(user1); |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("displayname:es")); |
| | | ValidateSortControl(expectedDNOrder, |
| | | requestControls, |
| | | "displayname:es.6:=A*"); |
| | | ValidateSortControl("displayname:es.6:=A*", expectedDNOrder, requestControls); |
| | | } |
| | | |
| | | |
| | |
| | | expectedDNOrder.add(user4); |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("-displayname:en")); |
| | | ValidateSortControl(expectedDNOrder, |
| | | requestControls, |
| | | "displayname:en-US.6:=A*"); |
| | | ValidateSortControl("displayname:en-US.6:=A*", expectedDNOrder, requestControls); |
| | | } |
| | | |
| | | |
| | |
| | | ArrayList<Control> requestControls = new ArrayList<Control>(); |
| | | requestControls.add(new ServerSideSortRequestControl("displayname:fr")); |
| | | requestControls.add(new VLVRequestControl(0, 4, 1, 0)); |
| | | ValidateSortControl(expectedDNOrder, |
| | | requestControls, |
| | | "objectclass=inetOrgPerson"); |
| | | ValidateSortControl("objectclass=inetOrgPerson", expectedDNOrder, requestControls); |
| | | } |
| | | |
| | | |
| | | |
| | | private void ValidateSortControl(ArrayList<DN> expectedDNOrder, |
| | | ArrayList<Control> requestControls, |
| | | String searchFilter) throws Exception |
| | | private void ValidateSortControl(String searchFilter, |
| | | ArrayList<DN> expectedDNOrder, |
| | | ArrayList<Control> requestControls) throws Exception |
| | | { |
| | | try |
| | | { |
| | | populateEntriesForControl(); |
| | | InternalClientConnection conn = |
| | | InternalClientConnection.getRootConnection(); |
| | | |
| | | InternalSearchOperation internalSearch = |
| | | new InternalSearchOperation(conn, InternalClientConnection.nextOperationID(), |
| | | InternalClientConnection.nextMessageID(), requestControls, |
| | | DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.createFilterFromString(searchFilter), |
| | | null, null); |
| | | |
| | | internalSearch.run(); |
| | | SearchRequest request = newSearchRequest(DN.valueOf("dc=example,dc=com"), SearchScope.WHOLE_SUBTREE, searchFilter) |
| | | .addControl(requestControls); |
| | | InternalSearchOperation internalSearch = getRootConnection().processSearch(request); |
| | | assertEquals(internalSearch.getResultCode(), ResultCode.SUCCESS); |
| | | ArrayList<DN> returnedDNOrder = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | returnedDNOrder.add(e.getName()); |
| | | } |
| | | assertEquals(returnedDNOrder, expectedDNOrder); |
| | | assertEquals(getDNs(internalSearch), expectedDNOrder); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | private ArrayList<DN> getDNs(InternalSearchOperation internalSearch) |
| | | { |
| | | ArrayList<DN> results = new ArrayList<DN>(); |
| | | for (Entry e : internalSearch.getSearchEntries()) |
| | | { |
| | | results.add(e.getName()); |
| | | } |
| | | return results; |
| | | } |
| | | |
| | | |
| | | private void populateEntriesForControl() throws Exception |
| | | { |
| | |
| | | import java.util.concurrent.CopyOnWriteArraySet; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DereferenceAliasesPolicy; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | |
| | | |
| | | |
| | | // Test a search operation against the PWReset Target user. |
| | | InternalSearchOperation searchOperation = new InternalSearchOperation(conn, |
| | | nextOperationID(), nextMessageID(), controls, targetDN, |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), null, |
| | | null); |
| | | searchOperation.run(); |
| | | SearchRequest request = newSearchRequest(targetDN, SearchScope.BASE_OBJECT).addControl(controls); |
| | | InternalSearchOperation searchOperation = conn.processSearch(request); |
| | | assertProxyPrivilege(searchOperation.getResultCode(), hasProxyPrivilege); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | // Test a search operation against the PWReset Target user. |
| | | InternalSearchOperation searchOperation = new InternalSearchOperation(conn, nextOperationID(), |
| | | nextMessageID(), controls, targetDN, |
| | | SearchScope.BASE_OBJECT, |
| | | DereferenceAliasesPolicy.NEVER, 0, 0, false, |
| | | SearchFilter.objectClassPresent(), null, |
| | | null); |
| | | SearchRequest request = newSearchRequest(targetDN, SearchScope.BASE_OBJECT).addControl(controls); |
| | | InternalSearchOperation searchOperation = conn.processSearch(request); |
| | | searchOperation.run(); |
| | | assertProxyPrivilege(searchOperation.getResultCode(), hasProxyPrivilege); |
| | | } |