incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vram...@apache.org
Subject svn commit: r1156202 [1/2] - in /sling/whiteboard/vramdal: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sling/ src/main/java/org/apache/sling/samples/ src/main/java/org/apache/sling/samples/ldap...
Date Wed, 10 Aug 2011 14:52:05 GMT
Author: vramdal
Date: Wed Aug 10 14:52:04 2011
New Revision: 1156202

URL: http://svn.apache.org/viewvc?rev=1156202&view=rev
Log:
Initial commit of LdapResource

Added:
    sling/whiteboard/vramdal/LICENSE
    sling/whiteboard/vramdal/NOTICE
    sling/whiteboard/vramdal/README.txt
    sling/whiteboard/vramdal/pom.xml
    sling/whiteboard/vramdal/src/
    sling/whiteboard/vramdal/src/main/
    sling/whiteboard/vramdal/src/main/java/
    sling/whiteboard/vramdal/src/main/java/org/
    sling/whiteboard/vramdal/src/main/java/org/apache/
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/Adapter.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapOperation.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResource.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/EntryAdapter.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapAttributeMap.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceImpl.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/AddOperation.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/DeleteOperation.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListChildrenOperation.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/LookupEntryOperation.java
    sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java
    sling/whiteboard/vramdal/src/main/resources/
    sling/whiteboard/vramdal/src/main/resources/OSGI-INF/
    sling/whiteboard/vramdal/src/main/resources/OSGI-INF/metatype/
    sling/whiteboard/vramdal/src/main/resources/OSGI-INF/metatype/metatype.properties
    sling/whiteboard/vramdal/src/test/
    sling/whiteboard/vramdal/src/test/java/
    sling/whiteboard/vramdal/src/test/java/org/
    sling/whiteboard/vramdal/src/test/java/org/apache/
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/CommonTestUtil.java
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/api/
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/api/AdapterTest.java
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/AbstractLdapTest.java
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImplTest.java
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/MockLdapNetworkConnection.java
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/operations/
    sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperationTest.java

Added: sling/whiteboard/vramdal/LICENSE
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/LICENSE?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/LICENSE (added)
+++ sling/whiteboard/vramdal/LICENSE Wed Aug 10 14:52:04 2011
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

Added: sling/whiteboard/vramdal/NOTICE
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/NOTICE?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/NOTICE (added)
+++ sling/whiteboard/vramdal/NOTICE Wed Aug 10 14:52:04 2011
@@ -0,0 +1,6 @@
+Apache Sling LDAP Resource Provider
+Copyright 2011 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+

