Search in sources :

Example 6 with AccessToken

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

the class Oauth2Controller method listTokens.

@ResponseBody
@GetMapping("/listToken")
@RequiresPermissions("sys:oauth2:listToken")
PageDO<AccessToken> listTokens(@RequestParam Map<String, Object> params) {
    Query query = new Query(params);
    PageDO<AccessToken> page = oauth2Service.queryTokenList(query);
    return page;
}
Also used : Query(io.github.tesla.ops.utils.Query) AccessToken(io.github.tesla.authz.domain.AccessToken) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with AccessToken

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

the class TokenAuthorizeHandler method forceTokenResponse.

private void forceTokenResponse() throws OAuthSystemException {
    AccessToken accessToken = oauthService.retrieveNewAccessToken(clientDetails(), oauthRequest.getScopes());
    normalTokenResponse(accessToken);
}
Also used : AccessToken(io.github.tesla.authz.domain.AccessToken)

Example 8 with AccessToken

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

the class ClientCredentialsTokenHandler method handleAfterValidation.

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

Example 9 with AccessToken

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

the class PasswordTokenHandler method handleAfterValidation.

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

Example 10 with AccessToken

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

the class OauthService method retrievePasswordAccessToken.

public AccessToken retrievePasswordAccessToken(ClientDetails clientDetails, Set<String> scopes, String username) throws OAuthSystemException {
    String scope = OAuthUtils.encodeScopes(scopes);
    final String clientId = clientDetails.getClientId();
    final String authenticationId = authenticationIdGenerator.generate(clientId, username, scope);
    AccessToken accessToken = oauthRepository.findAccessToken(clientId, username, 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, clientDetails.supportRefreshToken(), 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