Search in sources :

Example 6 with RequestPathInfo

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());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 7 with RequestPathInfo

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());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 8 with RequestPathInfo

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());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 9 with RequestPathInfo

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());
}
Also used : RequestPathInfo(org.apache.sling.api.request.RequestPathInfo)

Example 10 with RequestPathInfo

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);
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) RequestPathInfo(org.apache.sling.api.request.RequestPathInfo) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest)

Aggregations

RequestPathInfo (org.apache.sling.api.request.RequestPathInfo)33 Resource (org.apache.sling.api.resource.Resource)4 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 Expectations (org.jmock.Expectations)2 Test (org.junit.Test)2 Servlet (javax.servlet.Servlet)1 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 SlingMainServlet (org.apache.sling.engine.impl.SlingMainServlet)1 VersioningConfiguration (org.apache.sling.servlets.post.VersioningConfiguration)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1