File tree Expand file tree Collapse file tree 2 files changed +44
-3
lines changed
modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/auth
samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth Expand file tree Collapse file tree 2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change 1+ package { {invokerPackage} }.auth;
2+
3+ import { {invokerPackage} }.Pair;
4+
5+ import com.migcomponents.migbase64.Base64;
6+
7+ import java.util.Map;
8+ import java.util.List;
9+
10+ import java.io.UnsupportedEncodingException;
11+
12+ public class HttpBasicAuth implements Authentication {
13+ private String username;
14+ private String password;
15+
16+ public String getUsername() {
17+ return username;
18+ }
19+
20+ public void setUsername(String username) {
21+ this.username = username;
22+ }
23+
24+ public String getPassword() {
25+ return password;
26+ }
27+
28+ public void setPassword(String password) {
29+ this.password = password;
30+ }
31+
32+ @Override
33+ public void applyToParams(List<Pair > queryParams, Map<String , String > headerParams) {
34+ String str = (username == null ? " " : username) + " :" + (password == null ? " " : password);
35+ try {
36+ headerParams.put(" Authorization" , " Basic " + Base64.encodeToString(str.getBytes(" UTF-8" ), false ));
37+ } catch (UnsupportedEncodingException e) {
38+ throw new RuntimeException(e);
39+ }
40+ }
41+ }
Original file line number Diff line number Diff line change 22
33import io .swagger .client .Pair ;
44
5+ import com .migcomponents .migbase64 .Base64 ;
6+
57import java .util .Map ;
68import java .util .List ;
79
810import java .io .UnsupportedEncodingException ;
9- import javax .xml .bind .DatatypeConverter ;
1011
11- @ javax .annotation .Generated (value = "class io.swagger.codegen.languages.JavaClientCodegen" , date = "2015-08-31T19:27:38.337+08:00" )
1212public class HttpBasicAuth implements Authentication {
1313 private String username ;
1414 private String password ;
@@ -33,7 +33,7 @@ public void setPassword(String password) {
3333 public void applyToParams (List <Pair > queryParams , Map <String , String > headerParams ) {
3434 String str = (username == null ? "" : username ) + ":" + (password == null ? "" : password );
3535 try {
36- headerParams .put ("Authorization" , "Basic " + DatatypeConverter . printBase64Binary (str .getBytes ("UTF-8" )));
36+ headerParams .put ("Authorization" , "Basic " + Base64 . encodeToString (str .getBytes ("UTF-8" ), false ));
3737 } catch (UnsupportedEncodingException e ) {
3838 throw new RuntimeException (e );
3939 }
You can’t perform that action at this time.
0 commit comments