Search in sources :

Example 1 with ResolveContext

use of org.apache.sling.spi.resource.provider.ResolveContext in project sling by apache.

the class JcrResourceProviderTest method testAdaptTo_Principal.

public void testAdaptTo_Principal() {
    jcrResourceProvider = new JcrResourceProvider();
    ResolveContext ctx = Mockito.mock(ResolveContext.class);
    Mockito.when(ctx.getProviderState()).thenReturn(new JcrProviderState(session, null, false));
    Assert.assertNotNull(jcrResourceProvider.adaptTo(ctx, Principal.class));
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) Principal(java.security.Principal)

Example 2 with ResolveContext

use of org.apache.sling.spi.resource.provider.ResolveContext in project sling by apache.

the class LegacyResourceProviderAdapter method getResource.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext resourceContext, Resource parent) {
    Resource resourceCandidate;
    if (rp instanceof ParametrizableResourceProvider) {
        resourceCandidate = ((ParametrizableResourceProvider) rp).getResource(ctx.getResourceResolver(), path, resourceContext.getResolveParameters());
    } else {
        resourceCandidate = rp.getResource(ctx.getResourceResolver(), path);
    }
    ResourceProvider<?> parentProvider = ctx.getParentResourceProvider();
    ResolveContext parentCtx = ctx.getParentResolveContext();
    // Ask the parent provider
    if (resourceCandidate == null && !ownsRoot && parentProvider != null) {
        return parentProvider.getResource(parentCtx, path, resourceContext, parent);
    }
    // Support the INTERNAL_CONTINUE_RESOLVING flag
    Resource fallbackResource = resourceCandidate;
    if (resourceCandidate != null && parentProvider != null && isContinueResolving(resourceCandidate)) {
        resourceCandidate = ctx.getParentResourceProvider().getResource(parentCtx, path, resourceContext, parent);
    }
    if (resourceCandidate != null) {
        return resourceCandidate;
    } else {
        return fallbackResource;
    }
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) Resource(org.apache.sling.api.resource.Resource) ParametrizableResourceProvider(org.apache.sling.api.resource.ParametrizableResourceProvider)

Example 3 with ResolveContext

use of org.apache.sling.spi.resource.provider.ResolveContext in project sling by apache.

the class SecureResourceProviderDecoratorTest method prepare.

@Before
public void prepare() throws PersistenceException, AccessSecurityException {
    rr = mock(ResourceResolver.class);
    resolveContext = mock(ResolveContext.class);
    when(resolveContext.getResourceResolver()).thenReturn(rr);
    security = mock(ResourceAccessSecurity.class);
    first = mock(Resource.class);
    second = mock(Resource.class);
    when(security.getReadableResource(first)).thenReturn(first);
    when(security.getReadableResource(second)).thenReturn(null);
    when(security.transformQuery("FIND ALL", "MockQueryLanguage", rr)).thenReturn("FIND ALL");
    QueryLanguageProvider qlp = mock(QueryLanguageProvider.class);
    rp = mock(ResourceProvider.class);
    when(rp.getQueryLanguageProvider()).thenReturn(qlp);
    when(rp.create(resolveContext, "/some/path", Collections.<String, Object>emptyMap())).thenReturn(mock(Resource.class));
    when(qlp.findResources(resolveContext, "FIND ALL", "MockQueryLanguage")).thenReturn(Arrays.asList(first, second).iterator());
    ResourceAccessSecurityTracker securityTracker = new ResourceAccessSecurityTracker() {

        @Override
        public ResourceAccessSecurity getApplicationResourceAccessSecurity() {
            return security;
        }
    };
    final ResourceProviderHandler handler = mock(ResourceProviderHandler.class);
    when(handler.getResourceProvider()).thenReturn(this.rp);
    src = new AuthenticatedResourceProvider(handler, false, resolveContext, securityTracker);
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) ResourceAccessSecurityTracker(org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker) ResourceAccessSecurity(org.apache.sling.api.security.ResourceAccessSecurity) QueryLanguageProvider(org.apache.sling.spi.resource.provider.QueryLanguageProvider) Before(org.junit.Before)

Example 4 with ResolveContext

use of org.apache.sling.spi.resource.provider.ResolveContext in project sling by apache.

the class ResourceResolverImplTest method setup.

@Before
public void setup() throws LoginException {
    ResourceProvider<?> rp = new ResourceProvider<Object>() {

        @Override
        public Resource getResource(ResolveContext<Object> ctx, String path, ResourceContext rCtx, Resource parent) {
            return null;
        }

        @Override
        public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
            return null;
        }
    };
    List<ResourceProviderHandler> handlers = asList(createRPHandler(rp, "rp1", 0, "/"));
    resourceProviderTracker = mock(ResourceProviderTracker.class);
    ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
    when(resourceProviderTracker.getResourceProviderStorage()).thenReturn(storage);
    ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
    activator.resourceProviderTracker = resourceProviderTracker;
    activator.resourceAccessSecurityTracker = new ResourceAccessSecurityTracker();
    commonFactory = new CommonResourceResolverFactoryImpl(activator);
    final Bundle usingBundle = mock(Bundle.class);
    resFac = new ResourceResolverFactoryImpl(commonFactory, usingBundle, null);
    resResolver = resFac.getAdministrativeResourceResolver(null);
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceContext(org.apache.sling.spi.resource.provider.ResourceContext) ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) Bundle(org.osgi.framework.Bundle) ResourceProviderTracker(org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) Before(org.junit.Before)

