From b823e8bd35d236e04d6f4e69a19422ec75c44c06 Mon Sep 17 00:00:00 2001 From: xhh Date: Fri, 20 Nov 2015 17:34:46 +0800 Subject: [PATCH 1/3] Ignore auths when value not specified in Java clients --- .../src/main/resources/Java/auth/ApiKeyAuth.mustache | 3 +++ .../src/main/resources/Java/auth/HttpBasicAuth.mustache | 3 +++ .../Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache | 3 +++ .../src/main/java/io/swagger/client/auth/ApiKeyAuth.java | 5 ++++- .../src/main/java/io/swagger/client/auth/HttpBasicAuth.java | 5 ++++- .../src/main/java/io/swagger/client/auth/ApiKeyAuth.java | 5 ++++- .../src/main/java/io/swagger/client/auth/HttpBasicAuth.java | 5 ++++- .../src/main/java/io/swagger/client/auth/ApiKeyAuth.java | 5 ++++- .../src/main/java/io/swagger/client/auth/HttpBasicAuth.java | 3 +++ 9 files changed, 32 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache index 04be481229..931d17b0d0 100644 --- a/modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache @@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (apiKey == null) { + return; + } String value; if (apiKeyPrefix != null) { value = apiKeyPrefix + " " + apiKey; diff --git a/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache index 63813e2504..509f4742b6 100644 --- a/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache @@ -31,6 +31,9 @@ public class HttpBasicAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (username == null && password == null) { + return; + } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8"))); diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache index 5b4070fcaf..76fa4a2d0a 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache @@ -31,6 +31,9 @@ public class HttpBasicAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (username == null && password == null) { + return; + } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false)); diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index 14891e3504..0011210c8c 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-30T16:36:47.681+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:23.285+08:00") public class ApiKeyAuth implements Authentication { private final String location; private final String paramName; @@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (apiKey == null) { + return; + } String value; if (apiKeyPrefix != null) { value = apiKeyPrefix + " " + apiKey; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 99ff90e4c6..074f183354 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -8,7 +8,7 @@ import java.util.List; import java.io.UnsupportedEncodingException; import javax.xml.bind.DatatypeConverter; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-30T16:36:47.681+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:23.285+08:00") public class HttpBasicAuth implements Authentication { private String username; private String password; @@ -31,6 +31,9 @@ public class HttpBasicAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (username == null && password == null) { + return; + } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8"))); diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index d7d3d3e63b..bc3bdaefc4 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-17T11:17:50.535-05:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:47.318+08:00") public class ApiKeyAuth implements Authentication { private final String location; private final String paramName; @@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (apiKey == null) { + return; + } String value; if (apiKeyPrefix != null) { value = apiKeyPrefix + " " + apiKey; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 390502ab9e..0abfc056e1 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -8,7 +8,7 @@ import java.util.List; import java.io.UnsupportedEncodingException; import javax.xml.bind.DatatypeConverter; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-17T11:17:50.535-05:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:47.318+08:00") public class HttpBasicAuth implements Authentication { private String username; private String password; @@ -31,6 +31,9 @@ public class HttpBasicAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (username == null && password == null) { + return; + } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8"))); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index c072321f45..fbfda66f88 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -5,7 +5,7 @@ import io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-10-20T11:42:25.339-07:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:54.086+08:00") public class ApiKeyAuth implements Authentication { private final String location; private final String paramName; @@ -44,6 +44,9 @@ public class ApiKeyAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (apiKey == null) { + return; + } String value; if (apiKeyPrefix != null) { value = apiKeyPrefix + " " + apiKey; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index d2b5643316..38617121e3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -31,6 +31,9 @@ public class HttpBasicAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { + if (username == null && password == null) { + return; + } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false)); From 81cf57a00b2f279d8610090f28fb51e119f9a3e3 Mon Sep 17 00:00:00 2001 From: xhh Date: Fri, 20 Nov 2015 20:10:05 +0800 Subject: [PATCH 2/3] Use okhttp's Credentials class to build basic auth string --- .../okhttp-gson/auth/HttpBasicAuth.mustache | 11 +++---- .../Java/libraries/okhttp-gson/pom.mustache | 5 --- .../client/petstore/java/okhttp-gson/pom.xml | 5 --- .../io/swagger/client/auth/HttpBasicAuth.java | 11 +++---- .../swagger/client/auth/ApiKeyAuthTest.java | 31 ++++++++++++++++++- .../client/auth/HttpBasicAuthTest.java | 10 ++++++ 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache index 76fa4a2d0a..f3ed85d980 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth/HttpBasicAuth.mustache @@ -2,7 +2,7 @@ package {{invokerPackage}}.auth; import {{invokerPackage}}.Pair; -import com.migcomponents.migbase64.Base64; +import com.squareup.okhttp.Credentials; import java.util.Map; import java.util.List; @@ -34,11 +34,8 @@ public class HttpBasicAuth implements Authentication { if (username == null && password == null) { return; } - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); - try { - headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false)); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + headerParams.put("Authorization", Credentials.basic( + username == null ? "" : username, + password == null ? "" : password)); } } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache index 67fc10e832..0d7e901510 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/pom.mustache @@ -122,11 +122,6 @@ gson ${gson-version} - - com.brsanthu - migbase64 - 2.2 - diff --git a/samples/client/petstore/java/okhttp-gson/pom.xml b/samples/client/petstore/java/okhttp-gson/pom.xml index 2442e1c318..9fa057be93 100644 --- a/samples/client/petstore/java/okhttp-gson/pom.xml +++ b/samples/client/petstore/java/okhttp-gson/pom.xml @@ -122,11 +122,6 @@ gson ${gson-version} - - com.brsanthu - migbase64 - 2.2 - diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 38617121e3..6ed16d1db3 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -2,7 +2,7 @@ package io.swagger.client.auth; import io.swagger.client.Pair; -import com.migcomponents.migbase64.Base64; +import com.squareup.okhttp.Credentials; import java.util.Map; import java.util.List; @@ -34,11 +34,8 @@ public class HttpBasicAuth implements Authentication { if (username == null && password == null) { return; } - String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); - try { - headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false)); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + headerParams.put("Authorization", Credentials.basic( + username == null ? "" : username, + password == null ? "" : password)); } } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/auth/ApiKeyAuthTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/auth/ApiKeyAuthTest.java index 5bdb4fb78f..3715e9724e 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/auth/ApiKeyAuthTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/auth/ApiKeyAuthTest.java @@ -29,9 +29,23 @@ public class ApiKeyAuthTest { assertEquals(0, headerParams.size()); } + @Test + public void testApplyToParamsInQueryWithNullValue() { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + + ApiKeyAuth auth = new ApiKeyAuth("query", "api_key"); + auth.setApiKey(null); + auth.applyToParams(queryParams, headerParams); + + // no changes to parameters + assertEquals(0, queryParams.size()); + assertEquals(0, headerParams.size()); + } + @Test public void testApplyToParamsInHeaderWithPrefix() { - List queryParams = new ArrayList(); + List queryParams = new ArrayList(); Map headerParams = new HashMap(); ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN"); @@ -44,4 +58,19 @@ public class ApiKeyAuthTest { assertEquals(1, headerParams.size()); assertEquals("Token my-api-token", headerParams.get("X-API-TOKEN")); } + + @Test + public void testApplyToParamsInHeaderWithNullValue() { + List queryParams = new ArrayList(); + Map headerParams = new HashMap(); + + ApiKeyAuth auth = new ApiKeyAuth("header", "X-API-TOKEN"); + auth.setApiKey(null); + auth.setApiKeyPrefix("Token"); + auth.applyToParams(queryParams, headerParams); + + // no changes to parameters + assertEquals(0, queryParams.size()); + assertEquals(0, headerParams.size()); + } } diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/auth/HttpBasicAuthTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/auth/HttpBasicAuthTest.java index 52c5497ba8..ddee04f57f 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/auth/HttpBasicAuthTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/client/auth/HttpBasicAuthTest.java @@ -48,5 +48,15 @@ public class HttpBasicAuthTest { // the string below is base64-encoded result of "my-username:" with the "Basic " prefix expected = "Basic bXktdXNlcm5hbWU6"; assertEquals(expected, headerParams.get("Authorization")); + + // null username and password should be ignored + queryParams = new ArrayList(); + headerParams = new HashMap(); + auth.setUsername(null); + auth.setPassword(null); + auth.applyToParams(queryParams, headerParams); + // no changes to parameters + assertEquals(0, queryParams.size()); + assertEquals(0, headerParams.size()); } } From 4f831e032cfb90e37362618c62639a642b550e85 Mon Sep 17 00:00:00 2001 From: xhh Date: Sun, 22 Nov 2015 16:27:14 +0800 Subject: [PATCH 3/3] Use separate library to do base64 encoding in Java default and jersey2 clients to make it work in both JVM and Android --- .../src/main/resources/Java/auth/HttpBasicAuth.mustache | 5 +++-- .../src/main/resources/Java/libraries/jersey2/pom.mustache | 7 +++++++ .../swagger-codegen/src/main/resources/Java/pom.mustache | 7 +++++++ samples/client/petstore/java/default/pom.xml | 7 +++++++ .../main/java/io/swagger/client/auth/HttpBasicAuth.java | 7 ++++--- samples/client/petstore/java/jersey2/pom.xml | 7 +++++++ .../main/java/io/swagger/client/auth/HttpBasicAuth.java | 7 ++++--- 7 files changed, 39 insertions(+), 8 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache index 509f4742b6..febabe33d6 100644 --- a/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache @@ -2,11 +2,12 @@ package {{invokerPackage}}.auth; import {{invokerPackage}}.Pair; +import com.migcomponents.migbase64.Base64; + import java.util.Map; import java.util.List; import java.io.UnsupportedEncodingException; -import javax.xml.bind.DatatypeConverter; {{>generatedAnnotation}} public class HttpBasicAuth implements Authentication { @@ -36,7 +37,7 @@ public class HttpBasicAuth implements Authentication { } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { - headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8"))); + headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache index c8d2145bc6..dbe0138aa5 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/pom.mustache @@ -152,6 +152,13 @@ ${jodatime-version} + + + com.brsanthu + migbase64 + 2.2 + + junit diff --git a/modules/swagger-codegen/src/main/resources/Java/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/pom.mustache index 3f4d9d9a55..c5bfbc65b7 100644 --- a/modules/swagger-codegen/src/main/resources/Java/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/pom.mustache @@ -148,6 +148,13 @@ ${jodatime-version} + + + com.brsanthu + migbase64 + 2.2 + + junit diff --git a/samples/client/petstore/java/default/pom.xml b/samples/client/petstore/java/default/pom.xml index 894e318b5f..8a939b9dc3 100644 --- a/samples/client/petstore/java/default/pom.xml +++ b/samples/client/petstore/java/default/pom.xml @@ -148,6 +148,13 @@ ${jodatime-version} + + + com.brsanthu + migbase64 + 2.2 + + junit diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 074f183354..8c2aa44467 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -2,13 +2,14 @@ package io.swagger.client.auth; import io.swagger.client.Pair; +import com.migcomponents.migbase64.Base64; + import java.util.Map; import java.util.List; import java.io.UnsupportedEncodingException; -import javax.xml.bind.DatatypeConverter; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:23.285+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-22T13:15:32.345+08:00") public class HttpBasicAuth implements Authentication { private String username; private String password; @@ -36,7 +37,7 @@ public class HttpBasicAuth implements Authentication { } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { - headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8"))); + headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } diff --git a/samples/client/petstore/java/jersey2/pom.xml b/samples/client/petstore/java/jersey2/pom.xml index e5353a66ea..0881cc2937 100644 --- a/samples/client/petstore/java/jersey2/pom.xml +++ b/samples/client/petstore/java/jersey2/pom.xml @@ -152,6 +152,13 @@ ${jodatime-version} + + + com.brsanthu + migbase64 + 2.2 + + junit diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 0abfc056e1..071139d656 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -2,13 +2,14 @@ package io.swagger.client.auth; import io.swagger.client.Pair; +import com.migcomponents.migbase64.Base64; + import java.util.Map; import java.util.List; import java.io.UnsupportedEncodingException; -import javax.xml.bind.DatatypeConverter; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-20T17:28:47.318+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-22T13:15:27.225+08:00") public class HttpBasicAuth implements Authentication { private String username; private String password; @@ -36,7 +37,7 @@ public class HttpBasicAuth implements Authentication { } String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); try { - headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8"))); + headerParams.put("Authorization", "Basic " + Base64.encodeToString(str.getBytes("UTF-8"), false)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); }