+ String user;
+ String password;
+ String token;
+ Date expiration;
+ Cloudify cloudify = null;
+
+ public CloudifyClientTokenProvider(String cloudifyEndpoint, String user, String password) {
+ this.user = user;
+ this.password = password;
+
+ cloudify = new Cloudify(cloudifyEndpoint);
+ }
+
+ @Override
+ public String getToken() {
+ Date now = new Date();
+ if (token != null && expiration != null && expiration.after(now)) {
+ return token;
+ }
+
+ // Create a "Get Token" request. Force basic authentication to acquire the token itself.
+ GetToken tokenRequest = cloudify.tokens().token();
+ tokenRequest.setBasicAuthentication(user, password);
+ Token newToken = tokenRequest.execute();