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;
}
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: ");
}
Aggregations