You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2012/05/24 08:42:54 UTC
svn commit: r1342154 [1/5] - in
/sling/whiteboard/SLING-2396/resourceresolver: ./
src/main/java/org/apache/sling/jcr/resource/
src/main/java/org/apache/sling/jcr/resource/internal/
src/main/java/org/apache/sling/jcr/resource/internal/helper/ src/main/j...
Author: cziegeler
Date: Thu May 24 06:42:52 2012
New Revision: 1342154
URL: http://svn.apache.org/viewvc?rev=1342154&view=rev
Log:
SLING-2396 : New resource resolver factory based on resource provider factories (WiP)
Added:
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceIteratorDecorator.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceIteratorDecorator.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/console/ResourceResolverWebConsolePlugin.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/console/JcrResourceResolverWebConsolePlugin.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/AbstractWrappedResourceProvider.java (with props)
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/MapEntries.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/MapEntry.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/Mapping.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/Mapping.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RedirectResource.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/RedirectResource.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceIterator.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceIterator.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourcePathIterator.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceProviderEntry.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/ResourceResolverContext.java (with props)
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/RootResourceProviderEntry.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/RootResourceProviderEntry.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/SortedProviderList.java (with props)
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/StarResource.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/StarResource.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/URI.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/URI.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/URIException.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/URIException.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProvider.java (contents, props changed)
- copied, changed from r1339051, sling/whiteboard/SLING-2396/jcr.resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/helper/WrappedResourceProviderFactory.java (with props)
Removed:
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/JcrModifiablePropertyMap.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/JcrPropertyMap.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/JcrResourceConstants.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/JcrResourceResolverFactory.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/JcrResourceUtil.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/JcrItemAdapterFactory.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceIteratorDecorator.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/WorkspaceAuthInfoPostProcessor.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/WorkspaceDecoratedResource.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/JcrPropertyMapCacheEntry.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/LazyInputStream.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntries.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/MapEntry.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/Mapping.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/RedirectResource.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceIterator.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourceProviderEntry.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/RootResourceProviderEntry.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/URI.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/URIException.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/WrappedResourceProvider.java
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/helper/starresource/
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/scripting/
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/console/JcrResourceResolverWebConsolePlugin.java
Modified:
sling/whiteboard/SLING-2396/resourceresolver/pom.xml
sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/jcr/resource/internal/JcrResourceResolverTest.java
sling/whiteboard/SLING-2396/resourceresolver/src/test/java/org/apache/sling/jcr/resource/internal/helper/RedirectResourceTest.java
Modified: sling/whiteboard/SLING-2396/resourceresolver/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/pom.xml?rev=1342154&r1=1342153&r2=1342154&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/pom.xml (original)
+++ sling/whiteboard/SLING-2396/resourceresolver/pom.xml Thu May 24 06:42:52 2012
@@ -146,7 +146,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.1.0</version>
+ <version>2.2.5-WHITEBOARD-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -174,7 +174,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.0.6</version>
+ <version>2.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Copied: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java (from r1339051, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java?p2=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java&p1=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java&r1=1339051&r2=1342154&rev=1342154&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceDecoratorTracker.java (original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java Thu May 24 06:42:52 2012
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.jcr.resource.internal;
+package org.apache.sling.resourceresolver.impl;
import java.util.ArrayList;
import java.util.Collections;
@@ -24,15 +24,13 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import javax.servlet.http.HttpServletRequest;
-
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceDecorator;
-import org.apache.sling.commons.osgi.OsgiUtil;
+import org.apache.sling.commons.osgi.ServiceUtil;
/**
- * Helper class to track the resource decorators and keep
- * them sorted by their service ranking.
+ * Helper class to track the resource decorators and keep them sorted by their
+ * service ranking.
*/
public class ResourceDecoratorTracker {
@@ -55,20 +53,18 @@ public class ResourceDecoratorTracker {
}
}
- /** Decorate a resource. */
- public Resource decorate(final Resource resource, String workspaceName) {
+ /** Decorate a resource. */
+ public Resource decorate(final Resource resource) {
Resource result = resource;
final ResourceDecorator[] decorators = this.resourceDecoratorsArray;
- for(final ResourceDecorator decorator : decorators) {
+ for (final ResourceDecorator decorator : decorators) {
final Resource original = result;
result = decorator.decorate(original);
- if ( result == null ) {
+ if (result == null) {
result = original;
}
}
- if (workspaceName != null) {
- result = new WorkspaceDecoratedResource(result, workspaceName);
- }
+
return result;
}
@@ -76,17 +72,21 @@ public class ResourceDecoratorTracker {
return this.resourceDecoratorsArray;
}
- protected void bindResourceDecorator(final ResourceDecorator decorator, final Map<String, Object> props) {
+ protected void bindResourceDecorator(final ResourceDecorator decorator,
+ final Map<String, Object> props) {
synchronized (this.resourceDecorators) {
- this.resourceDecorators.add(new ResourceDecoratorEntry(decorator, OsgiUtil.getComparableForServiceRanking(props)));
+ this.resourceDecorators.add(new ResourceDecoratorEntry(decorator,
+ ServiceUtil.getComparableForServiceRanking(props)));
Collections.sort(this.resourceDecorators);
updateResourceDecoratorsArray();
}
}
- protected void unbindResourceDecorator(final ResourceDecorator decorator, final Map<String, Object> props) {
+ protected void unbindResourceDecorator(final ResourceDecorator decorator,
+ final Map<String, Object> props) {
synchronized (this.resourceDecorators) {
- final Iterator<ResourceDecoratorEntry> i = this.resourceDecorators.iterator();
+ final Iterator<ResourceDecoratorEntry> i = this.resourceDecorators
+ .iterator();
while (i.hasNext()) {
final ResourceDecoratorEntry current = i.next();
if (current.decorator == decorator) {
@@ -99,15 +99,16 @@ public class ResourceDecoratorTracker {
}
/**
- * Updates the ResourceDecorators array, this method is not thread safe and should only be
- * called from a synchronized block.
+ * Updates the ResourceDecorators array, this method is not thread safe and
+ * should only be called from a synchronized block.
*/
protected void updateResourceDecoratorsArray() {
final ResourceDecorator[] decorators;
if (this.resourceDecorators.size() > 0) {
decorators = new ResourceDecorator[this.resourceDecorators.size()];
int index = 0;
- final Iterator<ResourceDecoratorEntry> i = this.resourceDecorators.iterator();
+ final Iterator<ResourceDecoratorEntry> i = this.resourceDecorators
+ .iterator();
while (i.hasNext()) {
decorators[index] = i.next().decorator;
index++;
@@ -121,7 +122,8 @@ public class ResourceDecoratorTracker {
/**
* Internal class to keep track of the resource decorators.
*/
- private static final class ResourceDecoratorEntry implements Comparable<ResourceDecoratorEntry> {
+ private static final class ResourceDecoratorEntry implements
+ Comparable<ResourceDecoratorEntry> {
final Comparable<Object> comparable;
Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceDecoratorTracker.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceIteratorDecorator.java (from r1339051, sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceIteratorDecorator.java)
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceIteratorDecorator.java?p2=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceIteratorDecorator.java&p1=sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceIteratorDecorator.java&r1=1339051&r2=1342154&rev=1342154&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/jcr/resource/internal/ResourceIteratorDecorator.java (original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceIteratorDecorator.java Thu May 24 06:42:52 2012
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.sling.jcr.resource.internal;
+package org.apache.sling.resourceresolver.impl;
import java.util.Iterator;
@@ -29,16 +29,12 @@ public class ResourceIteratorDecorator i
private final ResourceDecoratorTracker tracker;
- private final String workspaceName;
-
private final Iterator<Resource> iterator;
public ResourceIteratorDecorator(final ResourceDecoratorTracker tracker,
- final String workspaceName,
final Iterator<Resource> iterator) {
this.tracker = tracker;
this.iterator = iterator;
- this.workspaceName = workspaceName;
}
public boolean hasNext() {
@@ -46,7 +42,7 @@ public class ResourceIteratorDecorator i
}
public Resource next() {
- return this.tracker.decorate(this.iterator.next(), workspaceName);
+ return this.tracker.decorate(this.iterator.next());
}
public void remove() {
Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceIteratorDecorator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceIteratorDecorator.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceIteratorDecorator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java?rev=1342154&r1=1342153&r2=1342154&view=diff
==============================================================================
--- sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java (original)
+++ sling/whiteboard/SLING-2396/resourceresolver/src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverFactoryImpl.java Thu May 24 06:42:52 2012
@@ -20,19 +20,10 @@ package org.apache.sling.resourceresolve
import java.util.ArrayList;
import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.regex.Pattern;
-import javax.jcr.Credentials;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.TreeBidiMap;
import org.apache.felix.scr.annotations.Component;
@@ -47,57 +38,44 @@ import org.apache.felix.scr.annotations.
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.ResourceDecorator;
import org.apache.sling.api.resource.ResourceProvider;
+import org.apache.sling.api.resource.ResourceProviderFactory;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
-import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
-import org.apache.sling.commons.osgi.OsgiUtil;
-import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.resource.JcrResourceConstants;
-import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
-import org.apache.sling.jcr.resource.internal.JcrItemAdapterFactory;
-import org.apache.sling.jcr.resource.internal.JcrResourceListener;
-import org.apache.sling.jcr.resource.internal.JcrResourceResolver;
-import org.apache.sling.jcr.resource.internal.ResourceDecoratorTracker;
-import org.apache.sling.jcr.resource.internal.helper.MapEntries;
-import org.apache.sling.jcr.resource.internal.helper.Mapping;
-import org.apache.sling.jcr.resource.internal.helper.ResourceProviderEntry;
-import org.apache.sling.jcr.resource.internal.helper.RootResourceProviderEntry;
-import org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderEntry;
-import org.apache.sling.resourceresolver.impl.console.JcrResourceResolverWebConsolePlugin;
+import org.apache.sling.commons.osgi.PropertiesUtil;
+import org.apache.sling.resourceresolver.impl.console.ResourceResolverWebConsolePlugin;
+import org.apache.sling.resourceresolver.impl.helper.MapEntries;
+import org.apache.sling.resourceresolver.impl.helper.Mapping;
+import org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext;
+import org.apache.sling.resourceresolver.impl.helper.RootResourceProviderEntry;
import org.osgi.framework.Constants;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.event.EventAdmin;
-import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * The <code>JcrResourceResolverFactoryImpl</code> is the
- * {@link JcrResourceResolverFactory} service providing the following
+ * The <code>ResourceResolverFactoryImpl</code> is the {@link ResourceResolverFactory} service
+ * providing the following
* functionality:
* <ul>
* <li><code>JcrResourceResolverFactory</code> service
- * <li>Bundle listener to load initial content and manage OCM mapping
- * descriptors provided by bundles.
+ * <li>Bundle listener to load initial content and manage OCM mapping descriptors provided by
+ * bundles.
* <li>Fires OSGi EventAdmin events on behalf of internal helper objects
* </ul>
- *
- * First attempt of an resource resolver factory implementation.
- * WORK IN PROGRESS - see SLING-1262
+ *
*/
-@Component(immediate=true, label="%resource.resolver.name", description="%resource.resolver.description", specVersion="1.1", metatype=true)
-@Service(value={JcrResourceResolverFactory.class, ResourceResolverFactory.class})
-@Properties({
- @Property(name = Constants.SERVICE_DESCRIPTION, value="Sling JcrResourceResolverFactory Implementation"),
- @Property(name = Constants.SERVICE_VENDOR, value="The Apache Software Foundation")
-
+@Component(immediate = true, label = "%resource.resolver.name", description = "%resource.resolver.description", specVersion = "1.1", metatype = true)
+@Service(value = ResourceResolverFactory.class)
+@Properties({ @Property(name = Constants.SERVICE_DESCRIPTION, value = "Sling JcrResourceResolverFactory Implementation"),
+ @Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation")
+
})
@References({
- @Reference(name="ResourceProvider", referenceInterface=ResourceProvider.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC),
- @Reference(name="ResourceDecorator", referenceInterface=ResourceDecorator.class, cardinality=ReferenceCardinality.OPTIONAL_MULTIPLE, policy=ReferencePolicy.DYNAMIC)
-})
-public class ResourceResolverFactoryImpl implements
- JcrResourceResolverFactory, ResourceResolverFactory {
+ @Reference(name = "ResourceProvider", referenceInterface = ResourceProvider.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
+ @Reference(name = "ResourceProviderFactory", referenceInterface = ResourceProviderFactory.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC),
+ @Reference(name = "ResourceDecorator", referenceInterface = ResourceDecorator.class, cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE, policy = ReferencePolicy.DYNAMIC) })
+public class ResourceResolverFactoryImpl implements ResourceResolverFactory {
public final static class ResourcePattern {
public final Pattern pattern;
@@ -110,15 +88,7 @@ public class ResourceResolverFactoryImpl
}
}
- private static final boolean DEFAULT_MULTIWORKSPACE = false;
-
- /**
- * Special value which, if passed to listener.workspaces, will have resource
- * events fired for all workspaces.
- */
- public static final String ALL_WORKSPACES = "*";
-
- @Property(value={"/apps", "/libs" })
+ @Property(value = { "/apps", "/libs" })
public static final String PROP_PATH = "resource.resolver.searchpath";
/**
@@ -126,27 +96,22 @@ public class ResourceResolverFactoryImpl
* (e.g. <code>jcr:</code> in <code>/home/path/jcr:content</code>) are
* mangled or not.
* <p>
- * Mangling means that any namespace prefix contained in the path is replaced
- * as per the generic substitution pattern <code>/([^:]+):/_$1_/</code>
- * when calling the <code>map</code> method of the resource resolver.
- * Likewise the <code>resolve</code> methods will unmangle such namespace
- * prefixes according to the substituation pattern
- * <code>/_([^_]+)_/$1:/</code>.
+ * Mangling means that any namespace prefix contained in the path is replaced as per the generic
+ * substitution pattern <code>/([^:]+):/_$1_/</code> when calling the <code>map</code> method of
+ * the resource resolver. Likewise the <code>resolve</code> methods will unmangle such namespace
+ * prefixes according to the substituation pattern <code>/_([^_]+)_/$1:/</code>.
* <p>
- * This feature is provided since there may be systems out there in the wild
- * which cannot cope with URLs containing colons, even though they are
- * perfectly valid characters in the path part of URI references with a
- * scheme.
+ * This feature is provided since there may be systems out there in the wild which cannot cope
+ * with URLs containing colons, even though they are perfectly valid characters in the path part
+ * of URI references with a scheme.
* <p>
- * The default value of this property if no configuration is provided is
- * <code>true</code>.
- *
+ * The default value of this property if no configuration is provided is <code>true</code>.
+ *
*/
- @Property(boolValue=true)
+ @Property(boolValue = true)
private static final String PROP_MANGLE_NAMESPACES = "resource.resolver.manglenamespaces";
-
- @Property(boolValue=true)
+ @Property(boolValue = true)
private static final String PROP_ALLOW_DIRECT = "resource.resolver.allowDirect";
/**
@@ -155,28 +120,22 @@ public class ResourceResolverFactoryImpl
* multivalue properties at the moment. So we just add a dummy direct
* mapping.
*/
- @Property(value="/:/", unbounded=PropertyUnbounded.ARRAY)
+ @Property(value = "/:/", unbounded = PropertyUnbounded.ARRAY)
private static final String PROP_VIRTUAL = "resource.resolver.virtual";
- @Property(value={"/:/", "/content/:/", "/system/docroot/:/"})
+ @Property(value = { "/:/", "/content/:/", "/system/docroot/:/" })
private static final String PROP_MAPPING = "resource.resolver.mapping";
- @Property(value=MapEntries.DEFAULT_MAP_ROOT)
+ @Property(value = MapEntries.DEFAULT_MAP_ROOT)
private static final String PROP_MAP_LOCATION = "resource.resolver.map.location";
- @Property(boolValue=DEFAULT_MULTIWORKSPACE)
- private static final String PROP_MULTIWORKSPACE = "resource.resolver.multiworkspace";
-
- /** default log */
- private final Logger log = LoggerFactory.getLogger(getClass());
-
- @Reference
- private SlingRepository repository;
+ /** Default logger */
+ private final Logger logger = LoggerFactory.getLogger(getClass());
/** Tracker for the resource decorators. */
private final ResourceDecoratorTracker resourceDecoratorTracker = new ResourceDecoratorTracker();
- // helper for the new JcrResourceResolver
+ // helper for the new ResourceResolver
private MapEntries mapEntries = MapEntries.EMPTY;
/** all mappings */
@@ -199,20 +158,8 @@ public class ResourceResolverFactoryImpl
// whether to mangle paths with namespaces or not
private boolean mangleNamespacePrefixes;
- private boolean useMultiWorkspaces;
-
- /** The resource listeners for the observation events. */
- private Set<JcrResourceListener> resourceListeners;
-
- /** The service tracker for the event admin
- */
- private ServiceTracker eventAdminTracker;
-
- /** The dynamic class loader */
- @Reference(cardinality=ReferenceCardinality.OPTIONAL_UNARY, policy=ReferencePolicy.DYNAMIC)
- private DynamicClassLoaderManager dynamicClassLoaderManager;
-
- private JcrItemAdapterFactory jcrItemAdapterFactory;
+ /** Event admin. */
+ private EventAdmin eventAdmin;
public ResourceResolverFactoryImpl() {
this.rootProviderEntry = new RootResourceProviderEntry();
@@ -223,41 +170,19 @@ public class ResourceResolverFactoryImpl
return this.resourceDecoratorTracker;
}
- // ---------- JcrResourceResolverFactory -----------------------------------
-
- /**
- * Returns a new <code>ResourceResolve</code> for the given session. Note
- * that each call to this method returns a new resource manager instance.
- *
- * @see org.apache.sling.jcr.resource.JcrResourceResolverFactory#getResourceResolver(javax.jcr.Session)
- */
- public ResourceResolver getResourceResolver(Session session) {
- Map<String, Object> authInfo = new HashMap<String, Object>(1);
- authInfo.put(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session);
- try {
- return getResourceResolver(authInfo);
- } catch (LoginException le) {
- // we don't expect a LoginException here because just a
- // ResourceResolver wrapping the given session is to be created.
- throw new InternalError("Unexpected LoginException");
- }
- }
-
// ---------- Resource Resolver Factory ------------------------------------
/**
* @see org.apache.sling.api.resource.ResourceResolverFactory#getAdministrativeResourceResolver(java.util.Map)
*/
- public ResourceResolver getAdministrativeResourceResolver(
- final Map<String, Object> authenticationInfo) throws LoginException {
+ public ResourceResolver getAdministrativeResourceResolver(final Map<String, Object> authenticationInfo) throws LoginException {
return getResourceResolverInternal(authenticationInfo, true);
}
/**
* @see org.apache.sling.api.resource.ResourceResolverFactory#getResourceResolver(java.util.Map)
*/
- public ResourceResolver getResourceResolver(
- final Map<String, Object> authenticationInfo) throws LoginException {
+ public ResourceResolver getResourceResolver(final Map<String, Object> authenticationInfo) throws LoginException {
return getResourceResolverInternal(authenticationInfo, false);
}
@@ -265,92 +190,19 @@ public class ResourceResolverFactoryImpl
* Create a new ResourceResolver wrapping a Session object. Carries map of
* authentication info in order to create a new resolver as needed.
*/
- private ResourceResolver getResourceResolverInternal(
- final Map<String, Object> authenticationInfo, final boolean isAdmin)
- throws LoginException {
-
- // by default any session used by the resource resolver returned is
- // closed when the resource resolver is closed
- boolean logoutSession = true;
-
- // derive the session to be used
- Session session;
- try {
- final String workspace = getWorkspace(authenticationInfo);
- if (isAdmin) {
- // requested admin session to any workspace (or default)
- session = getRepository().loginAdministrative(workspace);
-
- } else {
-
- session = getSession(authenticationInfo);
- if (session == null) {
- // requested non-admin session to any workspace (or default)
- final Credentials credentials = getCredentials(authenticationInfo);
- session = getRepository().login(credentials, workspace);
-
- } else if (workspace != null) {
- // session provided by map; but requested a different
- // workspace impersonate can only change the user not switch
- // the workspace as a workaround we login to the requested
- // workspace with admin and then switch to the provided
- // session's user (if required)
- Session tmpSession = null;
- try {
- tmpSession = getRepository().loginAdministrative(
- workspace);
- if (tmpSession.getUserID().equals(session.getUserID())) {
- session = tmpSession;
- tmpSession = null;
- } else {
- session = tmpSession.impersonate(new SimpleCredentials(
- session.getUserID(), new char[0]));
- }
- } finally {
- if (tmpSession != null) {
- tmpSession.logout();
- }
- }
-
- } else {
- // session provided; no special workspace; just make sure
- // the session is not logged out when the resolver is closed
- logoutSession = false;
- }
- }
- } catch (RepositoryException re) {
- throw getLoginException(re);
- }
+ private ResourceResolver getResourceResolverInternal(final Map<String, Object> authenticationInfo, final boolean isAdmin)
+ throws LoginException {
+ // create context
+ final ResourceResolverContext ctx = new ResourceResolverContext(isAdmin, authenticationInfo);
- session = handleImpersonation(session, authenticationInfo, logoutSession);
+ // login
+ this.rootProviderEntry.loginToRequiredFactories(ctx);
- final JcrResourceProviderEntry sessionRoot = new JcrResourceProviderEntry(
- session, rootProviderEntry, this.getDynamicClassLoader(),
- useMultiWorkspaces);
-
- if (logoutSession) {
- return new JcrResourceResolver(sessionRoot, this, isAdmin,
- authenticationInfo, useMultiWorkspaces);
- }
-
- return new JcrResourceResolver(sessionRoot, this, isAdmin,
- authenticationInfo, useMultiWorkspaces) {
- protected void closeSession() {
- }
- };
+ return new ResourceResolverImpl(this, ctx);
}
// ---------- Implementation helpers --------------------------------------
- /** Get the dynamic class loader if available */
- ClassLoader getDynamicClassLoader() {
- final DynamicClassLoaderManager dclm = this.dynamicClassLoaderManager;
- if ( dclm != null ) {
- return dclm.getDynamicClassLoader();
- }
- return null;
- }
-
/**
* This method is called from {@link MapEntries}
*/
@@ -365,11 +217,11 @@ public class ResourceResolverFactoryImpl
return mappings;
}
- String[] getSearchPath() {
+ public String[] getSearchPath() {
return searchPath;
}
- boolean isMangleNamespacePrefixes() {
+ public boolean isMangleNamespacePrefixes() {
return mangleNamespacePrefixes;
}
@@ -378,22 +230,18 @@ public class ResourceResolverFactoryImpl
return mapRoot;
}
- MapEntries getMapEntries() {
+ public MapEntries getMapEntries() {
return mapEntries;
}
- String getDefaultWorkspaceName() {
- return this.repository.getDefaultWorkspace();
- }
-
/**
* Getter for rootProviderEntry, making it easier to extend
* JcrResourceResolverFactoryImpl. See <a
* href="https://issues.apache.org/jira/browse/SLING-730">SLING-730</a>
- *
+ *
* @return Our rootProviderEntry
*/
- protected ResourceProviderEntry getRootProviderEntry() {
+ protected RootResourceProviderEntry getRootProviderEntry() {
return rootProviderEntry;
}
@@ -401,33 +249,29 @@ public class ResourceResolverFactoryImpl
/** Activates this component, called by SCR before registering as a service */
protected void activate(final ComponentContext componentContext) {
- // setup tracker first as this is used in the bind/unbind methods
- this.eventAdminTracker = new ServiceTracker(componentContext.getBundleContext(),
- EventAdmin.class.getName(), null);
- this.eventAdminTracker.open();
-
+ this.rootProviderEntry.setEventAdmin(this.eventAdmin);
final Dictionary<?, ?> properties = componentContext.getProperties();
- BidiMap virtuals = new TreeBidiMap();
- String[] virtualList = OsgiUtil.toStringArray(properties.get(PROP_VIRTUAL));
+ final BidiMap virtuals = new TreeBidiMap();
+ final String[] virtualList = PropertiesUtil.toStringArray(properties.get(PROP_VIRTUAL));
for (int i = 0; virtualList != null && i < virtualList.length; i++) {
- String[] parts = Mapping.split(virtualList[i]);
+ final String[] parts = Mapping.split(virtualList[i]);
virtuals.put(parts[0], parts[2]);
}
virtualURLMap = virtuals;
- List<Mapping> maps = new ArrayList<Mapping>();
- String[] mappingList = (String[]) properties.get(PROP_MAPPING);
+ final List<Mapping> maps = new ArrayList<Mapping>();
+ final String[] mappingList = (String[]) properties.get(PROP_MAPPING);
for (int i = 0; mappingList != null && i < mappingList.length; i++) {
maps.add(new Mapping(mappingList[i]));
}
- Mapping[] tmp = maps.toArray(new Mapping[maps.size()]);
+ final Mapping[] tmp = maps.toArray(new Mapping[maps.size()]);
// check whether direct mappings are allowed
- Boolean directProp = (Boolean) properties.get(PROP_ALLOW_DIRECT);
+ final Boolean directProp = (Boolean) properties.get(PROP_ALLOW_DIRECT);
allowDirect = (directProp != null) ? directProp.booleanValue() : true;
if (allowDirect) {
- Mapping[] tmp2 = new Mapping[tmp.length + 1];
+ final Mapping[] tmp2 = new Mapping[tmp.length + 1];
tmp2[0] = Mapping.DIRECT;
System.arraycopy(tmp, 0, tmp2, 1, tmp.length);
mappings = tmp2;
@@ -436,7 +280,7 @@ public class ResourceResolverFactoryImpl
}
// from configuration if available
- searchPath = OsgiUtil.toStringArray(properties.get(PROP_PATH));
+ searchPath = PropertiesUtil.toStringArray(properties.get(PROP_PATH));
if (searchPath != null && searchPath.length > 0) {
for (int i = 0; i < searchPath.length; i++) {
// ensure leading slash
@@ -454,67 +298,32 @@ public class ResourceResolverFactoryImpl
}
// namespace mangling
- mangleNamespacePrefixes = OsgiUtil.toBoolean(
- properties.get(PROP_MANGLE_NAMESPACES), false);
+ mangleNamespacePrefixes = PropertiesUtil.toBoolean(properties.get(PROP_MANGLE_NAMESPACES), false);
// the root of the resolver mappings
- mapRoot = OsgiUtil.toString(properties.get(PROP_MAP_LOCATION),
- MapEntries.DEFAULT_MAP_ROOT);
+ mapRoot = PropertiesUtil.toString(properties.get(PROP_MAP_LOCATION), MapEntries.DEFAULT_MAP_ROOT);
// set up the map entries from configuration
try {
- mapEntries = new MapEntries(this, componentContext.getBundleContext(), this.eventAdminTracker);
- } catch (Exception e) {
- log.error(
- "activate: Cannot access repository, failed setting up Mapping Support",
- e);
- }
-
-
- // start observation listener
- try {
- this.resourceListeners = new HashSet<JcrResourceListener>();
-
- // first - add a listener for the default workspace
- this.resourceListeners.add(new JcrResourceListener(null, this, "/", "/", this.eventAdminTracker));
-
- // check if multi workspace support is enabled
- this.useMultiWorkspaces = OsgiUtil.toBoolean(properties.get(PROP_MULTIWORKSPACE), DEFAULT_MULTIWORKSPACE);
- if (this.useMultiWorkspaces) {
- final String[] listenerWorkspaces = getAllWorkspaces();
- for (final String wspName : listenerWorkspaces) {
- if (!wspName.equals(this.repository.getDefaultWorkspace())) {
- this.resourceListeners.add(
- new JcrResourceListener(wspName, this, "/", "/", this.eventAdminTracker));
- }
- }
- }
- } catch (Exception e) {
- log.error(
- "activate: Cannot create resource listener; resource events for JCR resources will be disabled.",
- e);
+ mapEntries = new MapEntries(this, componentContext.getBundleContext(), this.eventAdmin);
+ } catch (final Exception e) {
+ logger.error("activate: Cannot access repository, failed setting up Mapping Support", e);
}
try {
- plugin = new JcrResourceResolverWebConsolePlugin(componentContext.getBundleContext(), this);
- } catch (Throwable ignore) {
- // an exception here propably means the web console plugin is not available
- log.debug(
- "activate: unable to setup web console plugin.", ignore);
+ plugin = new ResourceResolverWebConsolePlugin(componentContext.getBundleContext(), this);
+ } catch (final Throwable ignore) {
+ // an exception here propably means the web console plugin is not
+ // available
+ logger.debug("activate: unable to setup web console plugin.", ignore);
}
-
- jcrItemAdapterFactory = new JcrItemAdapterFactory(componentContext.getBundleContext(), this);
}
- private JcrResourceResolverWebConsolePlugin plugin;
+ private ResourceResolverWebConsolePlugin plugin;
/** Deativates this component, called by SCR to take out of service */
protected void deactivate(final ComponentContext componentContext) {
- if (jcrItemAdapterFactory != null) {
- jcrItemAdapterFactory.dispose();
- jcrItemAdapterFactory = null;
- }
-
+ this.rootProviderEntry.setEventAdmin(null);
if (plugin != null) {
plugin.dispose();
plugin = null;
@@ -524,240 +333,42 @@ public class ResourceResolverFactoryImpl
mapEntries.dispose();
mapEntries = MapEntries.EMPTY;
}
- if ( this.eventAdminTracker != null ) {
- this.eventAdminTracker.close();
- this.eventAdminTracker = null;
- }
- if ( this.resourceListeners != null && !this.resourceListeners.isEmpty() ) {
- for ( JcrResourceListener resourceListener : this.resourceListeners ) {
- resourceListener.dispose();
- }
- this.resourceListeners = null;
- }
this.resourceDecoratorTracker.close();
}
- protected void bindResourceProvider(final ResourceProvider provider, final Map<String, Object> props) {
- this.rootProviderEntry.bindResourceProvider(provider, props, this.eventAdminTracker);
- }
-
- protected void unbindResourceProvider(final ResourceProvider provider, final Map<String, Object> props) {
- this.rootProviderEntry.unbindResourceProvider(provider, props, this.eventAdminTracker);
- }
-
- protected void bindResourceDecorator(final ResourceDecorator decorator, final Map<String, Object> props) {
- this.resourceDecoratorTracker.bindResourceDecorator(decorator, props);
- }
-
- protected void unbindResourceDecorator(final ResourceDecorator decorator, final Map<String, Object> props) {
- this.resourceDecoratorTracker.unbindResourceDecorator(decorator, props);
- }
-
- // ---------- internal helper ----------------------------------------------
-
- /** Returns the JCR repository used by this factory */
- protected SlingRepository getRepository() {
- return repository;
- }
-
/**
- * Create a login exception from a repository exception.
- * If the repository exception is a {@link javax.jcr.LoginException}
- * a {@link LoginException} is created with the same information.
- * Otherwise a {@link LoginException} is created which wraps the
- * repository exception.
- * @param re The repository exception.
- * @return The login exception.
+ * Bind a resource provider.
*/
- private LoginException getLoginException(final RepositoryException re) {
- if ( re instanceof javax.jcr.LoginException ) {
- return new LoginException(re.getMessage(), re.getCause());
- }
- return new LoginException("Unable to login " + re.getMessage(), re);
+ protected void bindResourceProvider(final ResourceProvider provider, final Map<String, Object> props) {
+ this.rootProviderEntry.bindResourceProvider(provider, props);
}
/**
- * Get an array of all workspaces.
+ * Unbind a resource provider.
*/
- private String[] getAllWorkspaces() throws RepositoryException {
- Session session = null;
- try {
- session = repository.loginAdministrative(null);
- return session.getWorkspace().getAccessibleWorkspaceNames();
- } finally {
- if (session != null) {
- session.logout();
- }
- }
- }
-
- /**
- * Returns the session provided as the user.jcr.session property of the
- * <code>authenticationInfo</code> map or <code>null</code> if the
- * property is not contained in the map or is not a <code>javax.jcr.Session</code>.
- * @param authenticationInfo Optional authentication info.
- * @return The user.jcr.session property or <code>null</code>
- */
- private Session getSession(final Map<String, Object> authenticationInfo) {
- if (authenticationInfo != null) {
- final Object sessionObject = authenticationInfo.get(JcrResourceConstants.AUTHENTICATION_INFO_SESSION);
- if (sessionObject instanceof Session) {
- return (Session) sessionObject;
- }
- }
- return null;
+ protected void unbindResourceProvider(final ResourceProvider provider, final Map<String, Object> props) {
+ this.rootProviderEntry.unbindResourceProvider(provider, props);
}
/**
- * Return the workspace name.
- * If the workspace name is provided, it is returned, otherwise
- * <code>null</code> is returned.
- * @param authenticationInfo Optional authentication info.
- * @return The configured workspace name or <code>null</code>
+ * Bind a resource provider factory.
*/
- private String getWorkspace(final Map<String, Object> authenticationInfo) {
- if (authenticationInfo != null) {
- final Object workspaceObject = authenticationInfo.get(JcrResourceConstants.AUTHENTICATION_INFO_WORKSPACE);
- if (workspaceObject instanceof String) {
- return (String) workspaceObject;
- }
- }
- return null;
+ protected void bindResourceProviderFactory(final ResourceProviderFactory provider, final Map<String, Object> props) {
+ this.rootProviderEntry.bindResourceProviderFactory(provider, props);
}
/**
- * Return the sudo user information.
- * If the sudo user info is provided, it is returned, otherwise
- * <code>null</code> is returned.
- * @param authenticationInfo Optional authentication info.
- * @return The configured sudo user information or <code>null</code>
+ * Unbind a resource provider factory.
*/
- private String getSudoUser(final Map<String, Object> authenticationInfo) {
- if (authenticationInfo != null) {
- final Object sudoObject = authenticationInfo.get(ResourceResolverFactory.USER_IMPERSONATION);
- if (sudoObject instanceof String) {
- return (String) sudoObject;
- }
- }
- return null;
+ protected void unbindResourceProviderFactory(final ResourceProviderFactory provider, final Map<String, Object> props) {
+ this.rootProviderEntry.unbindResourceProviderFactory(provider, props);
}
- /**
- * Handle the sudo if configured. If the authentication info does not
- * contain a sudo info, this method simply returns the passed in session. If
- * a sudo user info is available, the session is tried to be impersonated.
- * The new impersonated session is returned. The original session is closed.
- * The session is also closed if the impersonation fails.
- *
- * @param session The session.
- * @param authenticationInfo The optional authentication info.
- * @param logoutSession whether to logout the <code>session</code> after
- * impersonation or not.
- * @return The original session or impersonated session.
- * @throws LoginException If something goes wrong.
- */
- private Session handleImpersonation(final Session session,
- final Map<String, Object> authenticationInfo, boolean logoutSession)
- throws LoginException {
- final String sudoUser = getSudoUser(authenticationInfo);
- if (sudoUser != null && !session.getUserID().equals(sudoUser)) {
- try {
- final SimpleCredentials creds = new SimpleCredentials(sudoUser,
- new char[0]);
- copyAttributes(creds, authenticationInfo);
- creds.setAttribute(ResourceResolver.USER_IMPERSONATOR,
- session.getUserID());
- return session.impersonate(creds);
- } catch (RepositoryException re) {
- throw getLoginException(re);
- } finally {
- if (logoutSession) {
- session.logout();
- }
- }
- }
- return session;
- }
-
- /**
- * Create a credentials object from the provided authentication info.
- * If no map is provided, <code>null</code> is returned.
- * If a map is provided and contains a credentials object, this object is
- * returned.
- * If a map is provided but does not contain a credentials object nor a
- * user, <code>null</code> is returned.
- * if a map is provided with a user name but without a credentials object
- * a new credentials object is created and all values from the authentication
- * info are added as attributes.
- * @param authenticationInfo Optional authentication info
- * @return A credentials object or <code>null</code>
- */
- private Credentials getCredentials(final Map<String, Object> authenticationInfo) {
- if (authenticationInfo == null) {
- return null;
- }
-
- final Object credentialsObject = authenticationInfo.get(JcrResourceConstants.AUTHENTICATION_INFO_CREDENTIALS);
- if (credentialsObject instanceof Credentials) {
- return (Credentials) credentialsObject;
- }
-
- // otherwise try to create SimpleCredentials if the userId is set
- final Object userId = authenticationInfo.get(USER);
- if (userId instanceof String) {
- final Object password = authenticationInfo.get(PASSWORD);
- final SimpleCredentials credentials = new SimpleCredentials(
- (String) userId, ((password instanceof char[])
- ? (char[]) password
- : new char[0]));
-
- // add attributes
- copyAttributes(credentials, authenticationInfo);
-
- return credentials;
- }
-
- // no user id (or not a String)
- return null;
- }
-
- /**
- * Copies the contents of the source map as attributes into the target
- * <code>SimpleCredentials</code> object with the exception of the
- * <code>user.jcr.credentials</code> and <code>user.password</code>
- * attributes to prevent leaking passwords into the JCR Session attributes
- * which might be used for break-in attempts.
- *
- * @param target The <code>SimpleCredentials</code> object whose attributes
- * are to be augmented.
- * @param source The map whose entries (except the ones listed above) are
- * copied as credentials attributes.
- */
- private void copyAttributes(final SimpleCredentials target,
- final Map<String, Object> source) {
- final Iterator<Map.Entry<String, Object>> i = source.entrySet().iterator();
- while (i.hasNext()) {
- final Map.Entry<String, Object> current = i.next();
- if (isAttributeVisible(current.getKey())) {
- target.setAttribute(current.getKey(), current.getValue());
- }
- }
+ protected void bindResourceDecorator(final ResourceDecorator decorator, final Map<String, Object> props) {
+ this.resourceDecoratorTracker.bindResourceDecorator(decorator, props);
}
- /**
- * Returns <code>true</code> unless the name is
- * <code>user.jcr.credentials</code> (
- * {@link JcrResourceConstants#AUTHENTICATION_INFO_CREDENTIALS}) or contains
- * the string <code>password</code> as in <code>user.password</code> (
- * {@link org.apache.sling.api.resource.ResourceResolverFactory#PASSWORD})
- *
- * @param name The name to check whether it is visible or not
- * @return <code>true</code> if the name is assumed visible
- * @throws NullPointerException if <code>name</code> is <code>null</code>
- */
- static boolean isAttributeVisible(final String name) {
- return !name.equals(JcrResourceConstants.AUTHENTICATION_INFO_CREDENTIALS)
- && !name.contains("password");
+ protected void unbindResourceDecorator(final ResourceDecorator decorator, final Map<String, Object> props) {
+ this.resourceDecoratorTracker.unbindResourceDecorator(decorator, props);
}
-
}
\ No newline at end of file