AMBARI-19010. Log Search external login credential let every user in (oleewere)

Change-Id: Iab889180bfb4916fd06240588b6cdd80493889a1


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/26868322
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/26868322
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/26868322

Branch: refs/heads/branch-feature-AMBARI-18901
Commit: 268683220382cb1f0061d1e9135cc882b74c0f97
Parents: 6f4055f
Author: oleewere <oleew...@gmail.com>
Authored: Tue Nov 29 13:16:51 2016 +0100
Committer: oleewere <oleew...@gmail.com>
Committed: Tue Nov 29 18:02:11 2016 +0100

----------------------------------------------------------------------
 .../ambari/logsearch/common/ExternalServerClient.java   | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/26868322/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java
----------------------------------------------------------------------
diff --git 
a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java
 
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java
index 1207373..230ca8c 100644
--- 
a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java
+++ 
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java
@@ -23,9 +23,11 @@ import javax.inject.Named;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 
 import org.apache.ambari.logsearch.conf.AuthPropsConfig;
 import org.apache.ambari.logsearch.util.SSLUtil;
+import org.apache.commons.httpclient.auth.InvalidCredentialsException;
 import org.apache.log4j.Logger;
 import org.glassfish.jersey.client.JerseyClient;
 import org.glassfish.jersey.client.JerseyClientBuilder;
@@ -64,9 +66,15 @@ public class ExternalServerClient {
     WebTarget target = client.target(url);
     LOG.debug("URL: " + url);
     
-    Invocation.Builder invocationBuilder =  
target.request(MediaType.APPLICATION_JSON_TYPE);
+    Invocation.Builder invocationBuilder =  target.request();
     try {
-      return invocationBuilder.get().readEntity(klass);
+      Response response = invocationBuilder.get();
+      if (response.getStatus() != Response.Status.OK.getStatusCode()
+        && response.getStatus() != Response.Status.FOUND.getStatusCode()) {
+        throw new InvalidCredentialsException(String.format("External auth 
failed with status code: %d, response: %s",
+          response.getStatus(), response.readEntity(String.class)));
+      }
+      return response.readEntity(klass);
     } catch (Exception e) {
       throw new Exception(e.getCause());
     } finally {

Reply via email to