Search in sources :

Example 1 with ResourceAccessSecurity

use of org.apache.sling.api.security.ResourceAccessSecurity in project sling by apache.

the class AuthenticatedResourceProvider method transformQuery.

/**
     * applies resource access security if configured
     */
private String transformQuery(final String query, final String language) {
    String returnValue = query;
    if (this.useRAS) {
        final ResourceAccessSecurity resourceAccessSecurity = tracker.getProviderResourceAccessSecurity();
        if (resourceAccessSecurity != null) {
            try {
                returnValue = resourceAccessSecurity.transformQuery(returnValue, language, this.resolveContext.getResourceResolver());
            } catch (AccessSecurityException e) {
                logger.error("AccessSecurityException occurred while trying to transform the query {} (language {}).", new Object[] { query, language }, e);
            }
        }
    }
    final ResourceAccessSecurity resourceAccessSecurity = tracker.getApplicationResourceAccessSecurity();
    if (resourceAccessSecurity != null) {
        try {
            returnValue = resourceAccessSecurity.transformQuery(returnValue, language, this.resolveContext.getResourceResolver());
        } catch (AccessSecurityException e) {
            logger.error("AccessSecurityException occurred while trying to transform the query {} (language {}).", new Object[] { query, language }, e);
        }
    }
    return returnValue;
}
Also used : ResourceAccessSecurity(org.apache.sling.api.security.ResourceAccessSecurity) AccessSecurityException(org.apache.sling.api.security.AccessSecurityException)

Example 2 with ResourceAccessSecurity

use of org.apache.sling.api.security.ResourceAccessSecurity 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 3 with ResourceAccessSecurity

use of org.apache.sling.api.security.ResourceAccessSecurity 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

ResourceAccessSecurity (org.apache.sling.api.security.ResourceAccessSecurity)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 ResourceAccessSecurityTracker (org.apache.sling.resourceresolver.impl.ResourceAccessSecurityTracker)2 ResourceProviderHandler (org.apache.sling.resourceresolver.impl.providers.ResourceProviderHandler)2 QueryLanguageProvider (org.apache.sling.spi.resource.provider.QueryLanguageProvider)2 ResolveContext (org.apache.sling.spi.resource.provider.ResolveContext)2 ResourceProvider (org.apache.sling.spi.resource.provider.ResourceProvider)2 Before (org.junit.Before)2 Resource (org.apache.sling.api.resource.Resource)1 AccessSecurityException (org.apache.sling.api.security.AccessSecurityException)1