You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by vr...@apache.org on 2011/08/12 14:19:32 UTC
svn commit: r1157069 - in /sling/whiteboard/vramdal/ldapresource: ./
src/main/java/org/apache/sling/samples/ldap/resource/api/
src/main/java/org/apache/sling/samples/ldap/resource/impl/
src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/
Author: vramdal
Date: Fri Aug 12 12:19:32 2011
New Revision: 1157069
URL: http://svn.apache.org/viewvc?rev=1157069&view=rev
Log:
LdapResource: Cleanup
Added:
sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListLdapOperation.java
Modified:
sling/whiteboard/vramdal/ldapresource/pom.xml
sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java
sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java
sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java
sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java
Modified: sling/whiteboard/vramdal/ldapresource/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/ldapresource/pom.xml?rev=1157069&r1=1157068&r2=1157069&view=diff
==============================================================================
--- sling/whiteboard/vramdal/ldapresource/pom.xml (original)
+++ sling/whiteboard/vramdal/ldapresource/pom.xml Fri Aug 12 12:19:32 2011
@@ -107,16 +107,6 @@
<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.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
Modified: sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java?rev=1157069&r1=1157068&r2=1157069&view=diff
==============================================================================
--- sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java (original)
+++ sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/api/LdapResourceProvider.java Fri Aug 12 12:19:32 2011
@@ -29,12 +29,6 @@ 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);
Modified: sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java?rev=1157069&r1=1157068&r2=1157069&view=diff
==============================================================================
--- sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java (original)
+++ sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapResourceProviderImpl.java Fri Aug 12 12:19:32 2011
@@ -19,10 +19,7 @@
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;
@@ -40,6 +37,7 @@ import org.apache.sling.samples.ldap.res
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.ListLdapOperation;
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;
@@ -82,6 +80,8 @@ public class LdapResourceProviderImpl im
@Property(name = "port", intValue = 10389)
private Integer port;
+ /* -- ResourceProvider implementation -- */
+
public Resource getResource(ResourceResolver resourceResolver, HttpServletRequest request, String path) {
return getResource(resourceResolver, path);
}
@@ -105,10 +105,6 @@ public class LdapResourceProviderImpl im
}
}
- LdapService getLdapService() {
- return new LdapService(this);
- }
-
public Iterator<Resource> listChildren(final Resource parent) {
LdapService connection = getLdapService();
ResourceResolver resourceResolver = parent.getResourceResolver();
@@ -132,6 +128,8 @@ public class LdapResourceProviderImpl im
}
}
+ /* -- LdapResourceProvider implementation -- */
+
@Override
public void delete(Resource resource) {
LdapService connection = getLdapService();
@@ -155,11 +153,11 @@ public class LdapResourceProviderImpl im
}
/**
- *
- * @param searchBaseDn
- * @param entryDn
- * @param attributeName
- * @param resourceResolver
+ * Searches for entries that reference another entry. Useful for finding members of a group, e.g.
+ * @param searchBaseDn The base DN to search under
+ * @param entryDn The entry DN to search for
+ * @param attributeName The attribute that should contain <code>entryDn</code> as a value
+ * @param resourceResolver The <code>ResourceResolver</code>
* @return An <code>Iterator</code> over paths that refer to entryDn
*/
@Override
@@ -181,25 +179,29 @@ public class LdapResourceProviderImpl im
return connection.invoke(op);
}
- public String getRoot() {
- return providerRoot;
- }
+ /* -- SCR integration -- */
- private static class ListLdapOperation implements LdapOperation<Iterator<Entry>> {
+ @Activate
+ protected void activate(ComponentContext context) {
+ 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");
+ }
+ }
- private String entryDn;
- private String attributeName;
+ /* -- Utility methods -- */
- private ListLdapOperation(String entryDn, String attributeName) {
- this.entryDn = entryDn;
- this.attributeName = attributeName;
- }
+ public String getRoot() {
+ return providerRoot;
+ }
- @Override
- public Iterator<Entry> invoke(LdapConnection connection, String providerRoot) throws Exception {
- EntryCursor cursor = connection.search(entryDn, "(objectclass=*)", SearchScope.OBJECT, attributeName);
- return cursor.iterator();
- }
+ LdapService getLdapService() {
+ return new LdapService(this);
}
String getBindDn() {
@@ -225,19 +227,4 @@ public class LdapResourceProviderImpl im
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");
- }
- }
-
}
Modified: sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java?rev=1157069&r1=1157068&r2=1157069&view=diff
==============================================================================
--- sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java (original)
+++ sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/LdapService.java Fri Aug 12 12:19:32 2011
@@ -72,11 +72,14 @@ public class LdapService {
public <T> T invoke(final LdapOperation<T> operation) {
LdapConnection connection = connect();
+ log.debug("Connected");
try {
+ log.debug("Binding as " + bindDn);
connection.bind(bindDn, bindPassword);
if (!connection.isAuthenticated()) {
throw new IllegalStateException("Unable to authenticate, using DN " + bindDn);
}
+ log.debug("Invoking " + operation.getClass().getSimpleName());
return operation.invoke(connection, this.providerRoot);
} catch (LdapException e) {
throw new IllegalStateException("LdapException (using DN " + bindDn + ")", e);
@@ -86,11 +89,13 @@ public class LdapService {
throw new IllegalStateException("Exception (using DN " + bindDn + ")", e);
} finally {
try {
+ log.debug("Unbinding");
connection.unBind();
} catch (LdapException e) {
log.warn("Exception unbinding connection", e);
}
try {
+ log.debug("Closing connection");
connection.close();
} catch (IOException e) {
log.warn("IOException while closing connection", e);
@@ -99,6 +104,7 @@ public class LdapService {
}
LdapNetworkConnection connect() {
+ log.debug("Connecting to " + this.provider.getHostname() + ":" + this.provider.getPort());
return new LdapNetworkConnection(this.provider.getHostname(), this.provider.getPort());
}
}
Added: sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListLdapOperation.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListLdapOperation.java?rev=1157069&view=auto
==============================================================================
--- sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListLdapOperation.java (added)
+++ sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ListLdapOperation.java Fri Aug 12 12:19:32 2011
@@ -0,0 +1,26 @@
+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.Iterator;
+
+public class ListLdapOperation implements LdapOperation<Iterator<Entry>> {
+
+ private String entryDn;
+ private String attributeName;
+
+ public 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();
+ }
+}
Modified: sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java?rev=1157069&r1=1157068&r2=1157069&view=diff
==============================================================================
--- sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java (original)
+++ sling/whiteboard/vramdal/ldapresource/src/main/java/org/apache/sling/samples/ldap/resource/impl/operations/ResolveReferencesOperation.java Fri Aug 12 12:19:32 2011
@@ -29,6 +29,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+/**
+ * @see org.apache.sling.samples.ldap.resource.impl.LdapResourceProviderImpl#getReferencingResources(String, String, String, org.apache.sling.api.resource.ResourceResolver)
+ */
public class ResolveReferencesOperation implements LdapOperation<List<String>> {
private final String searchBaseDn;
private final String attributeName;