Example 5 with ResolveContext

use of org.apache.sling.spi.resource.provider.ResolveContext in project sling by apache.

the class ResourceDecoratorTestBase method setup.

@Before
public void setup() throws LoginException {
    final ResourceDecorator d = new ResourceDecorator() {

        @Override
        public Resource decorate(Resource resource) {
            return ResourceDecoratorTestBase.this.wrapResourceForTest(resource);
        }

        @Override
        public Resource decorate(Resource resource, HttpServletRequest request) {
            throw new UnsupportedOperationException("Not supposed to be used in these tests");
        }
    };
    final ResourceDecoratorTracker t = new ResourceDecoratorTracker();
    t.bindResourceDecorator(d, null);
    final ResourceProvider<?> provider = new ResourceProvider<Object>() {

        @Override
        public QueryLanguageProvider<Object> getQueryLanguageProvider() {
            return new QueryLanguageProvider<Object>() {

                @Override
                public String[] getSupportedLanguages(ResolveContext<Object> ctx) {
                    return new String[] { QUERY_LANGUAGE };
                }

                @Override
                public Iterator<Resource> findResources(ResolveContext<Object> ctx, String query, String language) {
                    final List<Resource> found = new ArrayList<Resource>();
                    found.add(mockResource("/tmp/C"));
                    found.add(mockResource("/tmp/D"));
                    found.add(mockResource("/var/one"));
                    found.add(mockResource("/var/two"));
                    return found.iterator();
                }

                @Override
                public Iterator<ValueMap> queryResources(ResolveContext<Object> ctx, String query, String language) {
                    return null;
                }
            };
        }

        @Override
        public Resource getResource(ResolveContext<Object> ctx, String path, final ResourceContext rCtx, Resource parent) {
            if (path.equals("/") || path.startsWith("/tmp") || path.startsWith("/var")) {
                return mockResource(path);
            }
            return null;
        }

        @Override
        public Iterator<Resource> listChildren(ResolveContext<Object> ctx, Resource parent) {
            final List<Resource> children = new ArrayList<Resource>();
            if ("/".equals(parent.getPath())) {
                children.add(mockResource("/tmp"));
                children.add(mockResource("/var"));
            } else if ("/var".equals(parent.getPath())) {
                children.add(mockResource("/var/one"));
                children.add(mockResource("/var/two"));
                children.add(mockResource("/var/three"));
            } else if ("/tmp".equals(parent.getPath())) {
                children.add(mockResource("/tmp/A"));
                children.add(mockResource("/tmp/B"));
                children.add(mockResource("/tmp/C"));
                children.add(mockResource("/tmp/D"));
            }
            return children.iterator();
        }
    };
    ResourceResolverFactoryActivator activator = new ResourceResolverFactoryActivator();
    final CommonResourceResolverFactoryImpl crf = new CommonResourceResolverFactoryImpl(activator) {

        @Override
        public ResourceDecoratorTracker getResourceDecoratorTracker() {
            return t;
        }

        @Override
        public ResourceAccessSecurityTracker getResourceAccessSecurityTracker() {
            return new ResourceAccessSecurityTracker();
        }
    };
    final List<ResourceProviderHandler> list = Arrays.asList(MockedResourceResolverImplTest.createRPHandler(provider, "A-provider", 0L, "/"));
    resolver = new ResourceResolverImpl(crf, false, null, new ResourceProviderStorageProvider() {

        @Override
        public ResourceProviderStorage getResourceProviderStorage() {
            return new ResourceProviderStorage(list);
        }
    });
}
Also used : ResolveContext(org.apache.sling.spi.resource.provider.ResolveContext) ResourceContext(org.apache.sling.spi.resource.provider.ResourceContext) ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ValueMap(org.apache.sling.api.resource.ValueMap) NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) ResourceProviderStorageProvider(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider) ResourceDecorator(org.apache.sling.api.resource.ResourceDecorator) HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) ResourceDecoratorTracker(org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker) QueryLanguageProvider(org.apache.sling.spi.resource.provider.QueryLanguageProvider) Before(org.junit.Before)

Aggregations

ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)5 Resource (org.apache.sling.api.resource.Resource)4 ResourceProviderHandler (org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler)3 ResourceProvider (org.apache.sling.spi.resource.provider.ResourceProvider)3 Before (org.junit.Before)3 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)2 ResourceProviderStorage (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage)2 QueryLanguageProvider (org.apache.sling.spi.resource.provider.QueryLanguageProvider)2 ResourceContext (org.apache.sling.spi.resource.provider.ResourceContext)2 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ParametrizableResourceProvider (org.apache.sling.api.resource.ParametrizableResourceProvider)1 ResourceDecorator (org.apache.sling.api.resource.ResourceDecorator)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 ResourceAccessSecurity (org.apache.sling.api.security.ResourceAccessSecurity)1 ResourceAccessSecurityTracker (org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker)1 ResourceDecoratorTracker (org.apache.sling.resourceresolver.impl.helper.ResourceDecoratorTracker)1