I am developing a microservice that is responsible for starting other microservices running on CloudFoundry. Therefore I make use of the cf-java-client (https://github.com/cloudfoundry/cf-java-client). In our environment we have a special mechanism for authenticating machine users on CloudFoundry: I have to give a client id and secret to a certain endpoint, that returns an authorization code. With this code I can create temporary credentials for CloudFoundry (which live only 60 min). So far I implemented this behaviour the following:
@Bean
PasswordGrantTokenProvider tokenProvider() {
final Map<String, String> temporaryCredentialsMap =
getTemporaryCredentials(clientId, clientSecret);
return PasswordGrantTokenProvider.builder()
.username(temporaryCredentialsMap.get("username"))
.password(temporaryCredentialsMap.get("password"))
.build();
}
My problem is now that, when the credentials expire, I get a HTTP 401 bad credentials. I was thinking of recreating the bean above. Is this possible? Or any other ideas?
I solved this by changing the scope of all cf related beans to prototype scopes and requesting a new bean from the context to refresh credentials.