use of gov.ca.cwds.rest.api.domain.PerryException in project perry by ca-cwds.
the class LoginServiceImpl method invalidate.
@Override
public void invalidate(String perryToken) {
OAuth2AccessToken accessToken = tokenService.deleteToken(perryToken);
try {
HttpHeaders headers = new HttpHeaders();
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("token", accessToken.getValue());
params.add("token_type_hint", "access_token");
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
restClientService.clientRestTemplate().postForEntity(revokeTokenUri, request, String.class).getBody();
} catch (Exception e) {
throw new PerryException("Token Revocation problem for revokeTokenUri = " + revokeTokenUri, e);
}
}
use of gov.ca.cwds.rest.api.domain.PerryException in project perry by ca-cwds.
the class TokenService method getPerryTokenByAccessCode.
public String getPerryTokenByAccessCode(String accessCode) {
List<PerryTokenEntity> tokens = tokenRepository.findByAccessCode(accessCode);
if (tokens.isEmpty()) {
throw new PerryException("Access Code: " + accessCode + " is not found");
}
if (tokens.size() > 1) {
tokenRepository.delete(tokens);
throw new PerryException("Access Code: " + accessCode + " is not unique");
}
PerryTokenEntity perryTokenEntity = tokens.get(0);
if (new Date().after(DateUtils.addMinutes(perryTokenEntity.getCreatedDate(), properties.getJwt().getTimeout()))) {
tokenRepository.delete(perryTokenEntity);
throw new PerryException("Access Code: " + accessCode + " is expired");
}
perryTokenEntity.setAccessCode(null);
return perryTokenEntity.getToken();
}
Aggregations