Added: sling/whiteboard/vramdal/README.txt
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/README.txt?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/README.txt (added)
+++ sling/whiteboard/vramdal/README.txt Wed Aug 10 14:52:04 2011
@@ -0,0 +1,41 @@
+Apache Sling LDAP Resource Provider
+
+This bundle provides an implementation of the ResourceProvider, allowing
+access to entries in an LDAP directory as Sling resources.
+
+Only read-only access is supported.
+
+To configure LDAP access, install this bundle, and head over to
+http://localhost:8080/system/console/configMgr
+Here you should find Apache Sling LDAP Resource Provider where you can add
+LDAP connections.
+
+Note that due to a bug (SLING-2170) in the current release of Sling Explorer, LDAP resources will not
+show correctly when using http://localhost:8080/.explorer.html
+Instead, to verify that LDAP resources are present, use the JsonRendererServlet by
+browsing to http://localhost:8080/ldap.3.json
+Alternatively, use the GWT explorer, or an updated Sling Explorer build.
+
+
+Getting Started
+===============
+
+This component uses a Maven 2 (http://maven.apache.org/) build
+environment. It requires a Java 5 JDK (or higher) and Maven (http://maven.apache.org/)
+2.0.7 or later. We recommend to use the latest Maven version.
+
+If you have Maven 2 installed, you can compile and
+package the jar using the following command:
+
+    mvn package
+
+See the Maven 2 documentation for other build features.
+
+The latest source code for this component is available in the
+Subversion (http://subversion.tigris.org/) source repository of
+the Apache Software Foundation. If you have Subversion installed,
+you can checkout the latest source using the following command:
+
+    svn checkout http://svn.apache.org/repos/asf/sling/trunk/samples/ldapresource
+
+See the Subversion documentation for other source control features.
\ No newline at end of file

Added: sling/whiteboard/vramdal/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/pom.xml?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/pom.xml (added)
+++ sling/whiteboard/vramdal/pom.xml Wed Aug 10 14:52:04 2011
@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<!--suppress osmorcNonOsgiMavenDependency -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.samples.ldap.resource</artifactId>
+    <packaging>bundle</packaging>
+    <version>1.0-SNAPSHOT</version>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>10</version>
+    </parent>
+    <name>Apache Sling LDAP Resource Provider</name>
+    <description>Bundle implementing a ResourceProvider for LDAP directories</description>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <version>1.4.4</version>
+                <executions>
+                    <execution>
+                        <id>generate-scr-descriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <version>2.0.1</version>
+                <configuration>
+                    <instructions>
+                        <Private-Package>org.apache.sling.samples.ldap.resource.*</Private-Package>
+                        <Export-Package>org.apache.sling.samples.ldap.resource.api</Export-Package>
+                        <Embed-Dependency>shared-all,antlr,commons-lang,commons-pool,mina-core,xml-apis,xpp3,dom4j,jaxen</Embed-Dependency>
+                        <Embed-Transitive>true</Embed-Transitive>
+                        <Import-Package>!com.sun.*,!org.gjt.*,!org.relaxng.*,!nu.xom,!org.jdom,!org.jdom.*,*</Import-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.directory.shared</groupId>
+            <artifactId>shared-all</artifactId>
+            <version>1.0.0-M5</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.directory.shared</groupId>
+            <artifactId>shared-ldap-model</artifactId>
+            <version>1.0.0-M5</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>antlr</groupId>
+            <artifactId>antlr</artifactId>
+            <version>2.7.7</version>
+        </dependency>
+        <dependency>
+            <groupId>jaxen</groupId>
+            <artifactId>jaxen</artifactId>
+            <version>1.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.6</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-pool</groupId>
+            <artifactId>commons-pool</artifactId>
+            <version>1.5.6</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.mina</groupId>
+            <artifactId>mina-core</artifactId>
+            <version>2.0.4</version>
+        </dependency>
+        <dependency>
+            <groupId>xml-apis</groupId>
+            <artifactId>xml-apis</artifactId>
+            <version>2.0.2</version>
+        </dependency>
+        <dependency>
+            <groupId>xpp3</groupId>
+            <artifactId>xpp3</artifactId>
+            <version>1.1.4c</version>
+        </dependency>
+        <dependency>
+            <groupId>dom4j</groupId>
+            <artifactId>dom4j</artifactId>
+            <version>1.6.1</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
+            <version>2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.api</artifactId>
+            <version>2.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.5.10</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <version>1.0.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.testing</artifactId>
+            <version>2.0.8</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <version>1.5.2</version>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.16</version>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.2.0</version>
+        </dependency>
+    </dependencies>
+</project>

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/Adapter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/Adapter.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/Adapter.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/Adapter.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.api;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public interface Adapter<Input, Output> {
+
+    public Output adapt(Input input);
+
+    public static class IteratorAdapter<Input, Output> implements Adapter<Iterator<Input>, Iterator<Output>> {
+
+        private Adapter<Input, Output> adapter;
+
+        public IteratorAdapter(Adapter<Input, Output> adapter) {
+            this.adapter = adapter;
+        }
+
+        public Iterator<Output> adapt(final Iterator<Input> inputIterator) {
+            return new Iterator<Output>() {
+                @Override
+                public boolean hasNext() {
+                    return inputIterator.hasNext();
+                }
+
+                @Override
+                public Output next() {
+                    return adapter.adapt(inputIterator.next());
+                }
+
+                @Override
+                public void remove() {
+                    inputIterator.remove();
+                }
+            };
+        }
+    }
+
+    public class ListAdapter<Input, Output> implements Adapter<List<Input>, List<Output>>{
+
+        private Adapter<Input, Output> adapter;
+
+        public ListAdapter(Adapter<Input, Output> adapter) {
+            this.adapter = adapter;
+        }
+
+        @Override
+        public List<Output> adapt(final List<Input> input) {
+            List<Output> result = new ArrayList<Output>();
+            for (Input in : input) {
+                result.add(adapter.adapt(in));
+            }
+            return result;
+        }
+    }
+
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapOperation.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapOperation.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapOperation.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapOperation.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.api;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+
+public interface LdapOperation<T> {
+
+    public T invoke(final LdapConnection connection, String providerRoot) throws Exception;
+
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResource.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResource.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResource.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResource.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.api;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+
+import java.util.Iterator;
+
+public interface LdapResource extends Resource {
+    String getPath();
+
+    String getName();
+
+    Resource getParent();
+
+    Iterator<Resource> listChildren();
+
+    Resource getChild(String relPath);
+
+    String getResourceType();
+
+    String getResourceSuperType();
+
+    boolean isResourceType(String resourceType);
+
+    ResourceMetadata getResourceMetadata();
+
+    ResourceResolver getResourceResolver();
+
+    <AdapterType> AdapterType adaptTo(Class<AdapterType> type);
+
+    String getDn();
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.api;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public interface LdapResourceProvider extends ResourceProvider {
+    Resource getResource(ResourceResolver resourceResolver, HttpServletRequest request, String path);
+
+    Resource getResource(ResourceResolver resourceResolver, String path);
+
+    Iterator<Resource> listChildren(Resource parent);
+
+    <T> T doOperation(LdapOperation<T> op);
+
+    void delete(Resource resource);
+
+    void add(String path, Map<String, Object[]> attributes);
+
+    Iterator<LdapResource> getAttributeValues(String entryDn, String attributeName, ResourceResolver resourceResolver);
+
+    List<String> getReferencingResources(String searchBaseDn, String entryDn, String attributeName, ResourceResolver resourceResolver);
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/EntryAdapter.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/EntryAdapter.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/EntryAdapter.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/EntryAdapter.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl;
+
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.samples.ldap.resource.api.Adapter;
+import org.apache.sling.samples.ldap.resource.api.LdapResource;
+
+public class EntryAdapter implements Adapter<Entry, LdapResource> {
+
+    private LdapResourceProviderImpl ldapResourceProvider;
+    private ResourceResolver resourceResolver;
+
+    public EntryAdapter(LdapResourceProviderImpl ldapResourceProvider, ResourceResolver resourceResolver) {
+        this.ldapResourceProvider = ldapResourceProvider;
+        this.resourceResolver = resourceResolver;
+    }
+
+    static LdapResourceImpl adaptToResource(LdapResourceProviderImpl ldapResourceProvider, ResourceResolver resourceResolver, Entry entry) {
+        return new LdapResourceImpl(entry, LdapService.translateDnToPath(entry.getDn().getName(), ldapResourceProvider.getBaseDn(), ldapResourceProvider.getProviderRoot()), resourceResolver, ldapResourceProvider);
+    }
+
+    @Override
+    public LdapResource adapt(Entry entry) {
+        return adaptToResource(ldapResourceProvider, resourceResolver, entry);
+    }
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapAttributeMap.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapAttributeMap.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapAttributeMap.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapAttributeMap.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.model.entry.Attribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultAttribute;
+import org.apache.directory.shared.ldap.model.entry.DefaultModification;
+import org.apache.directory.shared.ldap.model.entry.Modification;
+import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.sling.api.resource.PersistableValueMap;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.samples.ldap.resource.api.LdapOperation;
+import org.apache.sling.samples.ldap.resource.api.LdapResourceProvider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class LdapAttributeMap implements PersistableValueMap {
+
+    private org.apache.directory.shared.ldap.model.entry.Entry entry;
+    private LdapResourceProvider ldapResourceProvider;
+    private Map<String, Object> values = new HashMap<String, Object>();
+
+    public LdapAttributeMap(org.apache.directory.shared.ldap.model.entry.Entry entry, LdapResourceProvider ldapResourceProvider) {
+        this.entry = entry;
+        this.ldapResourceProvider = ldapResourceProvider;
+        readAttributes(entry);
+    }
+
+    private void readAttributes(org.apache.directory.shared.ldap.model.entry.Entry entry) {
+        this.values.put("dn", this.entry.getDn().getName());
+        for (Attribute attribute : entry) {
+            this.values.put(attribute.getId(), attribute.get().getString());
+        }
+    }
+
+    public <T> T get(String name, Class<T> type) {
+        if (type.isAssignableFrom(String.class)) {
+            //noinspection unchecked
+            return (T) this.values.get(name);
+        } else {
+            return null;
+        }
+    }
+
+    public <T> T get(String name, T defaultValue) {
+        if (this.values.containsKey(name)) {
+            //noinspection unchecked
+            return (T) get(name);
+        } else {
+            return defaultValue;
+        }
+    }
+
+    public int size() {
+        return values.size();
+    }
+
+    public boolean isEmpty() {
+        return values.isEmpty();
+    }
+
+    public boolean containsKey(Object o) {
+        return values.containsKey(o);
+    }
+
+    public boolean containsValue(Object o) {
+        return values.containsValue(o);
+    }
+
+    public Object get(Object o) {
+        return values.get(o);
+    }
+
+    public Object put(String s, Object o) {
+        return values.put(s, o);
+    }
+
+    public Object remove(Object o) {
+        return values.remove(o);
+    }
+
+    public void putAll(Map<? extends String, ?> map) {
+        values.putAll(map);
+    }
+
+    public void clear() {
+        values.clear();
+    }
+
+    public Set<String> keySet() {
+        return values.keySet();
+    }
+
+    public Collection<Object> values() {
+        return values.values();
+    }
+
+    public Set<Entry<String, Object>> entrySet() {
+        return values.entrySet();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return o instanceof LdapAttributeMap && values.equals(o);
+    }
+
+    @Override
+    public int hashCode() {
+        return values.hashCode();
+    }
+
+    public void save() throws PersistenceException {
+        List<Modification> modifications = new ArrayList<Modification>();
+        for (String propName : values.keySet()) {
+            if (propName.equals("dn") || propName.equals("uid")) {
+                continue;
+            }
+            Attribute oldAttribute = entry.get(propName);
+            String value = (String) values.get(propName);
+            try {
+                if (oldAttribute == null) {
+                    entry.add(propName, value);
+                } else {
+                    DefaultAttribute newAttribute = new DefaultAttribute(oldAttribute.getId(), value);
+                    DefaultModification modification = new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, newAttribute);
+                    modifications.add(modification);
+                }
+            } catch (LdapException e) {
+                throw new PersistenceException("Error saving attribute " + propName, e);
+            }
+        }
+        SaveAttributesOperation operation = new SaveAttributesOperation(entry, modifications);
+        this.ldapResourceProvider.doOperation(operation);
+    }
+
+    public void reset() {
+        this.values.clear();
+        readAttributes(this.entry);
+    }
+
+    public class SaveAttributesOperation implements LdapOperation<Void> {
+
+        private org.apache.directory.shared.ldap.model.entry.Entry entry;
+        private List<Modification> modifications;
+
+        public SaveAttributesOperation(org.apache.directory.shared.ldap.model.entry.Entry entry, List<Modification> modifications) {
+            this.entry = entry;
+            this.modifications = modifications;
+        }
+
+        public Void invoke(LdapConnection connection, String providerRoot) throws Exception {
+            connection.modify(entry.getDn(), modifications.toArray(new Modification[modifications.size()]));
+            return null;
+        }
+
+        public Void getResult() {
+            return null;
+        }
+    }
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceImpl.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceImpl.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceImpl.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl;
+
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.model.name.Dn;
+import org.apache.sling.api.adapter.SlingAdaptable;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.samples.ldap.resource.api.LdapResource;
+import org.apache.sling.samples.ldap.resource.api.LdapResourceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Iterator;
+import java.util.Map;
+
+public class LdapResourceImpl extends SlingAdaptable implements LdapResource {
+    public static final String RESOURCE_SUPERTYPE = "ldap";
+    private String path;
+    private ResourceResolver resourceResolver;
+    private LdapResourceProvider ldapResourceProvider;
+    private String resourceType;
+    private String resourceSuperType;
+    private ValueMap values;
+    private static final Logger log = LoggerFactory.getLogger(LdapResource.class);
+    private ResourceMetadata resourceMetadata;
+    private Dn dn;
+    public static final String RT_PREFIX = RESOURCE_SUPERTYPE + "/";
+
+    public LdapResourceImpl(Entry entry, String path, ResourceResolver resourceResolver, LdapResourceProvider ldapResourceProvider) {
+        try {
+            this.path = path;
+            this.resourceResolver = resourceResolver;
+            this.ldapResourceProvider = ldapResourceProvider;
+            this.resourceType = RT_PREFIX + entry.get("objectClass").getString();
+            this.resourceSuperType = RESOURCE_SUPERTYPE;
+            this.values = new LdapAttributeMap(entry, ldapResourceProvider);
+            this.resourceMetadata = new ResourceMetadata();
+            this.resourceMetadata.setResolutionPath(path);
+            this.dn = entry.getDn();
+        } catch (LdapInvalidAttributeValueException e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
+    public String getPath() {
+        return this.path;
+    }
+
+    public String getName() {
+        return ResourceUtil.getName(this.path);
+    }
+
+    public Resource getParent() {
+        return this.resourceResolver.getResource(ResourceUtil.getParent(this.path));
+    }
+
+    public Iterator<Resource> listChildren() {
+        return this.resourceResolver.listChildren(this);
+    }
+
+    public Resource getChild(String relPath) {
+        return this.resourceResolver.getResource(this.path + "/" + relPath);
+    }
+
+    public String getResourceType() {
+        return this.resourceType;
+    }
+
+    public String getResourceSuperType() {
+        return this.resourceSuperType;
+    }
+
+    public boolean isResourceType(String resourceType) {
+        return ResourceUtil.isA(this, resourceType);
+    }
+
+    public ResourceMetadata getResourceMetadata() {
+        return resourceMetadata;
+    }
+
+    public ResourceResolver getResourceResolver() {
+        return this.resourceResolver;
+    }
+
+    public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+        if (Map.class.isAssignableFrom(type)) {
+            //noinspection unchecked
+            return (AdapterType) this.values;
+        } else {
+            return super.adaptTo(type);
+/*
+            log.info("Cannot adapt LdapResource to " + type.getName());
+            return null;
+*/
+        }
+    }
+
+    public String getDn() {
+        return dn.toString();
+    }
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Services;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.SyntheticResource;
+import org.apache.sling.samples.ldap.resource.api.Adapter;
+import org.apache.sling.samples.ldap.resource.api.LdapOperation;
+import org.apache.sling.samples.ldap.resource.api.LdapResource;
+import org.apache.sling.samples.ldap.resource.api.LdapResourceProvider;
+import org.apache.sling.samples.ldap.resource.impl.operations.AddOperation;
+import org.apache.sling.samples.ldap.resource.impl.operations.DeleteOperation;
+import org.apache.sling.samples.ldap.resource.impl.operations.ListChildrenOperation;
+import org.apache.sling.samples.ldap.resource.impl.operations.LookupEntryOperation;
+import org.apache.sling.samples.ldap.resource.impl.operations.ResolveReferencesOperation;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+@Component(description = "Maps the contents of an LDAP directory as Sling resources", getConfigurationFactory = true, metatype = true)
+@Services({@Service(ResourceProvider.class), @Service(LdapResourceProvider.class)})
+@Properties({
+        @Property(name = ResourceProvider.ROOTS, value = "/ldap")
+})
+public class LdapResourceProviderImpl implements LdapResourceProvider {
+
+    private static final Logger log = LoggerFactory.getLogger(LdapResourceProviderImpl.class);
+    public static final String RT_LDAP_ROOT = "ldap/root";
+    public static final String SUPERTYPE = "ldap";
+
+    @Property(name = "bindDn", value = "uid=admin,ou=system")
+    private String bindDn;
+
+    @Property(name = "bindPassword", value = "secret")
+    private String bindPassword;
+
+    @Property(name = "baseDn", value = "")
+    private String baseDn;
+
+    @Property(name = "hostname", value = "localhost")
+    private String hostname;
+
+    private String providerRoot;
+
+    @Property(name = "port", intValue = 10389)
+    private Integer port;
+
+    public Resource getResource(ResourceResolver resourceResolver, HttpServletRequest request, String path) {
+        return getResource(resourceResolver, path);
+    }
+
+    public Resource getResource(ResourceResolver resourceResolver, String path) {
+        if (path.equals(providerRoot)) {
+            return new SyntheticResource(resourceResolver, path, RT_LDAP_ROOT) {
+                @Override
+                public String getResourceSuperType() {
+                    return LdapResourceImpl.RESOURCE_SUPERTYPE;
+                }
+            };
+        }
+        LdapService connection = getLdapService();
+        LookupEntryOperation searchOperation = new LookupEntryOperation(path);
+        Entry result = connection.invoke(searchOperation);
+        if (result == null) {
+            return null;
+        } else {
+            return new LdapResourceImpl(result, path, resourceResolver, this);
+        }
+    }
+
+    LdapService getLdapService() {
+        return new LdapService(this);
+    }
+
+    public Iterator<Resource> listChildren(final Resource parent) {
+        LdapService connection = getLdapService();
+        ResourceResolver resourceResolver = parent.getResourceResolver();
+        if (parent.getPath().equals(providerRoot)) {
+            List<Resource> baseDnList = new ArrayList<Resource>();
+            baseDnList.add(getResource(resourceResolver, providerRoot + "/" + baseDn));
+            return baseDnList.iterator();
+        } else {
+            if (!(parent.isResourceType(SUPERTYPE))) {
+                return null;
+            }
+            ListChildrenOperation op = new ListChildrenOperation(parent.getPath());
+            List<Resource> result = new ArrayList<Resource>();
+            List<Entry> entries = connection.invoke(op);
+            for (Entry entry : entries) {
+                Resource resource = EntryAdapter.adaptToResource(this, resourceResolver, entry);
+                result.add(resource);
+            }
+
+            return result.listIterator();
+        }
+    }
+
+    @Override
+    public void delete(Resource resource) {
+        LdapService connection = getLdapService();
+        DeleteOperation operation = new DeleteOperation(resource.getPath());
+        connection.invoke(operation);
+    }
+
+    @Override
+    public void add(final String path, final Map<String, Object[]> attributes) {
+        LdapService connection = getLdapService();
+        AddOperation operation = new AddOperation(attributes, LdapService.translatePathToDn(path, this.providerRoot));
+        connection.invoke(operation);
+    }
+
+    @Override
+    public Iterator<LdapResource> getAttributeValues(String entryDn, String attributeName, ResourceResolver resourceResolver) {
+        LdapService connection = getLdapService();
+        ListLdapOperation operation = new ListLdapOperation(entryDn, attributeName);
+        EntryAdapter adapter = new EntryAdapter(this, resourceResolver);
+        return new Adapter.IteratorAdapter<Entry, LdapResource>(adapter).adapt(connection.invoke(operation));
+    }
+
+    /**
+     *
+     * @param searchBaseDn
+     * @param entryDn
+     * @param attributeName
+     * @param resourceResolver
+     * @return An <code>Iterator</code> over paths that refer to entryDn
+     */
+    @Override
+    public List<String> getReferencingResources(final String searchBaseDn, final String entryDn, final String attributeName, ResourceResolver resourceResolver) {
+        LdapService connection = getLdapService();
+        LdapOperation<List<String>> operation = new ResolveReferencesOperation(searchBaseDn, attributeName, entryDn);
+
+        List<String> dns = connection.invoke(operation);
+        return new Adapter.ListAdapter<String, String>(new Adapter<String, String>() {
+            @Override
+            public String adapt(String dn) {
+                return LdapService.translateDnToPath(dn, LdapResourceProviderImpl.this.baseDn, LdapResourceProviderImpl.this.providerRoot);
+            }
+        }).adapt(dns);
+    }
+
+    public <T> T doOperation(LdapOperation<T> op) {
+        LdapService connection = getLdapService();
+        return connection.invoke(op);
+    }
+
+    public String getRoot() {
+        return providerRoot;
+    }
+
+    private static class ListLdapOperation implements LdapOperation<Iterator<Entry>> {
+
+        private String entryDn;
+        private String attributeName;
+
+        private ListLdapOperation(String entryDn, String attributeName) {
+            this.entryDn = entryDn;
+            this.attributeName = attributeName;
+        }
+
+        @Override
+        public Iterator<Entry> invoke(LdapConnection connection, String providerRoot) throws Exception {
+            EntryCursor cursor = connection.search(entryDn, "(objectclass=*)", SearchScope.OBJECT, attributeName);
+            return cursor.iterator();
+        }
+    }
+
+    String getBindDn() {
+        return bindDn;
+    }
+
+    String getBindPassword() {
+        return bindPassword;
+    }
+
+    String getBaseDn() {
+        return baseDn;
+    }
+
+    String getHostname() {
+        return hostname;
+    }
+
+    int getPort() {
+        return port;
+    }
+
+    public String getProviderRoot() {
+        return providerRoot;
+    }
+
+    @Activate
+    protected void activate(ComponentContext context) {
+        BundleContext bc = context.getBundleContext();
+        final Dictionary properties = context.getProperties();
+        if (properties != null) {
+            this.baseDn = properties.get("baseDn").toString();
+            this.providerRoot = properties.get(ResourceProvider.ROOTS).toString();
+            this.bindDn = properties.get("bindDn").toString();
+            this.bindPassword = properties.get("bindPassword").toString();
+            this.hostname = properties.get("hostname").toString();
+            this.port = (Integer) properties.get("port");
+        }
+    }
+
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.sling.samples.ldap.resource.api.LdapOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+public class LdapService {
+
+    private static final Logger log = LoggerFactory.getLogger(LdapService.class);
+    private String bindDn;
+    private String bindPassword;
+    private String providerRoot;
+    private String baseDn;
+
+    private LdapResourceProviderImpl provider;
+
+    public LdapService(LdapResourceProviderImpl provider) {
+        this.provider = provider;
+        this.bindDn = provider.getBindDn();
+        this.bindPassword = provider.getBindPassword();
+        this.providerRoot = provider.getRoot();
+        this.baseDn = provider.getBaseDn();
+    }
+
+    public static String translatePathToDn(String path, String providerRoot) {
+        if (!path.startsWith(providerRoot)) {
+            throw new IllegalArgumentException("Path must start with " + providerRoot);
+        }
+        path = path.substring(providerRoot.length() + 1);
+        String[] parts = path.split("/");
+        ArrayUtils.reverse(parts);
+        return StringUtils.join(parts, ',');
+    }
+
+    public static String translateDnToPath(String dn, String baseDn, String providerRoot) {
+        try {
+            String afterBase;
+            afterBase = dn.substring(0, dn.indexOf(baseDn));
+            String[] parts = afterBase.split(",");
+            ArrayUtils.reverse(parts);
+            return providerRoot + "/" + baseDn + "/" + StringUtils.join(parts, "/");
+        } catch (StringIndexOutOfBoundsException e) {
+            throw new IllegalArgumentException("Cannot convert dn '" + dn + "' to path, with baseDn='" + baseDn + "', providerRoot='" + providerRoot + "'", e);
+        }
+    }
+
+    public <T> T invoke(final LdapOperation<T> operation) {
+        LdapConnection connection = connect();
+        try {
+            connection.bind(bindDn, bindPassword);
+            if (!connection.isAuthenticated()) {
+                throw new IllegalStateException("Unable to authenticate, using DN " + bindDn);
+            }
+            return operation.invoke(connection, this.providerRoot);
+        } catch (LdapException e) {
+            throw new IllegalStateException("LdapException (using DN " + bindDn + ")", e);
+        } catch (IOException e) {
+            throw new IllegalStateException("IOException (using DN " + bindDn + ")", e);
+        } catch (Exception e) {
+            throw new IllegalStateException("Exception (using DN " + bindDn + ")", e);
+        } finally {
+            try {
+                connection.unBind();
+            } catch (LdapException e) {
+                log.warn("Exception unbinding connection", e);
+            }
+            try {
+                connection.close();
+            } catch (IOException e) {
+                log.warn("IOException while closing connection", e);
+            }
+        }
+    }
+
+    LdapNetworkConnection connect() {
+        return new LdapNetworkConnection(this.provider.getHostname(), this.provider.getPort());
+    }
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/AddOperation.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/AddOperation.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/AddOperation.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/AddOperation.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl.operations;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
+import org.apache.sling.samples.ldap.resource.api.LdapOperation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class AddOperation implements LdapOperation<Void> {
+    private final Map<String, Object[]> attributes;
+    private final String dn;
+
+    public AddOperation(Map<String, Object[]> attributes, String dn) {
+        this.attributes = attributes;
+        this.dn = dn;
+    }
+
+    @Override
+    public Void invoke(LdapConnection connection, String providerRoot) throws Exception {
+        List<Object> attributesList = new ArrayList<Object>();
+        for (Map.Entry<String, Object[]> attributeEntry : attributes.entrySet()) {
+            Object value = attributeEntry.getValue();
+            attributesList.add(attributeEntry.getKey() + ": " + value.toString());
+        }
+        connection.add(new DefaultEntry(connection.getSchemaManager(), dn, attributesList.toArray(new Object[attributesList.size()])));
+        return null;
+    }
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/DeleteOperation.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/DeleteOperation.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/DeleteOperation.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/DeleteOperation.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl.operations;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.sling.samples.ldap.resource.api.LdapOperation;
+import org.apache.sling.samples.ldap.resource.impl.LdapService;
+
+import java.util.List;
+
+public class DeleteOperation implements LdapOperation<Void> {
+
+    private String path;
+
+    public DeleteOperation(String path) {
+        this.path = path;
+    }
+
+    @Override
+    public Void invoke(LdapConnection connection, String providerRoot) throws Exception {
+        List<Entry> entries = ListChildrenOperation.listChildEntries(connection, LdapService.translatePathToDn(path, providerRoot));
+        for (Entry entry : entries) {
+            connection.delete(entry.getDn());
+        }
+        connection.delete(LdapService.translatePathToDn(path, providerRoot));
+        return null;
+    }
+
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListChildrenOperation.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListChildrenOperation.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListChildrenOperation.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListChildrenOperation.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl.operations;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.samples.ldap.resource.api.LdapOperation;
+import org.apache.sling.samples.ldap.resource.impl.LdapService;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ListChildrenOperation implements LdapOperation<List<Entry>> {
+    private String path;
+    private List<Resource> result = new ArrayList<Resource>();
+
+    public ListChildrenOperation(String path) {
+        this.path = path;
+    }
+
+    public List<Entry> invoke(LdapConnection connection, String providerRoot) throws Exception {
+        return listChildEntries(connection, LdapService.translatePathToDn(path, providerRoot));
+    }
+
+    public static List<Entry> listChildEntries(LdapConnection connection, final String parentDn) throws Exception {
+        EntryCursor cursor = connection.search(parentDn, "(objectclass=*)", SearchScope.ONELEVEL);
+        List<Entry> entries = new ArrayList<Entry>();
+        while (cursor.next()) {
+            Entry entry = cursor.get();
+            entries.add(entry);
+        }
+        cursor.close();
+        return entries;
+    }
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/LookupEntryOperation.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/LookupEntryOperation.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/LookupEntryOperation.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/LookupEntryOperation.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl.operations;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.sling.samples.ldap.resource.api.LdapOperation;
+import org.apache.sling.samples.ldap.resource.impl.LdapService;
+
+public class LookupEntryOperation implements LdapOperation<Entry> {
+
+    private String path;
+
+
+    public LookupEntryOperation(String path) {
+        super();
+        this.path = path;
+
+    }
+
+    public Entry invoke(final LdapConnection connection, String providerRoot) throws Exception {
+        // See http://directory.apache.org/api/searching-.html
+        try {
+            return connection.lookup(LdapService.translatePathToDn(path, providerRoot));
+        } catch (LdapException e) {
+            throw new LdapException("Error looking up " + path, e);
+        }
+    }
+}

Added: sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java (added)
+++ sling/whiteboard/vramdal/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl.operations;
+
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
+import org.apache.sling.samples.ldap.resource.api.LdapOperation;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ResolveReferencesOperation implements LdapOperation<List<String>> {
+    private final String searchBaseDn;
+    private final String attributeName;
+    private final String entryDn;
+
+    public ResolveReferencesOperation(String searchBaseDn, String attributeName, String entryDn) {
+        this.searchBaseDn = searchBaseDn;
+        this.attributeName = attributeName;
+        this.entryDn = entryDn;
+    }
+
+    @Override
+    public List<String> invoke(LdapConnection connection, String providerRoot) throws Exception {
+        EntryCursor search = connection.search(searchBaseDn, "(" + attributeName + "=" + entryDn + ")", SearchScope.SUBTREE, "dn");
+        Iterator<Entry> iterator = search.iterator();
+        List<String> result = new ArrayList<String>();
+        while (iterator.hasNext()) {
+            Entry entry = iterator.next();
+            result.add(entry.getDn().toString());
+        }
+        return result;
+    }
+}

Added: sling/whiteboard/vramdal/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ sling/whiteboard/vramdal/src/main/resources/OSGI-INF/metatype/metatype.properties Wed Aug 10 14:52:04 2011
@@ -0,0 +1,41 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+org.apache.sling.samples.ldap.resource.impl.LdapResourceProviderImpl.description = Resource provider for LDAP directories
+org.apache.sling.samples.ldap.resource.impl.LdapResourceProviderImpl.name = Apache Sling LDAP Resource Provider
+
+provider.roots.name = Provider root
+provider.roots.description = Location in the virtual resource tree where the LDAP resources are mapped in. This property must not be an empty string.
+
+hostname.name = Host name / IP address
+hostname.description = Name of the LDAP server host
+
+port.name = IP port
+port.description = The port where the LDAP server is running
+
+bindDn.name = Bind DN
+bindDn.description = DN (user name) to connect to the LDAP server
+
+bindPassword.name = Bind password
+bindPassword.description = Password to connect to the LDAP server
+
+baseDn.name = Base DN
+baseDn.description = Base DN to use when connecting to the LDAP server
+
+

Added: sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/CommonTestUtil.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/CommonTestUtil.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/CommonTestUtil.java (added)
+++ sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/CommonTestUtil.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap;
+
+import java.lang.reflect.Field;
+
+public class CommonTestUtil {
+
+    public static void setField(Object obj, String fieldName, Object value) {
+        setField(obj, fieldName, value, obj.getClass());
+    }
+
+    public static void setField(Object obj, String fieldName, Object value, final Class objClass) {
+        try {
+            final Field field = objClass.getDeclaredField(fieldName);
+            field.setAccessible(true);
+            field.set(obj, value);
+        } catch (Throwable e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

Added: sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/api/AdapterTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/api/AdapterTest.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/api/AdapterTest.java (added)
+++ sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/api/AdapterTest.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.api;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+public class AdapterTest extends TestCase {
+
+    protected StringIntegerAdapter stringIntegerAdapter;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        stringIntegerAdapter = new StringIntegerAdapter();
+    }
+
+    public void testAdapter() {
+        assertEquals((Integer) 1, stringIntegerAdapter.adapt("1"));
+        assertEquals((Integer) 10, stringIntegerAdapter.adapt("10"));
+        assertEquals((Integer) 33, stringIntegerAdapter.adapt("33"));
+        assertFalse(1 == stringIntegerAdapter.adapt("33"));
+    }
+
+    public void testAdapterIterator() {
+        List<String> input = Arrays.asList("1", "10", "33");
+        Iterator<Integer> expected = Arrays.asList(1, 10, 33).iterator();
+        Adapter.IteratorAdapter<String, Integer> iteratorAdapter = new Adapter.IteratorAdapter<String, Integer>(stringIntegerAdapter);
+        Iterator<Integer> iterator = iteratorAdapter.adapt(input.iterator());
+        while (iterator.hasNext()) {
+            assertEquals(expected.next(), iterator.next());
+        }
+    }
+
+    private static class StringIntegerAdapter implements Adapter<String, Integer> {
+        @Override
+        public Integer adapt(String s) {
+            return Integer.parseInt(s);
+        }
+    }
+}

Added: sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/AbstractLdapTest.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/AbstractLdapTest.java?rev=1156202&view=auto
==============================================================================
--- sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/AbstractLdapTest.java (added)
+++ sling/whiteboard/vramdal/src/test/java/org/apache/sling/samples/ldap/resource/impl/AbstractLdapTest.java Wed Aug 10 14:52:04 2011
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.samples.ldap.resource.impl;
+
+import junit.framework.TestCase;
+import org.apache.directory.ldap.client.api.LdapNetworkConnection;
+import org.apache.sling.commons.testing.sling.MockResourceResolver;
+import org.apache.sling.samples.ldap.CommonTestUtil;
+
+public abstract class AbstractLdapTest extends TestCase {
+    public static final String BASE_DN = "dc=somewhere,dc=com";
+    protected LdapResourceProviderImpl provider;
+    protected MockResourceResolver resourceResolver;
+    protected LdapService ldapService;
+    protected MockLdapNetworkConnection ldapNetworkConnection;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        provider = new LdapResourceProviderImpl() {
+            @Override
+            LdapService getLdapService() {
+                return new LdapService(this) {
+                    @Override
+                    LdapNetworkConnection connect() {
+                        ldapNetworkConnection = new MockLdapNetworkConnection();
+                        return ldapNetworkConnection;
+                    }
+                };
+            }
+        };
+        ldapService = provider.getLdapService();
+        CommonTestUtil.setField(provider, "bindDn", "uid=admin,ou=system", LdapResourceProviderImpl.class);
+        CommonTestUtil.setField(provider, "bindPassword", "passord", LdapResourceProviderImpl.class);
+        CommonTestUtil.setField(provider, "baseDn", BASE_DN, LdapResourceProviderImpl.class);
+        CommonTestUtil.setField(provider, "providerRoot", "/ldap", LdapResourceProviderImpl.class);
+        CommonTestUtil.setField(provider, "hostname", "localhost", LdapResourceProviderImpl.class);
+        CommonTestUtil.setField(provider, "port", 10389, LdapResourceProviderImpl.class);
+        resourceResolver = new MockResourceResolver();
+    }
+
+}



Mime
View raw message