knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject knox git commit: KNOX-1540 - Replace UTF8 with StandardCharsets where possible
Date Thu, 01 Nov 2018 15:33:15 GMT
Repository: knox
Updated Branches:
  refs/heads/master 59311f757 -> 124b3368e


KNOX-1540 - Replace UTF8 with StandardCharsets where possible

Signed-off-by: Kevin Risden <krisden@apache.org>


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

Branch: refs/heads/master
Commit: 124b3368e3f3fd4799cdfcbe44c732973ea6b8db
Parents: 59311f7
Author: Kevin Risden <krisden@apache.org>
Authored: Thu Nov 1 10:58:34 2018 -0400
Committer: Kevin Risden <krisden@apache.org>
Committed: Thu Nov 1 10:58:40 2018 -0400

----------------------------------------------------------------------
 .../gateway/services/security/impl/DefaultCryptoService.java | 8 +-------
 .../gateway/services/security/impl/RemoteAliasService.java   | 2 +-
 .../gateway/services/security/impl/BaseKeystoreService.java  | 4 +---
 .../gateway/services/security/impl/CMFMasterService.java     | 6 +++---
 .../java/org/apache/knox/gateway/util/CertificateUtils.java  | 6 ++----
 5 files changed, 8 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/124b3368/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
index 2898624..502dfa2 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
@@ -17,7 +17,6 @@
  */
 package org.apache.knox.gateway.services.security.impl;
 
-import java.io.UnsupportedEncodingException;
 import java.nio.charset.StandardCharsets;
 import java.security.InvalidKeyException;
 import java.security.KeyStoreException;
@@ -108,12 +107,7 @@ public class DefaultCryptoService implements CryptoService {
 
   @Override
   public byte[] decryptForCluster(String clusterName, String alias, String cipherText) {
-    try {
-      return decryptForCluster(clusterName, alias, cipherText.getBytes("UTF8"), null, null);
-    } catch (UnsupportedEncodingException e) {
-      LOG.unsupportedEncoding( e );
-    }
-    return null;
+    return decryptForCluster(clusterName, alias, cipherText.getBytes(StandardCharsets.UTF_8),
null, null);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/knox/blob/124b3368/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/RemoteAliasService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/RemoteAliasService.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/RemoteAliasService.java
index 0ba5a84..7954361 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/RemoteAliasService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/RemoteAliasService.java
@@ -556,7 +556,7 @@ public class RemoteAliasService implements AliasService {
     return Base64.encodeBase64String(
         (Base64.encodeBase64String(result.salt) + "::" + Base64
             .encodeBase64String(result.iv) + "::" + Base64
-            .encodeBase64String(result.cipher)).getBytes("UTF8"));
+            .encodeBase64String(result.cipher)).getBytes(StandardCharsets.UTF_8));
 
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/124b3368/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java
index 67b034f..57d7884 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/BaseKeystoreService.java
@@ -173,12 +173,10 @@ public class BaseKeystoreService {
   protected void addCredential(String alias, String value, KeyStore ks) {
     if (ks != null) {
       try {
-        final Key key = new SecretKeySpec(value.getBytes("UTF8"), "AES");
+        final Key key = new SecretKeySpec(value.getBytes(StandardCharsets.UTF_8), "AES");
         ks.setKeyEntry( alias, key, masterService.getMasterSecret(), null);
       } catch (KeyStoreException e) {
         LOG.failedToAddCredential(e);
-      } catch (IOException e) {
-        LOG.failedToAddCredential(e);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/124b3368/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
index 4bae4b1..6552dcc 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/services/security/impl/CMFMasterService.java
@@ -140,9 +140,9 @@ public class CMFMasterService {
       String line = Base64.encodeBase64String((
           Base64.encodeBase64String(atom.salt) + "::" + 
           Base64.encodeBase64String(atom.iv) + "::" + 
-          Base64.encodeBase64String(atom.cipher)).getBytes("UTF8"));
+          Base64.encodeBase64String(atom.cipher)).getBytes(StandardCharsets.UTF_8));
       lines.add(line);
-      FileUtils.writeLines(masterFile, "UTF8", lines);
+      FileUtils.writeLines(masterFile, StandardCharsets.UTF_8.name(), lines);
       
       // restrict os permissions to only the user running this process
       chmod("600", masterFile);
@@ -169,7 +169,7 @@ public class CMFMasterService {
         String[] parts = line.split("::");
         this.master = new String(encryptor.decrypt(Base64.decodeBase64(parts[0]),
             Base64.decodeBase64(parts[1]), Base64.decodeBase64(parts[2])),
-            "UTF8").toCharArray();
+            StandardCharsets.UTF_8).toCharArray();
       } catch (IOException e) {
         LOG.failedToInitializeFromPersistentMaster(masterFile.getName(), e);
         throw e;

http://git-wip-us.apache.org/repos/asf/knox/blob/124b3368/gateway-util-common/src/main/java/org/apache/knox/gateway/util/CertificateUtils.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/CertificateUtils.java
b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/CertificateUtils.java
index 6aa0b3c..b55db71 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/CertificateUtils.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/CertificateUtils.java
@@ -18,7 +18,7 @@
 package org.apache.knox.gateway.util;
 
 import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.security.PublicKey;
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
@@ -44,7 +44,7 @@ public class CertificateUtils {
     try {
       CertificateFactory fact = CertificateFactory.getInstance("X.509");
       ByteArrayInputStream is = new ByteArrayInputStream(
-          fullPem.getBytes("UTF8"));
+          fullPem.getBytes(StandardCharsets.UTF_8));
 
       X509Certificate cer = (X509Certificate) fact.generateCertificate(is);
       key = cer.getPublicKey();
@@ -57,8 +57,6 @@ public class CertificateUtils {
         message = "CertificateException - PEM may be corrupt";
       }
       throw new ServletException(message, ce);
-    } catch (UnsupportedEncodingException uee) {
-      throw new ServletException(uee);
     }
     return (RSAPublicKey) key;
   }


Mime
View raw message