Use Java 8's Base64 instead of Jersey's or Apache Commons' 70/50670/1
authorStephen Kitt <skitt@redhat.com>
Thu, 19 Jan 2017 14:02:32 +0000 (15:02 +0100)
committerStephen Kitt <skitt@redhat.com>
Thu, 19 Jan 2017 14:02:32 +0000 (15:02 +0100)
Java 8 includes a Base64 decoder and encoder; using that allows us to
drop dependencies on Jersey and Apache Commons Codec.

Change-Id: Ibc1cea40c67e349b285d457974e20506cbad3af4
Signed-off-by: Stephen Kitt <skitt@redhat.com>
aaa-authn-basic/pom.xml
aaa-authn-basic/src/main/java/org/opendaylight/aaa/basic/HttpBasicAuth.java
aaa-authn-basic/src/test/java/org/opendaylight/aaa/basic/HttpBasicAuthTest.java
aaa-cert/pom.xml
aaa-cert/src/main/java/org/opendaylight/aaa/cert/impl/ODLKeyTool.java

index 6e2865d83fd606c53ffa8cc797c1d9e0747455f1..e01a7ce0bf025c4b50802cf314d40f9fc4609232 100644 (file)
             <groupId>org.opendaylight.aaa</groupId>
             <artifactId>aaa-authn-api</artifactId>
         </dependency>
-        <dependency>
-            <groupId>com.sun.jersey</groupId>
-            <artifactId>jersey-server</artifactId>
-            <scope>provided</scope>
-        </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
index eff47e6380a677e0bb6df0fe0d8c2b56aeb1a8b9..fe31fc7999f31df59eed6bdf7e0c8b67a4ff1e3b 100644 (file)
@@ -8,7 +8,7 @@
 
 package org.opendaylight.aaa.basic;
 
-import com.sun.jersey.core.util.Base64;
+import java.util.Base64;
 import java.util.List;
 import java.util.Map;
 import org.opendaylight.aaa.AuthenticationBuilder;
@@ -74,7 +74,7 @@ public class HttpBasicAuth implements TokenAuth {
     }
 
     private static String[] extractCredentialArray(final String authHeader) {
-        return new String(Base64.base64Decode(authHeader.substring(BASIC_PREFIX.length())))
+        return new String(Base64.getDecoder().decode(authHeader.substring(BASIC_PREFIX.length())))
                 .split(AUTH_SEP);
     }
 
index 4ee439df6b43e64cea8142e65abf510c16e02c16..8027806496e028072902e96866c9ac7819749b66 100644 (file)
@@ -13,9 +13,9 @@ import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.sun.jersey.core.util.Base64;
 import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
+import java.util.Base64;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -55,7 +55,7 @@ public class HttpBasicAuthTest {
         String data = USERNAME + ":" + PASSWORD + ":" + DOMAIN;
         Map<String, List<String>> headers = new HashMap<>();
         headers.put("Authorization",
-                Arrays.asList("Basic " + new String(Base64.encode(data.getBytes("utf-8")))));
+                Arrays.asList("Basic " + new String(Base64.getEncoder().encode(data.getBytes("utf-8")))));
         Claim claim = auth.validate(headers);
         assertNotNull(claim);
         assertEquals(USERNAME, claim.user());
@@ -67,7 +67,7 @@ public class HttpBasicAuthTest {
         String data = USERNAME + ":bozo:" + DOMAIN;
         Map<String, List<String>> headers = new HashMap<>();
         headers.put("Authorization",
-                Arrays.asList("Basic " + new String(Base64.encode(data.getBytes("utf-8")))));
+                Arrays.asList("Basic " + new String(Base64.getEncoder().encode(data.getBytes("utf-8")))));
         auth.validate(headers);
     }
 
@@ -76,7 +76,7 @@ public class HttpBasicAuthTest {
         String data = USERNAME + ":bozo";
         Map<String, List<String>> headers = new HashMap<>();
         headers.put("Authorization",
-                Arrays.asList("Basic " + new String(Base64.encode(data.getBytes("utf-8")))));
+                Arrays.asList("Basic " + new String(Base64.getEncoder().encode(data.getBytes("utf-8")))));
         auth.validate(headers);
     }
 
@@ -86,7 +86,7 @@ public class HttpBasicAuthTest {
         String data = USERNAME;
         Map<String, List<String>> headers = new HashMap<>();
         headers.put("Authorization",
-                Arrays.asList("Basic " + new String(Base64.encode(data.getBytes("utf-8")))));
+                Arrays.asList("Basic " + new String(Base64.getEncoder().encode(data.getBytes("utf-8")))));
         auth.validate(headers);
     }
 
@@ -96,7 +96,7 @@ public class HttpBasicAuthTest {
         String data = USERNAME + "$" + PASSWORD;
         Map<String, List<String>> headers = new HashMap<>();
         headers.put("Authorization",
-                Arrays.asList("Basic " + new String(Base64.encode(data.getBytes("utf-8")))));
+                Arrays.asList("Basic " + new String(Base64.getEncoder().encode(data.getBytes("utf-8")))));
         auth.validate(headers);
     }
 }
index 463ea16fb5442ef9e3475e7e0101c68af46eedf1..37d8a844769dc0fab2dd8a939c26dd6ddace83bf 100755 (executable)
@@ -47,10 +47,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
         <groupId>org.bouncycastle</groupId>
         <artifactId>bcprov-jdk15on</artifactId>
     </dependency>
-    <dependency>
-        <groupId>commons-codec</groupId>
-        <artifactId>commons-codec</artifactId>
-    </dependency>
 
     <!-- Testing Dependencies -->
     <dependency>
index 1d878b80121e0e52ca1a0b195e0015ec92a076a6..3a087dc01794eb6515828fd21575db5dfb9a25e6 100644 (file)
@@ -30,9 +30,9 @@ import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
+import java.util.Base64;
 import java.util.Date;
 import javax.xml.bind.DatatypeConverter;
-import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.lang3.StringUtils;
 import org.bouncycastle.asn1.x509.X509Name;
 import org.bouncycastle.jce.PKCS10CertificationRequest;
@@ -294,7 +294,7 @@ public class ODLKeyTool {
             final int sIdx = certificate.indexOf(KeyStoreConstant.END_CERTIFICATE);
             certificate = certificate.substring(fIdx, sIdx);
         }
-        final byte[] byteCert = Base64.decodeBase64(certificate);
+        final byte[] byteCert = Base64.getDecoder().decode(certificate);
         final InputStream inputStreamCert = new ByteArrayInputStream(byteCert);
         CertificateFactory certFactory;
         try {