use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.
the class OauthService method retrieveClientCredentialsAccessToken.
public AccessToken retrieveClientCredentialsAccessToken(ClientDetails clientDetails, Set<String> scopes) throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String clientId = clientDetails.getClientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, clientId, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, clientId, authenticationId);
boolean needCreate = false;
if (accessToken == null) {
needCreate = true;
LOG.debug("Not found AccessToken from repository, will create a new one, client_id: {}", clientId);
} else if (accessToken.tokenExpired()) {
LOG.debug("Delete expired AccessToken: {} and create a new one, client_id: {}", accessToken, clientId);
oauthRepository.deleteAccessToken(accessToken);
needCreate = true;
} else {
LOG.debug("Use existed AccessToken: {}, client_id: {}", accessToken, clientId);
}
if (needCreate) {
accessToken = createAndSaveAccessToken(clientDetails, false, clientId, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
}
return accessToken;
}
use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.
the class OauthService method changeAccessTokenByRefreshToken.
public AccessToken changeAccessTokenByRefreshToken(String refreshToken, String clientId) throws OAuthSystemException {
final AccessToken oldToken = loadAccessTokenByRefreshToken(refreshToken, clientId);
AccessToken newAccessToken = oldToken.cloneMe();
LOG.debug("Create new AccessToken: {} from old AccessToken: {}", newAccessToken, oldToken);
ClientDetails details = oauthRepository.findClientDetails(clientId);
newAccessToken.updateByClientDetails(details);
final String authId = authenticationIdGenerator.generate(clientId, oldToken.username(), null);
newAccessToken.authenticationId(authId).tokenId(oAuthIssuer.accessToken()).refreshToken(oAuthIssuer.refreshToken());
oauthRepository.deleteAccessToken(oldToken);
LOG.debug("Delete old AccessToken: {}", oldToken);
oauthRepository.saveAccessToken(newAccessToken);
LOG.debug("Save new AccessToken: {}", newAccessToken);
return newAccessToken;
}
use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.
the class OauthService method createAndSaveAccessToken.
private AccessToken createAndSaveAccessToken(ClientDetails clientDetails, boolean includeRefreshToken, String username, String authenticationId) throws OAuthSystemException {
AccessToken accessToken = new AccessToken().clientId(clientDetails.getClientId()).username(username).tokenId(oAuthIssuer.accessToken()).authenticationId(authenticationId).updateByClientDetails(clientDetails);
if (includeRefreshToken) {
accessToken.refreshToken(oAuthIssuer.refreshToken());
}
this.oauthRepository.saveAccessToken(accessToken);
LOG.debug("Save AccessToken: {}", accessToken);
return accessToken;
}
use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.
the class OauthService method retrieveNewAccessToken.
public AccessToken retrieveNewAccessToken(ClientDetails clientDetails, Set<String> scopes) throws OAuthSystemException {
String scope = OAuthUtils.encodeScopes(scopes);
final String username = currentUsername();
final String clientId = clientDetails.getClientId();
final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
if (accessToken != null) {
LOG.debug("Delete existed AccessToken: {}", accessToken);
oauthRepository.deleteAccessToken(accessToken);
}
accessToken = createAndSaveAccessToken(clientDetails, false, username, authenticationId);
LOG.debug("Create a new AccessToken: {}", accessToken);
return accessToken;
}
Aggregations