Skip to content

Commit 145e771

Browse files
author
Alexander Furer
committed
fix : thread safe token supplier
1 parent 641e386 commit 145e771

File tree

1 file changed

+3
-5
lines changed
  • grpc-client-spring-boot-starter/src/main/java/org/lognet/springboot/grpc/security

1 file changed

+3
-5
lines changed

grpc-client-spring-boot-starter/src/main/java/org/lognet/springboot/grpc/security/AuthHeader.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ public AuthHeader.AuthHeaderBuilder basic(String userName, byte[] password) {
2828
.put(password);
2929
buffer.rewind();
3030
ByteBuffer token = Base64.getEncoder().encode(buffer);
31+
token.rewind();
3132
return authScheme(Constants.BASIC_AUTH_SCHEME)
32-
.tokenSupplier(() -> {
33-
token.rewind();
34-
return token;
35-
});
33+
.tokenSupplier( token::duplicate);
3634
}
3735

3836

@@ -41,7 +39,7 @@ public Metadata attach(Metadata metadataHeader){
4139
ByteBuffer token = tokenSupplier.get();
4240
final byte[] header = ByteBuffer.allocate(authScheme.length() + token.remaining() + 1)
4341
.put(authScheme.getBytes())
44-
.put((byte) ' ')
42+
.put((byte)' ')
4543
.put(token)
4644
.array();
4745
metadataHeader.put(Constants.AUTH_HEADER_KEY,header);

0 commit comments

Comments
 (0)