From 90716a659b32365f8076ce32bfdb8ddd539c2942 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 27 Apr 2012 17:30:29 +0000
Subject: [PATCH] Checkpoint current working copy.
---
/dev/null | 24 ----
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Validator.java | 12 +-
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/package-info.java | 2
opendj3/opendj-rest2ldap/pom.xml | 6 +
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPResource.java | 219 +++++++++++++++++++++++++++---------
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AttributeMapper.java | 65 +++++-----
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/EntryContainer.java | 29 ++++
7 files changed, 232 insertions(+), 125 deletions(-)
diff --git a/opendj3/opendj-rest2ldap/pom.xml b/opendj3/opendj-rest2ldap/pom.xml
index b7fe6c0..8c52fc1 100644
--- a/opendj3/opendj-rest2ldap/pom.xml
+++ b/opendj3/opendj-rest2ldap/pom.xml
@@ -56,6 +56,12 @@
<version>1.1.0</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.forgerock.commons</groupId>
+ <artifactId>org.forgerock.json.resource</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AttributeMapper.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AttributeMapper.java
index 3d6c4de..32e593e 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AttributeMapper.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/AttributeMapper.java
@@ -24,6 +24,8 @@
import org.forgerock.json.fluent.JsonValue;
import org.forgerock.opendj.ldap.Attribute;
import org.forgerock.opendj.ldap.Entry;
+import org.forgerock.opendj.ldap.ResultHandler;
+import org.forgerock.resource.provider.Context;
/**
*
@@ -31,38 +33,6 @@
public interface AttributeMapper {
/**
- * Transforms attributes contained in the provided LDAP entry to JSON
- * content, invoking a completion handler once the transformation has
- * completed.
- * <p>
- * This method is invoked whenever an LDAP entry is converted to a REST
- * resource, i.e. when responding to read, query, create, put, or patch
- * requests.
- *
- * @param c
- * @param e
- * @param v
- * @param h
- */
- void toJson(Context c, Entry e, JsonValue v, CompletionHandler<JsonValue> h);
-
- /**
- * Transforms JSON content in the provided JSON value to LDAP attributes,
- * invoking a completion handler once the transformation has completed.
- * <p>
- * This method is invoked whenever a REST resource is converted to an LDAP
- * entry or LDAP modification, i.e. when performing create, put, or patch
- * requests.
- *
- * @param c
- * @param v
- * @param a
- * @param h
- */
- void toLDAP(Context c, JsonValue v, List<Attribute> a,
- CompletionHandler<Entry> h);
-
- /**
* Returns an unmodifiable set containing the names of the LDAP attributes
* required by this attribute mapper. The returned set should only contain
* the names of attributes found in the LDAP entry directly associated with
@@ -88,6 +58,37 @@
*/
Collection<String> getLDAPAttributesFor(JsonPointer resourceAttribute);
+ /**
+ * Transforms attributes contained in the provided LDAP entry to JSON
+ * content, invoking a completion handler once the transformation has
+ * completed.
+ * <p>
+ * This method is invoked whenever an LDAP entry is converted to a REST
+ * resource, i.e. when responding to read, query, create, put, or patch
+ * requests.
+ *
+ * @param c
+ * @param e
+ * @param v
+ * @param h
+ */
+ void toJson(Context c, Entry e, JsonValue v, ResultHandler<JsonValue> h);
+
+ /**
+ * Transforms JSON content in the provided JSON value to LDAP attributes,
+ * invoking a completion handler once the transformation has completed.
+ * <p>
+ * This method is invoked whenever a REST resource is converted to an LDAP
+ * entry or LDAP modification, i.e. when performing create, put, or patch
+ * requests.
+ *
+ * @param c
+ * @param v
+ * @param a
+ * @param h
+ */
+ void toLDAP(Context c, JsonValue v, List<Attribute> a, ResultHandler<Entry> h);
+
// TODO: methods for obtaining schema information (e.g. name, description,
// type information).
// TODO: methods for creating filters createLDAPEqualityFilter().
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/CompletionHandler.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/CompletionHandler.java
deleted file mode 100644
index 4fd14e7..0000000
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/CompletionHandler.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyrighted [year] [name of copyright owner]".
- *
- * Copyright 2012 ForgeRock AS. All rights reserved.
- */
-
-package org.forgerock.opendj.rest2ldap;
-
-/**
- *
- */
-public interface CompletionHandler<T> {
-
- void completed(T result);
-
- void failed(Throwable t);
-}
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Context.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Context.java
deleted file mode 100644
index dcb7982..0000000
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Context.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyrighted [year] [name of copyright owner]".
- *
- * Copyright 2012 ForgeRock AS. All rights reserved.
- */
-
-package org.forgerock.opendj.rest2ldap;
-
-/**
- *
- */
-public final class Context {
- // FIXME: this is a stub until JsonResource is complete.
- public String getAuthenticationID() {
- return "bjensen";
- }
-}
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/EntryContainer.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/EntryContainer.java
index 3dd3de4..cb98f56 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/EntryContainer.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/EntryContainer.java
@@ -18,7 +18,10 @@
import java.util.Set;
-import org.forgerock.opendj.ldap.Entry;
+import org.forgerock.opendj.ldap.ResultHandler;
+import org.forgerock.opendj.ldap.SearchResultHandler;
+import org.forgerock.opendj.ldap.responses.SearchResultEntry;
+import org.forgerock.resource.provider.Context;
/**
*
@@ -26,8 +29,26 @@
public final class EntryContainer {
/**
+ * @param entry
+ * @return
+ */
+ public String getIDFromEntry(final SearchResultEntry entry) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * @param context
+ * @param handler
+ */
+ public void listEntries(final Context context, final SearchResultHandler handler) {
+ // TODO Auto-generated method stub
+
+ }
+
+ /**
* Reads the entry having the specified resource ID.
- *
+ *
* @param c
* The request context.
* @param id
@@ -37,8 +58,8 @@
* @param h
* The result handler.
*/
- public void readEntry(Context c, String id, Set<String> attributes,
- CompletionHandler<Entry> h) {
+ public void readEntry(final Context c, final String id, final Set<String> attributes,
+ final ResultHandler<SearchResultEntry> h) {
// TODO Auto-generated method stub
}
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPResource.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPResource.java
index ba2a5b1..579148f 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPResource.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPResource.java
@@ -16,6 +16,7 @@
package org.forgerock.opendj.rest2ldap;
+import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -23,114 +24,218 @@
import org.forgerock.json.fluent.JsonPointer;
import org.forgerock.json.fluent.JsonValue;
import org.forgerock.opendj.ldap.Entry;
+import org.forgerock.opendj.ldap.ErrorResultException;
+import org.forgerock.opendj.ldap.ResultHandler;
+import org.forgerock.opendj.ldap.SearchResultHandler;
+import org.forgerock.opendj.ldap.responses.Result;
+import org.forgerock.opendj.ldap.responses.SearchResultEntry;
+import org.forgerock.opendj.ldap.responses.SearchResultReference;
+import org.forgerock.resource.exception.NotSupportedException;
+import org.forgerock.resource.exception.ResourceException;
+import org.forgerock.resource.provider.ActionRequest;
+import org.forgerock.resource.provider.ActionResultHandler;
+import org.forgerock.resource.provider.Context;
+import org.forgerock.resource.provider.CreateRequest;
+import org.forgerock.resource.provider.CreateResultHandler;
+import org.forgerock.resource.provider.DeleteRequest;
+import org.forgerock.resource.provider.DeleteResultHandler;
+import org.forgerock.resource.provider.PatchRequest;
+import org.forgerock.resource.provider.PatchResultHandler;
+import org.forgerock.resource.provider.QueryRequest;
+import org.forgerock.resource.provider.QueryResultHandler;
+import org.forgerock.resource.provider.ReadRequest;
+import org.forgerock.resource.provider.ReadResultHandler;
+import org.forgerock.resource.provider.Resource;
+import org.forgerock.resource.provider.UpdateRequest;
+import org.forgerock.resource.provider.UpdateResultHandler;
/**
*
*/
-public class LDAPResource {
- // FIXME: This will inherit from JsonResource.
- private EntryContainer container;
- private List<AttributeMapper> mappers;
+public class LDAPResource implements Resource {
private Set<String> allLDAPAttributes;
+ private final EntryContainer container;
+ private final List<AttributeMapper> mappers;
/**
* Creates a new LDAP resource.
- *
+ *
* @param container
* The entry container which will be used to interact with the
* LDAP server.
* @param mappers
* The list of attribute mappers.
*/
- public LDAPResource(EntryContainer container, List<AttributeMapper> mappers) {
+ public LDAPResource(final EntryContainer container, final List<AttributeMapper> mappers) {
this.container = container;
this.mappers = mappers;
cacheAllLDAPAttributes();
}
/**
+ * {@inheritDoc}
+ */
+ public void action(final ActionRequest request, final Context context,
+ final ActionResultHandler out) {
+ out.setFailure(new NotSupportedException("Not yet implemented"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void create(final CreateRequest request, final Context context,
+ final CreateResultHandler out) {
+ out.setFailure(new NotSupportedException("Not yet implemented"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void delete(final DeleteRequest request, final Context context,
+ final DeleteResultHandler out) {
+ out.setFailure(new NotSupportedException("Not yet implemented"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void patch(final PatchRequest request, final Context context,
+ final PatchResultHandler out) {
+ out.setFailure(new NotSupportedException("Not yet implemented"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void query(final QueryRequest request, final Context context,
+ final QueryResultHandler out) {
+ out.setFailure(new NotSupportedException("Not yet implemented"));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void read(final ReadRequest request, final Context context, final ReadResultHandler out) {
+ final String id = request.getId();
+ if (id == null) {
+ // List the entries.
+ final SearchResultHandler handler = new SearchResultHandler() {
+ private final List<String> resourceIDs = new ArrayList<String>();
+
+ public boolean handleEntry(final SearchResultEntry entry) {
+ // TODO: should the resource or the container define the ID
+ // mapping?
+ resourceIDs.add(container.getIDFromEntry(entry));
+ return true;
+ }
+
+ public void handleErrorResult(final ErrorResultException error) {
+ out.setFailure(adaptErrorResult(error));
+ }
+
+ public boolean handleReference(final SearchResultReference reference) {
+ // TODO: should this be classed as an error since rest2ldap
+ // assumes entries are all colocated.
+ return true;
+ }
+
+ public void handleResult(final Result result) {
+ out.setResult(id, null, new JsonValue(resourceIDs));
+ }
+ };
+ container.listEntries(context, handler);
+ } else {
+ // Read a single entry.
+
+ // TODO: Determine the set of LDAP attributes that need to be read.
+ final Set<JsonPointer> requestedAttributes = new LinkedHashSet<JsonPointer>();
+ final Set<String> requestedLDAPAttributes =
+ getRequestedLDAPAttributes(requestedAttributes);
+
+ final ResultHandler<SearchResultEntry> handler =
+ new ResultHandler<SearchResultEntry>() {
+ public void handleErrorResult(final ErrorResultException error) {
+ out.setFailure(adaptErrorResult(error));
+ }
+
+ public void handleResult(final SearchResultEntry entry) {
+ final String revision = getRevisionFromEntry(entry);
+
+ final ResultHandler<JsonValue> mapHandler =
+ new ResultHandler<JsonValue>() {
+ public void handleErrorResult(
+ final ErrorResultException error) {
+ out.setFailure(adaptErrorResult(error));
+ }
+
+ public void handleResult(final JsonValue result) {
+ out.setResult(id, revision, result);
+ }
+ };
+ mapEntryToJson(context, requestedAttributes, entry, mapHandler);
+ }
+ };
+ container.readEntry(context, id, requestedLDAPAttributes, handler);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void update(final UpdateRequest request, final Context context,
+ final UpdateResultHandler out) {
+ out.setFailure(new NotSupportedException("Not yet implemented"));
+ }
+
+ private ResourceException adaptErrorResult(final ErrorResultException error) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
* Caches the set of LDAP attributes associated with all of this resource's
* mappers.
*/
private void cacheAllLDAPAttributes() {
allLDAPAttributes = new LinkedHashSet<String>(mappers.size());
- for (AttributeMapper mapper : mappers) {
+ for (final AttributeMapper mapper : mappers) {
allLDAPAttributes.addAll(mapper.getAllLDAPAttributes());
}
}
/**
- * Reads a resource from the LDAP directory.
- *
- * @param c
- * The request context.
- * @param r
- * The read request.
- * @param h
- * The read result handler.
- */
- public void read(final Context c, final ReadRequest r,
- final CompletionHandler<JsonValue> h) {
- // Determine the set of LDAP attributes that need to be read.
- final Set<JsonPointer> requestedAttributes = r.getRequestedAttributes();
- Set<String> requestedLDAPAttributes = getRequestedLDAPAttributes(requestedAttributes);
-
- // Create a completion handler which will convert the entry to a
- // JsonValue.
- CompletionHandler<Entry> eh = new CompletionHandler<Entry>() {
- public void failed(Throwable t) {
- // Unable to read the entry.
- handleReadFailure(c, h, t);
- }
-
- public void completed(Entry result) {
- // Convert the entry to a JsonValue.
- mapEntryToJson(c, requestedAttributes, result, h);
- }
-
- };
-
- // Read the entry.
- container.readEntry(c, r.getResourceID(), requestedLDAPAttributes, eh);
- }
-
- /**
* Determines the set of LDAP attributes to request in an LDAP read (search,
* post-read), based on the provided set of JSON pointers.
- *
+ *
* @param requestedAttributes
* The set of resource attributes to be read.
* @return The set of LDAP attributes associated with the resource
* attributes.
*/
- private Set<String> getRequestedLDAPAttributes(
- Set<JsonPointer> requestedAttributes) {
+ private Set<String> getRequestedLDAPAttributes(final Set<JsonPointer> requestedAttributes) {
if (requestedAttributes.isEmpty()) {
// Full read.
return allLDAPAttributes;
} else {
// Partial read.
- Set<String> requestedLDAPAttributes = new LinkedHashSet<String>(
- requestedAttributes.size());
- for (JsonPointer requestedAttribute : requestedAttributes) {
- for (AttributeMapper mapper : mappers) {
- requestedLDAPAttributes.addAll(mapper
- .getLDAPAttributesFor(requestedAttribute));
+ final Set<String> requestedLDAPAttributes =
+ new LinkedHashSet<String>(requestedAttributes.size());
+ for (final JsonPointer requestedAttribute : requestedAttributes) {
+ for (final AttributeMapper mapper : mappers) {
+ requestedLDAPAttributes.addAll(mapper.getLDAPAttributesFor(requestedAttribute));
}
}
return requestedLDAPAttributes;
}
}
- private void handleReadFailure(Context c, CompletionHandler<JsonValue> h,
- Throwable t) {
+ private String getRevisionFromEntry(final SearchResultEntry entry) {
// TODO Auto-generated method stub
-
+ return null;
}
- private void mapEntryToJson(Context c,
- Set<JsonPointer> requestedAttributes, Entry result,
- CompletionHandler<JsonValue> h) {
+ private void mapEntryToJson(final Context c, final Set<JsonPointer> requestedAttributes,
+ final Entry result, final ResultHandler<JsonValue> h) {
// TODO Auto-generated method stub
}
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReadRequest.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReadRequest.java
deleted file mode 100644
index 6d35430..0000000
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/ReadRequest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyrighted [year] [name of copyright owner]".
- *
- * Copyright 2012 ForgeRock AS. All rights reserved.
- */
-
-package org.forgerock.opendj.rest2ldap;
-
-import java.util.Collections;
-import java.util.Set;
-
-import org.forgerock.json.fluent.JsonPointer;
-
-/**
- *
- */
-public class ReadRequest extends RestRequest {
- // FIXME: this is a stub until JsonResource is complete.
-
- public String getResourceID() {
- return "dummy";
- }
-
- public Set<JsonPointer> getRequestedAttributes() {
- return Collections.emptySet();
- }
-}
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/RestRequest.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/RestRequest.java
deleted file mode 100644
index 684f549..0000000
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/RestRequest.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyrighted [year] [name of copyright owner]".
- *
- * Copyright 2012 ForgeRock AS. All rights reserved.
- */
-
-package org.forgerock.opendj.rest2ldap;
-
-/**
- *
- */
-public class RestRequest {
-
-}
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Validator.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Validator.java
index b91de14..6812619 100644
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Validator.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/Validator.java
@@ -21,21 +21,21 @@
*/
final class Validator {
- private Validator() {
- // Prevent instantiation.
- }
-
- static <T> T ensureNotNull(T object) {
+ static <T> T ensureNotNull(final T object) {
if (object == null) {
throw new NullPointerException();
}
return object;
}
- static <T> T ensureNotNull(T object, String message) {
+ static <T> T ensureNotNull(final T object, final String message) {
if (object == null) {
throw new NullPointerException(message);
}
return object;
}
+
+ private Validator() {
+ // Prevent instantiation.
+ }
}
diff --git a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/package-info.java b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/package-info.java
index 3bfa0f4..97a6106 100755
--- a/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/package-info.java
+++ b/opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/package-info.java
@@ -29,5 +29,3 @@
*/
package org.forgerock.opendj.rest2ldap;
-
-
--
Gitblit v1.10.0