Search in sources :

Example 11 with AccessToken

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;
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken)

Example 12 with 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;
}
Also used : ClientDetails(io.github.tesla.authz.domain.ClientDetails) AccessToken(io.github.tesla.authz.domain.AccessToken)

Example 13 with AccessToken

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;
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken)

Example 14 with 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;
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken)

Aggregations

AccessToken (io.github.tesla.authz.domain.AccessToken)14 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)4 ClientDetails (io.github.tesla.authz.domain.ClientDetails)1 OauthCode (io.github.tesla.authz.domain.OauthCode)1 Query (io.github.tesla.ops.utils.Query)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1