Search in sources :

Example 1 with AccessToken

use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.

the class AuthorizationCodeTokenHandler method responseToken.

private void responseToken() throws OAuthSystemException {
    AccessToken accessToken = oauthService.retrieveAuthorizationCodeAccessToken(clientDetails(), tokenRequest.getCode());
    final OAuthResponse tokenResponse = createTokenResponse(accessToken, false);
    LOG.debug("'authorization_code' response: {}", tokenResponse);
    WebUtils.writeOAuthJsonResponse(response, tokenResponse);
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse)

Example 2 with AccessToken

use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.

the class RefreshTokenHandler method handleAfterValidation.

@Override
public void handleAfterValidation() throws OAuthProblemException, OAuthSystemException {
    final String refreshToken = tokenRequest.getRefreshToken();
    AccessToken accessToken = oauthService.changeAccessTokenByRefreshToken(refreshToken, tokenRequest.getClientId());
    final OAuthResponse tokenResponse = createTokenResponse(accessToken, false);
    LOG.debug("'refresh_token' response: {}", tokenResponse);
    WebUtils.writeOAuthJsonResponse(response, tokenResponse);
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse)

Example 3 with AccessToken

use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.

the class RefreshTokenClientDetailsValidator method validateSelf.

@Override
protected OAuthResponse validateSelf(ClientDetails clientDetails) throws OAuthSystemException {
    final String grantType = grantType();
    if (!clientDetails.grantTypes().contains(grantType)) {
        LOG.debug("Invalid grant_type '{}', client_id = '{}'", grantType, clientDetails.getClientId());
        return invalidGrantTypeResponse(grantType);
    }
    final String clientSecret = oauthRequest.getClientSecret();
    if (clientSecret == null || !clientSecret.equals(clientDetails.getClientSecret())) {
        LOG.debug("Invalid client_secret '{}', client_id = '{}'", clientSecret, clientDetails.getClientId());
        return invalidClientSecretResponse();
    }
    final String refreshToken = tokenRequest.getRefreshToken();
    AccessToken accessToken = oauthService.loadAccessTokenByRefreshToken(refreshToken, oauthRequest.getClientId());
    if (accessToken == null || accessToken.refreshTokenExpired()) {
        LOG.debug("Invalid refresh_token: '{}'", refreshToken);
        return invalidRefreshTokenResponse(refreshToken);
    }
    return null;
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken)

Example 4 with AccessToken

use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.

the class OauthService method retrieveAuthorizationCodeAccessToken.

public AccessToken retrieveAuthorizationCodeAccessToken(ClientDetails clientDetails, String code) throws OAuthSystemException {
    final OauthCode oauthCode = loadOauthCode(code, clientDetails);
    final String username = oauthCode.username();
    final String clientId = clientDetails.getClientId();
    final String authenticationId = authenticationIdGenerator.generate(clientId, username, null);
    AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, authenticationId);
    if (accessToken != null) {
        LOG.debug("Delete existed AccessToken: {}", accessToken);
        oauthRepository.deleteAccessToken(accessToken);
    }
    accessToken = createAndSaveAccessToken(clientDetails, clientDetails.supportRefreshToken(), username, authenticationId);
    LOG.debug("Create a new AccessToken: {}", accessToken);
    return accessToken;
}
Also used : OauthCode(io.github.tesla.authz.domain.OauthCode) AccessToken(io.github.tesla.authz.domain.AccessToken)

Example 5 with AccessToken

use of io.github.tesla.authz.domain.AccessToken in project tesla by linking12.

the class OauthService method retrieveAccessToken.

public AccessToken retrieveAccessToken(ClientDetails clientDetails, Set<String> scopes, boolean includeRefreshToken) 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) {
        accessToken = createAndSaveAccessToken(clientDetails, includeRefreshToken, 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