简体   繁体   中英

Problems implementing TokenProvider for CloudFoundry Java CLI

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM