I have sping-boot application with rest services written using Spring web flux.
For now I access minio using login/password authorizaton and it works fine.
For now I want to exchange application JWT token with STS minio token and I implemented method to test:
@PostMapping
public boolean test(JwtAuthenticationToken token) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
MinioClient minioClient =
MinioClient.builder()
.region(...)
.endpoint(...)
.credentialsProvider(new WebIdentityProvider(
() -> new Jwt(token.getToken().getTokenValue(), 1000),
String.valueOf(...),
null,
null,
null,
null,
null))
.build();
return minioClient.bucketExists("mybucket").build());
}
This code successfully works and returns true
because mybucket
actually exists.
But it is only test and I need to move minioClient
to the configuration. The issue here that I have to have credentials provider there.
So I've created folowing configuration:
@Bean
public MinioClient minioClient() {
return MinioClient.builder()
.region(...)
.endpoint(...)
.credentialsProvider(new WebIdentityProvider(
() -> {
String block = null;
try {
block = ReactiveSecurityContextHolder
.getContext()
.map(context -> {
return context
.getAuthentication()
.getPrincipal();
}
)
.cast(Jwt.class)
.map(Jwt::token)
.block();
} catch (Exception e) {
// it fails here <=======
System.out.println(e);
}
Jwt jwt = new Jwt(String.valueOf(block),
1000);
return jwt; },
String.valueOf(...),
null,
null,
null,
null,
null))
.build();
}
But unfortunately method block()
fails with exception:
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-6
Any ideas how to fix it?
P.S. _
I tried
.toFuture()
.get();
instead of .block();
but it returns null
public boolean test(JwtAuthenticationToken token)
is not null and I expected to have the same jwt token in ReactiveSecurityContextHolder – BackwoodsmanblockingWrapper.block()
throw exception ? – Backwoodsman