From b825d6e6631ee7733c4a793e2465994fe117f538 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 15 Oct 2014 15:39:36 +0000
Subject: [PATCH] Converted opendj3 code to use SearchRequest like API
---
opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java | 8 +-
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java | 97 +++-----------------------------
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/config/JMXMBean.java | 18 ++----
3 files changed, 20 insertions(+), 103 deletions(-)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/config/JMXMBean.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/config/JMXMBean.java
index a2a709d..bbb3cbe 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/config/JMXMBean.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/config/JMXMBean.java
@@ -64,7 +64,6 @@
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.jmx.Credential;
import org.opends.server.protocols.jmx.JmxClientConnection;
-import org.opends.server.protocols.ldap.LDAPFilter;
import org.opends.server.types.AttributeType;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
@@ -481,14 +480,12 @@
// Perform the Ldap operation for
// - ACI Check
// - Loggin purpose
- InternalSearchOperation op=null;
+ SearchRequest request = newSearchRequest(configEntryDN, SearchScope.BASE_OBJECT);
+ InternalSearchOperation op = null;
if (clientConnection instanceof JmxClientConnection) {
- op = ((JmxClientConnection)clientConnection).processSearch(
- ByteString.valueOf(configEntryDN.toString()),
- SearchScope.BASE_OBJECT, LDAPFilter.objectClassPresent());
+ op = ((JmxClientConnection) clientConnection).processSearch(request);
}
else if (clientConnection instanceof InternalClientConnection) {
- SearchRequest request = newSearchRequest(configEntryDN, SearchScope.BASE_OBJECT);
op = ((InternalClientConnection) clientConnection).processSearch(request);
}
// BUG : op may be null
@@ -545,8 +542,7 @@
*/
@Override
public AttributeList getAttributes(String[] attributes)
- {
-
+ {
//
// Get the jmx Client connection
ClientConnection clientConnection = getClientConnection();
@@ -559,14 +555,12 @@
// Perform the Ldap operation for
// - ACI Check
// - Loggin purpose
+ SearchRequest request = newSearchRequest(configEntryDN, SearchScope.BASE_OBJECT);
InternalSearchOperation op = null;
if (clientConnection instanceof JmxClientConnection) {
- op = ((JmxClientConnection)clientConnection).processSearch(
- ByteString.valueOf(configEntryDN.toString()),
- SearchScope.BASE_OBJECT, LDAPFilter.objectClassPresent());
+ op = ((JmxClientConnection) clientConnection).processSearch(request);
}
else if (clientConnection instanceof InternalClientConnection) {
- SearchRequest request = newSearchRequest(configEntryDN, SearchScope.BASE_OBJECT);
op = ((InternalClientConnection) clientConnection).processSearch(request);
}
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java
index 9443d4b..0f3257b 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/protocols/jmx/JmxClientConnection.java
@@ -39,16 +39,13 @@
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
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.api.ClientConnection;
import org.opends.server.api.ConnectionHandler;
import org.opends.server.core.*;
import org.opends.server.core.networkgroups.NetworkGroup;
-import org.opends.server.protocols.internal.InternalSearchListener;
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.*;
import static org.opends.messages.ProtocolMessages.*;
@@ -765,55 +762,21 @@
/**
* Processes an Jmx search operation with the provided information.
- * It will not dereference any aliases, will not request a size or time limit,
- * and will retrieve all user attributes.
*
- * @param rawBaseDN The base DN for the search.
- * @param scope The scope for the search.
- * @param filter The filter for the search.
- *
+ * @param request The search request.
* @return A reference to the internal search operation that was processed
* and contains information about the result of the processing as
* well as lists of the matching entries and search references.
*/
- public InternalSearchOperation processSearch(ByteString rawBaseDN,
- SearchScope scope, LDAPFilter filter)
+ public InternalSearchOperation processSearch(SearchRequest request)
{
- return processSearch(rawBaseDN, scope,
- DereferenceAliasesPolicy.NEVER, 0, 0, false,
- filter, new LinkedHashSet<String>(0));
- }
-
-
-
- /**
- * Processes an Jmx search operation with the provided information.
- *
- * @param rawBaseDN The base DN for the search.
- * @param scope The scope for the search.
- * @param derefPolicy The alias dereferencing policy for the search.
- * @param sizeLimit The size limit for the search.
- * @param timeLimit The time limit for the search.
- * @param typesOnly The typesOnly flag for the search.
- * @param filter The filter for the search.
- * @param attributes The set of requested attributes for the search.
- *
- * @return A reference to the internal search operation that was processed
- * and contains information about the result of the processing as
- * well as lists of the matching entries and search references.
- */
- public InternalSearchOperation processSearch(ByteString rawBaseDN,
- SearchScope scope,
- DereferenceAliasesPolicy derefPolicy,
- int sizeLimit, int timeLimit,
- boolean typesOnly, LDAPFilter filter,
- LinkedHashSet<String> attributes)
- {
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(this, nextOperationID(), nextMessageID(),
- new ArrayList<Control>(0), rawBaseDN,
- scope, derefPolicy, sizeLimit, timeLimit,
- typesOnly, filter, attributes, null);
+ 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);
if (! hasPrivilege(Privilege.JMX_READ, null))
{
@@ -828,46 +791,6 @@
return searchOperation;
}
-
-
- /**
- * Processes an Jmx search operation with the provided information.
- *
- * @param rawBaseDN The base DN for the search.
- * @param scope The scope for the search.
- * @param derefPolicy The alias dereferencing policy for the search.
- * @param sizeLimit The size limit for the search.
- * @param timeLimit The time limit for the search.
- * @param typesOnly The typesOnly flag for the search.
- * @param filter The filter for the search.
- * @param attributes The set of requested attributes for the search.
- * @param searchListener The internal search listener that should be used to
- * handle the matching entries and references.
- *
- * @return A reference to the internal search operation that was processed
- * and contains information about the result of the processing.
- */
- public InternalSearchOperation processSearch(ByteString rawBaseDN,
- SearchScope scope,
- DereferenceAliasesPolicy derefPolicy,
- int sizeLimit, int timeLimit,
- boolean typesOnly, LDAPFilter filter,
- LinkedHashSet<String> attributes,
- InternalSearchListener searchListener)
- {
- InternalSearchOperation searchOperation =
- new InternalSearchOperation(this, nextOperationID(), nextMessageID(),
- new ArrayList<Control>(0), rawBaseDN,
- scope, derefPolicy, sizeLimit, timeLimit,
- typesOnly, filter, attributes,
- searchListener);
-
- searchOperation.run();
- return searchOperation;
- }
-
-
-
/**
* Sends the provided search result entry to the client.
*
diff --git a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
index fffe578..1b55199 100644
--- a/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
+++ b/opendj-sdk/opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxPrivilegeTestCase.java
@@ -59,7 +59,7 @@
import org.opends.server.core.SchemaConfigManager;
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.*;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -68,6 +68,7 @@
import static org.opends.messages.ProtocolMessages.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
import static org.testng.Assert.*;
/**
@@ -481,9 +482,8 @@
{
assertEquals(conn.hasPrivilege(Privilege.JMX_READ, null), hasPrivilege);
- ByteString dn = ByteString.valueOf("cn=config");
- LDAPFilter filter = LDAPFilter.objectClassPresent();
- InternalSearchOperation searchOperation = conn.processSearch(dn, SearchScope.BASE_OBJECT, filter);
+ SearchRequest request = newSearchRequest(DN.valueOf("cn=config"), SearchScope.BASE_OBJECT);
+ InternalSearchOperation searchOperation = conn.processSearch(request);
if (hasPrivilege)
{
assertEquals(searchOperation.getResultCode(), ResultCode.SUCCESS);
--
Gitblit v1.10.0