use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class SlingRequestPathInfoTest method testTrailingDot.
public void testTrailingDot() {
RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path", "."));
assertEquals("/some/path", p.getResourcePath());
assertNull("Selectors are null", p.getSelectorString());
assertEquals(0, p.getSelectors().length);
assertNull("Extension is null", p.getExtension());
assertNull("Suffix is null", p.getSuffix());
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class SlingRequestPathInfoTest method testPathAndExtensionOnly.
public void testPathAndExtensionOnly() {
RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path/here", ".html"));
assertEquals("/some/path/here", p.getResourcePath());
assertNull("Selectors are null", p.getSelectorString());
assertEquals(0, p.getSelectors().length);
assertEquals("html", p.getExtension());
assertNull("Suffix is null", p.getSuffix());
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class SlingRequestPathInfoTest method testPathExtAndSuffix.
public void testPathExtAndSuffix() {
RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path/here", ".html/something"));
assertEquals("/some/path/here", p.getResourcePath());
assertNull("Selectors are null", p.getSelectorString());
assertEquals(0, p.getSelectors().length);
assertEquals("html", p.getExtension());
assertEquals("/something", p.getSuffix());
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class SlingRequestPathInfoTest method testPathAndOneSelectorOnly.
public void testPathAndOneSelectorOnly() {
RequestPathInfo p = new SlingRequestPathInfo(new MockResource("/some/path/here", ".print.html"));
assertEquals("/some/path/here", p.getResourcePath());
assertEquals("print", p.getSelectorString());
assertEquals(1, p.getSelectors().length);
assertEquals("print", p.getSelectors()[0]);
assertEquals("html", p.getExtension());
assertNull("Suffix is null", p.getSuffix());
}
use of org.apache.sling.api.request.RequestPathInfo in project sling by apache.
the class UrlFilter method doFilter.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (request instanceof SlingHttpServletRequest && response instanceof SlingHttpServletResponse) {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
RequestPathInfo pathInfo = slingRequest.getRequestPathInfo();
Resource definitionResource = findUrlFilterDefinitionResource(slingRequest.getResource(), slingRequest.getResourceResolver());
if (definitionResource != null) {
logger.debug("found url filter definition resource at {}", definitionResource.getPath());
ValueMap properties = definitionResource.adaptTo(ValueMap.class);
if (properties != null) {
if (checkSelector(pathInfo, properties) && checkSuffix(pathInfo, properties) && checkExtension(pathInfo, properties)) {
logger.debug("url filter definition resource at {} passed for request {}.", definitionResource.getPath(), slingRequest.getRequestPathInfo());
} else {
logger.info("url filter definition resource at {} FAILED for request {}.", definitionResource.getPath(), slingRequest.getRequestPathInfo());
slingResponse.sendError(403);
return;
}
}
}
}
chain.doFilter(request, response);
}
Aggregations