You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/04/19 13:38:36 UTC

[cxf] 05/09: Use JavaUtils method instead to determine JDK compatability

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit a4a93414e7cc1ce8d844b146ba8559c7f2485c0c
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Thu Apr 19 10:35:03 2018 +0100

    Use JavaUtils method instead to determine JDK compatability
---
 .../java/org/apache/cxf/rt/security/crypto/CryptoUtils.java  | 12 ++----------
 .../cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest.java     | 11 ++---------
 2 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java b/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
index 20475a9..c6a899b 100644
--- a/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
+++ b/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
@@ -62,6 +62,7 @@ import org.apache.cxf.common.util.Base64UrlUtility;
 import org.apache.cxf.common.util.Base64Utility;
 import org.apache.cxf.common.util.CompressionUtils;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.JavaUtils;
 
 
 /**
@@ -544,8 +545,7 @@ public final class CryptoUtils {
                 result = c.doFinal(bytes);
             } else {
                 if (blockSize == -1) {
-                    String javaVersion = System.getProperty("java.version");
-                    if (isJava9Compatible(javaVersion) || isJava8Release161OrLater(javaVersion)) {
+                    if (JavaUtils.isJava9Compatible() || isJava8Release161OrLater(System.getProperty("java.version"))) {
                         //the default block size is 256 when use private key under java9
                         blockSize = secretKey instanceof PublicKey ? 117 : 256;
                     } else {
@@ -575,14 +575,6 @@ public final class CryptoUtils {
         }
     }
 
-    private static boolean isJava9Compatible(String javaVersion) {
-        if (javaVersion.indexOf(".") > 0) {
-            javaVersion = javaVersion.substring(0, javaVersion.indexOf("."));
-        }
-
-        return Integer.valueOf(javaVersion) >= 9;
-    }
-
     private static boolean isJava8Release161OrLater(String javaVersion) {
         return javaVersion.startsWith("1.8.0_") && Integer.parseInt(javaVersion.substring(6)) >= 161;
     }
diff --git a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest.java b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest.java
index 6e8a015..269396e 100644
--- a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest.java
+++ b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/PolicyBasedWss4JInOutTest.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
 
 import javax.xml.namespace.QName;
 
+import org.apache.cxf.helpers.JavaUtils;
 import org.apache.cxf.ws.security.wss4j.CryptoCoverageUtil.CoverageType;
 import org.apache.wss4j.policy.SP12Constants;
 
@@ -430,7 +431,7 @@ public class PolicyBasedWss4JInOutTest extends AbstractPolicySecurityTest {
                 null,
                 Arrays.asList(CoverageType.ENCRYPTED, CoverageType.SIGNED));
 
-        if (!isJava9Compatible()) {
+        if (!JavaUtils.isJava9Compatible()) {
             // CXF-7270
             this.runAndValidate(
                 "wsse-request-clean.xml",
@@ -556,12 +557,4 @@ public class PolicyBasedWss4JInOutTest extends AbstractPolicySecurityTest {
         // TODO: Tests for derived keys.
     }
 
-    private boolean isJava9Compatible() {
-        String version = System.getProperty("java.version");
-        if (version.indexOf(".") > 0) {
-            version = version.substring(0, version.indexOf("."));
-        }
-
-        return Integer.valueOf(version) >= 9;
-    }
 }

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.