knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject knox git commit: KNOX-877 - Coverity Scan Cleanup
Date Thu, 09 Feb 2017 18:04:07 GMT
Repository: knox
Updated Branches:
  refs/heads/master e90109f37 -> f1dcae4dc


KNOX-877 - Coverity Scan Cleanup

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

Branch: refs/heads/master
Commit: f1dcae4dc38cd67c59eb6f6050231332020bc6ae
Parents: e90109f
Author: Larry McCay <lmccay@hortonworks.com>
Authored: Thu Feb 9 13:03:50 2017 -0500
Committer: Larry McCay <lmccay@hortonworks.com>
Committed: Thu Feb 9 13:03:50 2017 -0500

----------------------------------------------------------------------
 .../service/knoxtoken/TokenResource.java        | 34 +++++++++++---------
 .../org/apache/hadoop/gateway/shell/KnoxSh.java | 27 ++++++++--------
 2 files changed, 32 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/f1dcae4d/gateway-service-knoxtoken/src/main/java/org/apache/hadoop/gateway/service/knoxtoken/TokenResource.java
----------------------------------------------------------------------
diff --git a/gateway-service-knoxtoken/src/main/java/org/apache/hadoop/gateway/service/knoxtoken/TokenResource.java
b/gateway-service-knoxtoken/src/main/java/org/apache/hadoop/gateway/service/knoxtoken/TokenResource.java
index 16b3852..726f664 100644
--- a/gateway-service-knoxtoken/src/main/java/org/apache/hadoop/gateway/service/knoxtoken/TokenResource.java
+++ b/gateway-service-knoxtoken/src/main/java/org/apache/hadoop/gateway/service/knoxtoken/TokenResource.java
@@ -118,23 +118,25 @@ public class TokenResource {
         token = ts.issueToken(p, aud, "RS256", expires);
       }
 
-      String accessToken = token.toString();
-
-      HashMap<String, Object> map = new HashMap<String, Object>();
-      // TODO: populate map from JWT authorization code
-      map.put(ACCESS_TOKEN, accessToken);
-      map.put(TOKEN_TYPE, BEARER);
-      map.put(EXPIRES_IN, expires);
-      if (tokenTargetUrl != null) {
-        map.put(TARGET_URL, tokenTargetUrl);
+      if (token != null) {
+        String accessToken = token.toString();
+  
+        HashMap<String, Object> map = new HashMap<String, Object>();
+        map.put(ACCESS_TOKEN, accessToken);
+        map.put(TOKEN_TYPE, BEARER);
+        map.put(EXPIRES_IN, expires);
+        if (tokenTargetUrl != null) {
+          map.put(TARGET_URL, tokenTargetUrl);
+        }
+  
+        String jsonResponse = JsonUtils.renderAsJsonString(map);
+        
+        response.getWriter().write(jsonResponse);
+        return Response.ok().build();
+      }
+      else {
+        return Response.serverError().build();
       }
-
-      String jsonResponse = JsonUtils.renderAsJsonString(map);
-      
-      response.getWriter().write(jsonResponse);
-      //KNOX-685: response.getWriter().flush();
-//      return response; // break filter chain
-      return Response.ok().build();
 
     }
     catch (TokenServiceException | IOException e) {

http://git-wip-us.apache.org/repos/asf/knox/blob/f1dcae4d/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java
----------------------------------------------------------------------
diff --git a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java
index 954a640..3dfce78 100644
--- a/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java
+++ b/gateway-shell/src/main/java/org/apache/hadoop/gateway/shell/KnoxSh.java
@@ -185,19 +185,20 @@ public class KnoxSh {
         //println "Access Token: " + json.access_token
         System.out.println("knoxinit successful!");
         displayTokenDetails(json);
-  
-        File tokenfile = new File(System.getProperty("user.home"), ".knoxtokencache");
-        FileOutputStream fos = new FileOutputStream(tokenfile);
-        fos.write(text.getBytes("UTF-8"));
-  
-        Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
-        fos.close();
-  
-        //add owners permission only
-        perms.add(PosixFilePermission.OWNER_READ);
-        perms.add(PosixFilePermission.OWNER_WRITE);
-  
-        Files.setPosixFilePermissions(Paths.get(System.getProperty("user.home") + "/.knoxtokencache"),
perms);
+        
+        FileOutputStream fos = null;
+        try {
+          File tokenfile = new File(System.getProperty("user.home"), ".knoxtokencache");
+          fos = new FileOutputStream(tokenfile);
+          fos.write(text.getBytes("UTF-8"));
+          Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
+          //add owners permission only
+          perms.add(PosixFilePermission.OWNER_READ);
+          perms.add(PosixFilePermission.OWNER_WRITE);
+          Files.setPosixFilePermissions(Paths.get(System.getProperty("user.home") + "/.knoxtokencache"),
perms);
+        } finally {
+          fos.close();
+        }
       }
       catch(HadoopException he) {
         System.out.println("Failure to acquire token. Please verify your credentials and
Knox URL and try again.");


Mime
View raw message