Skip to content

Commit

Permalink
fix : thread safe token supplier
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Furer committed Oct 15, 2020
1 parent 641e386 commit 145e771
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ public AuthHeader.AuthHeaderBuilder basic(String userName, byte[] password) {
.put(password);
buffer.rewind();
ByteBuffer token = Base64.getEncoder().encode(buffer);
token.rewind();
return authScheme(Constants.BASIC_AUTH_SCHEME)
.tokenSupplier(() -> {
token.rewind();
return token;
});
.tokenSupplier( token::duplicate);
}


Expand All @@ -41,7 +39,7 @@ public Metadata attach(Metadata metadataHeader){
ByteBuffer token = tokenSupplier.get();
final byte[] header = ByteBuffer.allocate(authScheme.length() + token.remaining() + 1)
.put(authScheme.getBytes())
.put((byte) ' ')
.put((byte)' ')
.put(token)
.array();
metadataHeader.put(Constants.AUTH_HEADER_KEY,header);
Expand Down

0 comments on commit 145e771

Please sign in to comment.