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);
}
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);
}
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);
}
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());
}
Aggregations