Search in sources :

Example 1 with ResourceAccessSecurityTracker

use of org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker 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 2 with ResourceAccessSecurityTracker

use of org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker 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)

Example 3 with ResourceAccessSecurityTracker

use of org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker 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 4 with ResourceAccessSecurityTracker

use of org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker in project sling by apache.

the class ResourceResolverFactoryInitializer method ensureResourceResolverFactoryActivatorDependencies.

/**
     * Ensure dependencies for ResourceResolverFactoryActivator are present.
     * @param bundleContext Bundle context
     */
private static void ensureResourceResolverFactoryActivatorDependencies(BundleContext bundleContext) {
    Dictionary<String, Object> config = new Hashtable<String, Object>();
    config.put("user.mapping", bundleContext.getBundle().getSymbolicName() + "=admin");
    registerServiceIfNotPresent(bundleContext, ServiceUserMapper.class, new ServiceUserMapperImpl(), config);
    registerServiceIfNotPresent(bundleContext, ResourceAccessSecurityTracker.class, new ResourceAccessSecurityTracker());
    registerServiceIfNotPresent(bundleContext, EventAdmin.class, new MockEventAdmin());
}
Also used : MockEventAdmin(org.apache.sling.testing.mock.osgi.MockEventAdmin) Hashtable(java.util.Hashtable) ServiceUserMapperImpl(org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl) ResourceAccessSecurityTracker(org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker)

Aggregations

ResourceAccessSecurityTracker (org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 ResourceProviderHandler (org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler)3 ResourceProvider (org.apache.sling.spi.resource.provider.ResourceProvider)3 Before (org.junit.Before)3 Resource (org.apache.sling.api.resource.Resource)2 ResourceAccessSecurity (org.apache.sling.api.security.ResourceAccessSecurity)2 QueryLanguageProvider (org.apache.sling.spi.resource.provider.QueryLanguageProvider)2 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)2 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 Fixture (org.apache.sling.resourceresolver.impl.Fixture)1 SimpleValueMapImpl (org.apache.sling.resourceresolver.impl.SimpleValueMapImpl)1 ResourceProviderInfo (org.apache.sling.resourceresolver.impl.providers.ResourceProviderInfo)1 ResourceProviderStorage (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorage)1 ResourceProviderStorageProvider (org.apache.sling.resourceresolver.impl.providers.ResourceProviderStorageProvider)1 ServiceUserMapperImpl (org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl)1 MockEventAdmin (org.apache.sling.testing.mock.osgi.MockEventAdmin)1 BundleContext (org.osgi.framework.BundleContext)1