this.jiveInstanceHolder = jiveInstanceHolder;
}
@Override
public String getAccessToken() throws JiveInstanceNotFoundException, OAuthCodeNotFoundException {
JiveInstance jiveInstance = null;
try {
jiveInstance = jiveInstanceHolder.getJiveInstance();
if (jiveInstance == null) throw new JiveInstanceNotFoundException();
} catch (Exception e) {
logger.error("An error occurred getting access token", e);
if (e instanceof JiveInstanceNotFoundException) throw (JiveInstanceNotFoundException)e;
throw new JiveInstanceNotFoundException(e);
}
if (jiveInstance.getCredentials() == null || !StringUtils.hasText(jiveInstance.getCredentials().getAccessToken())) {
// we don't have credentials yet, we need to request them using the code
if (!StringUtils.hasText(jiveInstance.getCode())) throw new OAuthCodeNotFoundException();
exchangeCodeForTokens(jiveInstance);
}
if (jiveInstance.getCredentials().isAccessTokenExpired()) {
updateAccessToken(jiveInstance);
}
return jiveInstance.getCredentials().getAccessToken();
}