diff options
author | Bjørn Christian Seime <bjorncs@oath.com> | 2018-02-20 17:15:33 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@oath.com> | 2018-02-20 17:15:33 +0100 |
commit | ef9bd4f8b90cb88c7350e8681f8b9613d9e07891 (patch) | |
tree | 1e0258ed24b60c751559c7b2c44c5ccee47e472d /application | |
parent | 7cbcd92168f36a63f0dade4acc5683e134e9ac48 (diff) |
Support user principal in incoming request
Diffstat (limited to 'application')
-rw-r--r-- | application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java | 4 | ||||
-rw-r--r-- | application/src/main/java/com/yahoo/application/container/handler/Request.java | 20 |
2 files changed, 23 insertions, 1 deletions
diff --git a/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java b/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java index 7475c08009c..7b806642e39 100644 --- a/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java +++ b/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java @@ -88,9 +88,11 @@ final class SynchronousRequestResponseHandler { String scheme = getScheme(request.getUri()); com.yahoo.jdisc.Request discRequest; if ("http".equals(scheme) || "https".equals(scheme)) { - discRequest = com.yahoo.jdisc.http.HttpRequest.newServerRequest(currentContainer, + com.yahoo.jdisc.http.HttpRequest httpRequest = com.yahoo.jdisc.http.HttpRequest.newServerRequest(currentContainer, URI.create(request.getUri()), com.yahoo.jdisc.http.HttpRequest.Method.valueOf(request.getMethod().name())); + request.getUserPrincipal().ifPresent(httpRequest::setUserPrincipal); + discRequest = httpRequest; } else { discRequest = new com.yahoo.jdisc.Request(currentContainer, URI.create(request.getUri())); } diff --git a/application/src/main/java/com/yahoo/application/container/handler/Request.java b/application/src/main/java/com/yahoo/application/container/handler/Request.java index 1a6dbe59f04..87543c7db9a 100644 --- a/application/src/main/java/com/yahoo/application/container/handler/Request.java +++ b/application/src/main/java/com/yahoo/application/container/handler/Request.java @@ -5,7 +5,9 @@ import com.google.common.annotations.Beta; import net.jcip.annotations.Immutable; import java.nio.charset.StandardCharsets; +import java.security.Principal; import java.util.Map; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; /** @@ -23,6 +25,7 @@ public class Request { private final byte[] body; private final Method method; private final Map<String, Object> attributes = new ConcurrentHashMap<>(); + private final Principal userPrincipal; /** * Creates a Request with an empty body. @@ -60,9 +63,22 @@ public class Request { * @param body the body of the request */ public Request(String uri, byte[] body, Method method) { + this(uri, body, method, null); + } + + /** + * Creates a Request with a message body, method and user principal. + * + * @param uri the URI of the request + * @param body the body of the request + * @param method the method of the request + * @param principal the user principal of the request + */ + public Request(String uri, byte[] body, Method method, Principal principal) { this.uri = uri; this.body = body; this.method = method; + this.userPrincipal = principal; } /** @@ -118,6 +134,10 @@ public class Request { return method; } + public Optional<Principal> getUserPrincipal() { + return Optional.ofNullable(userPrincipal); + } + public enum Method { OPTIONS, GET, |