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