Search in sources :

Example 1 with RevokedAccessTokenException

use of com.thoughtworks.go.server.exceptions.RevokedAccessTokenException in project gocd by gocd.

the class AccessTokenService method findByAccessToken.

public AccessToken findByAccessToken(String actualToken) {
    if (actualToken.length() != 40) {
        throw new InvalidAccessTokenException();
    }
    String saltId = StringUtils.substring(actualToken, 0, 8);
    AccessToken token = accessTokenDao.findAccessTokenBySaltId(saltId);
    if (token == null) {
        throw new InvalidAccessTokenException();
    }
    boolean isValid = token.isValidToken(actualToken);
    if (!isValid) {
        throw new InvalidAccessTokenException();
    }
    if (token.isRevoked()) {
        throw new RevokedAccessTokenException(token.getRevokedAt());
    }
    return token;
}
Also used : InvalidAccessTokenException(com.thoughtworks.go.server.exceptions.InvalidAccessTokenException) AccessToken(com.thoughtworks.go.domain.AccessToken) RevokedAccessTokenException(com.thoughtworks.go.server.exceptions.RevokedAccessTokenException)

Example 2 with RevokedAccessTokenException

use of com.thoughtworks.go.server.exceptions.RevokedAccessTokenException in project gocd by gocd.

the class AccessTokenServiceIntegrationTest method shouldNotGetAccessTokenProvidedTokenValueWhenTokenIsRevoked.

@Test
public void shouldNotGetAccessTokenProvidedTokenValueWhenTokenIsRevoked() {
    String tokenDescription = "This is my first Token";
    AccessToken.AccessTokenWithDisplayValue createdToken = accessTokenService.create(tokenDescription, "bob", authConfigId);
    accessTokenService.revokeAccessToken(createdToken.getId(), "BOB", null);
    String accessTokenInString = createdToken.getDisplayValue();
    RevokedAccessTokenException exception = assertThrows(RevokedAccessTokenException.class, () -> accessTokenService.findByAccessToken(accessTokenInString));
    assertThat(exception.getMessage()).startsWith("Invalid Personal Access Token. Access token was revoked at: ");
}
Also used : AccessToken(com.thoughtworks.go.domain.AccessToken) RevokedAccessTokenException(com.thoughtworks.go.server.exceptions.RevokedAccessTokenException) Test(org.junit.jupiter.api.Test)

Aggregations

AccessToken (com.thoughtworks.go.domain.AccessToken)2 RevokedAccessTokenException (com.thoughtworks.go.server.exceptions.RevokedAccessTokenException)2 InvalidAccessTokenException (com.thoughtworks.go.server.exceptions.InvalidAccessTokenException)1 Test (org.junit.jupiter.api.Test)1