summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2018-02-21 16:19:06 +0100
committerBjørn Christian Seime <bjorncs@oath.com>2018-02-21 16:19:06 +0100
commit2bc9a1173a0ef7a11b11be1d65b2ae66a773d017 (patch)
treeceb93d42aed17c3f0a7ee15fbdd43345864e08f9 /controller-server
parente85ab74e8091edf8d14d22acfcf95d92788d617f (diff)
Improve error message when principal is of wrong type
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java11
1 files changed, 8 insertions, 3 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
index c161374d753..9bf2a858476 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java
@@ -88,6 +88,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.security.Principal;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
@@ -1045,9 +1046,13 @@ public class ApplicationApiHandler extends LoggingRequestHandler {
}
private static AthenzPrincipal getUserPrincipal(HttpRequest request) {
- return Optional.ofNullable(request.getJDiscRequest().getUserPrincipal())
- .map(AthenzPrincipal.class::cast)
- .orElseThrow(() -> new InternalServerErrorException("Expected user principal"));
+ Principal principal = request.getJDiscRequest().getUserPrincipal();
+ if (principal == null) throw new InternalServerErrorException("Expected a user principal");
+ if (!(principal instanceof AthenzPrincipal))
+ throw new InternalServerErrorException(
+ String.format("Expected principal of type %s, got %s",
+ AthenzPrincipal.class.getSimpleName(), principal.getClass().getName()));
+ return (AthenzPrincipal) principal;
}
private Inspector mandatory(String key, Inspector object) {