You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by gh...@apache.org on 2020/09/22 00:12:02 UTC
[sling-org-apache-sling-engine] 01/01: SLING-9662 Use SlingUri as
provided in request from auth.core
This is an automated email from the ASF dual-hosted git repository.
ghenzler pushed a commit to branch feature/SLING-9662-Introduce-SlingUri-Mapping-SPI_v3
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-engine.git
commit b9448bd06dfe66f2661bd1850045b4306ab0f8a2
Author: georg.henzler <ge...@netcentric.biz>
AuthorDate: Mon Sep 21 17:13:00 2020 +0200
SLING-9662 Use SlingUri as provided in request from auth.core
---
pom.xml | 4 ++--
.../sling/engine/impl/request/RequestData.java | 23 ++++++++++------------
.../engine/impl/request/InitResourceTest.java | 17 +++++++++-------
3 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/pom.xml b/pom.xml
index 83d0419..9917ad6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -111,7 +111,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.6.0</version>
+ <version>2.23.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -123,7 +123,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.auth.core</artifactId>
- <version>1.0.0</version>
+ <version>1.5.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
diff --git a/src/main/java/org/apache/sling/engine/impl/request/RequestData.java b/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
index 379eb83..71f9921 100644
--- a/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
+++ b/src/main/java/org/apache/sling/engine/impl/request/RequestData.java
@@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
+import java.util.Map;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
@@ -46,8 +47,10 @@ import org.apache.sling.api.request.TooManyCallsException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.api.uri.SlingUri;
import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
+import org.apache.sling.auth.core.AuthenticationSupport;
import org.apache.sling.engine.impl.SlingHttpServletRequestImpl;
import org.apache.sling.engine.impl.SlingHttpServletResponseImpl;
import org.apache.sling.engine.impl.SlingMainServlet;
@@ -213,8 +216,7 @@ public class RequestData {
this.servletResponse = response;
this.slingRequest = getSlingHttpServletRequestFactory().createRequest(this, this.servletRequest);
- this.slingResponse = new SlingHttpServletResponseImpl(this,
- servletResponse);
+ this.slingResponse = new SlingHttpServletResponseImpl(this, servletResponse);
// Getting the RequestProgressTracker from the request attributes like
// this should not be generally used, it's just a way to pass it from
@@ -237,19 +239,14 @@ public class RequestData {
requestProgressTracker.startTimer("ResourceResolution");
final SlingHttpServletRequest request = getSlingRequest();
- StringBuffer requestURL = servletRequest.getRequestURL();
- String path = request.getPathInfo();
- if (requestURL.indexOf(";") > -1 && !path.contains(";")) {
- final String decodedURL;
- try {
- decodedURL = URLDecoder.decode(requestURL.toString(), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new AssertionError("UTF-8 encoding is not supported");
- }
- path = path.concat(decodedURL.substring(decodedURL.indexOf(';')));
+ // Set by o.a.s.auth.core bundle
+ SlingUri slingUri = (SlingUri) request.getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_URI);
+ if (slingUri == null) {
+ throw new IllegalStateException(
+ "SlingUri not available as attribute of request (expected to be set in bundle o.a.s.auth.core)");
}
- Resource resource = resourceResolver.resolve(request, path);
+ Resource resource = resourceResolver.resolve(request, slingUri.getPath());
if (request.getAttribute(REQUEST_RESOURCE_PATH_ATTR) == null) {
request.setAttribute(REQUEST_RESOURCE_PATH_ATTR, resource.getPath());
}
diff --git a/src/test/java/org/apache/sling/engine/impl/request/InitResourceTest.java b/src/test/java/org/apache/sling/engine/impl/request/InitResourceTest.java
index 9e5f1ce..92be856 100644
--- a/src/test/java/org/apache/sling/engine/impl/request/InitResourceTest.java
+++ b/src/test/java/org/apache/sling/engine/impl/request/InitResourceTest.java
@@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.sling.api.request.RequestProgressTracker;
import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.uri.SlingUriBuilder;
+import org.apache.sling.auth.core.AuthenticationSupport;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.junit.Before;
@@ -48,13 +50,13 @@ public class InitResourceTest {
@Parameters(name="URL={0} path={1}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
- { "/one;v=1.1", "one;v=1.1", "/one;v=1.1" },
- { "/two;v=1.1", "two", "/two;v=1.1" },
+ { "/one;v=1.1", "one;v=1.1", "/one;v='1.1'" },
+ { "/two;v=1.1", "two", "/two;v='1.1'" },
{ "/three", "three", "/three" },
{ "/four%3Bv=1.1", "four", "/four" },
- { "/five%3Bv=1.1", "five;v=1.1", "/five;v=1.1" },
- { "/six;v=1.1", "six;v=1.1", "/six;v=1.1" },
- { "/seven", "seven;v=1.1", "/seven;v=1.1" },
+ { "/five%3Bv=1.1", "five;v=1.1", "/five;v='1.1'" },
+ { "/six;v=1.1", "six;v=1.1", "/six;v='1.1'" },
+ { "/seven", "seven;v=1.1", "/seven;v='1.1'" },
});
}
@@ -73,8 +75,9 @@ public class InitResourceTest {
resourceResolver = context.mock(ResourceResolver.class);
context.checking(new Expectations() {{
- allowing(req).getRequestURL();
- will(returnValue(new StringBuffer(requestURL)));
+
+ allowing(req).getAttribute(AuthenticationSupport.REQUEST_ATTRIBUTE_URI);
+ will(returnValue(SlingUriBuilder.create().setPath(expectedResolvePath).build()));
allowing(req).getRequestURI();