Search in sources :

Example 16 with ResourceProviderHandler

use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler in project sling by apache.

the class ResourceResolverControlTest method prepare.

@Before
public void prepare() throws Exception {
    BundleContext bc = MockOsgi.newBundleContext();
    Fixture fixture = new Fixture(bc);
    // sub-provider
    subProvider = Mockito.mock(ResourceProvider.class);
    ResourceProviderInfo info = fixture.registerResourceProvider(subProvider, "/some/path", AuthType.required);
    ResourceProviderHandler handler = new ResourceProviderHandler(bc, info);
    when(subProvider.getQueryLanguageProvider()).thenReturn(new SimpleQueryLanguageProvider(QL_MOCK, QL_ANOTHER_MOCK) {

        @Override
        public Iterator<ValueMap> queryResources(ResolveContext<Object> ctx, String query, String language) {
            if (query.equals(QUERY_MOCK_FIND_ALL) && language.equals(QL_MOCK)) {
                SimpleValueMapImpl valueMap = new SimpleValueMapImpl();
                valueMap.put("key", "value");
                return Collections.<ValueMap>singletonList(valueMap).iterator();
            }
            throw new UnsupportedOperationException();
        }

        @Override
        public Iterator<Resource> findResources(ResolveContext<Object> ctx, String query, String language) {
            if (query.equals(QUERY_MOCK_FIND_ALL) && language.equals(QL_MOCK)) {
                return Collections.<Resource>singletonList(newMockResource("/some/path/object")).iterator();
            }
            throw new UnsupportedOperationException();
        }
    });
    handler.activate();
    rootProvider = mock(ResourceProvider.class);
    ResourceProviderInfo rootInfo = fixture.registerResourceProvider(rootProvider, "/", AuthType.required);
    ResourceProviderHandler rootHandler = new ResourceProviderHandler(bc, rootInfo);
    when(rootProvider.getQueryLanguageProvider()).thenReturn(new SimpleQueryLanguageProvider(QL_NOOP));
    rootHandler.activate();
    // configure mock resources
    Resource root = configureResourceAt(rootProvider, "/");
    somethingResource = configureResourceAt(rootProvider, "/something");
    subProviderResource = configureResourceAt(subProvider, "/some/path/object");
    // configure query at '/'
    when(rootProvider.listChildren((ResolveContext<Object>) Mockito.anyObject(), Mockito.eq(root))).thenReturn(Collections.singleton(somethingResource).iterator());
    ResourceResolver rr = mock(ResourceResolver.class);
    ResourceAccessSecurityTracker securityTracker = Mockito.mock(ResourceAccessSecurityTracker.class);
    authInfo = getAuthInfo();
    handlers = Arrays.asList(rootHandler, handler);
    final ResourceProviderStorage storage = new ResourceProviderStorage(handlers);
    crp = new ResourceResolverControl(false, authInfo, new ResourceProviderStorageProvider() {

        @Override
        public ResourceProviderStorage getResourceProviderStorage() {
            return storage;
        }
    });
    context = new ResourceResolverContext(rr, securityTracker);
}
Also used : ResourceProviderHandler(org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ResourceProviderStorageProvider(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider) SimpleValueMapImpl(org.apache.sling.resourceresolver.impl.SimpleValueMapImpl) ResourceProviderInfo(org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo) ResourceProviderStorage(org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage) ResourceProvider(org.apache.sling.spi.resource.provider.ResourceProvider) Iterator(java.util.Iterator) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ResourceAccessSecurityTracker(org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker) Fixture(org.apache.sling.resourceresolver.impl.Fixture) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 17 with ResourceProviderHandler

use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler 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 18 with ResourceProviderHandler

use of org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler in project sling by apache.

the class AuthenticatedResourceProviderTest method prepare.

@Before
public void prepare() throws PersistenceException, AccessSecurityException {
    this.resourceResolver = mock(ResourceResolver.class);
    this.resolveContext = mock(ResolveContext.class);
    when(this.resolveContext.getResourceResolver()).thenReturn(this.resourceResolver);
    this.security = mock(ResourceAccessSecurity.class);
    this.queryLanguageProvider = mock(QueryLanguageProvider.class);
    this.resourceProvider = mock(ResourceProvider.class);
    when(resourceProvider.getQueryLanguageProvider()).thenReturn(this.queryLanguageProvider);
    final ResourceProviderHandler handler = mock(ResourceProviderHandler.class);
    when(handler.getResourceProvider()).thenReturn(this.resourceProvider);
    useRAS = false;
    final ResourceAccessSecurityTracker securityTracker = new ResourceAccessSecurityTracker() {

        @Override
        public ResourceAccessSecurity getApplicationResourceAccessSecurity() {
            if (useRAS) {
                return security;
            }
            return null;
        }
    };
    this.src = new AuthenticatedResourceProvider(handler, false, this.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) 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)

Aggregations

ResourceProviderHandler (org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler)18 Resource (org.apache.sling.api.resource.Resource)9 ResourceProviderStorage (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage)7 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)7 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)6 Test (org.junit.Test)6 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)5 ResourceProviderTracker (org.apache.sling.resourceresolver.impl.providers.ResourceProviderTracker)5 ResourceContext (org.apache.sling.spi.resource.provider.ResourceContext)5 ResourceProvider (org.apache.sling.spi.resource.provider.ResourceProvider)5 Before (org.junit.Before)5 ArrayList (java.util.ArrayList)4 ResourceProviderInfo (org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo)4 ServiceReference (org.osgi.framework.ServiceReference)4 LoginException (org.apache.sling.api.resource.LoginException)3 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)3 ResourceAccessSecurityTracker (org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker)3 ResourceProviderStorageProvider (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider)3 QueryLanguageProvider (org.apache.sling.spi.resource.provider.QueryLanguageProvider)3 AbstractResource (org.apache.sling.api.resource.AbstractResource)2