use of gov.ca.cwds.data.reissue.model.PerryTokenEntity in project perry by ca-cwds.
the class TokenService method issueAccessCode.
public String issueAccessCode(UniversalUserToken userToken, OAuth2AccessToken accessToken) {
String accessCode = generator.generate();
PerryTokenEntity perryTokenEntity = new PerryTokenEntity();
perryTokenEntity.setUser(userToken.getUserId());
perryTokenEntity.setAccessCode(accessCode);
perryTokenEntity.writeAccessToken(accessToken);
perryTokenEntity.setToken(userToken.getToken());
deleteExpiredRecords();
tokenRepository.save(perryTokenEntity);
return accessCode;
}
use of gov.ca.cwds.data.reissue.model.PerryTokenEntity 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();
}
use of gov.ca.cwds.data.reissue.model.PerryTokenEntity in project perry by ca-cwds.
the class TokenServiceTest method testLoginFlow.
@Test
public void testLoginFlow() {
String accessCode = issueAccessCode();
assert accessCode != null;
PerryTokenEntity perryTokenEntity = tokenRepository.findOne(PERRY_TOKEN);
assert perryTokenEntity != null;
assert perryTokenEntity.readAccessToken().getValue().equals(ACCESS_TOKEN);
assert perryTokenEntity.getCreatedDate() != null;
assert perryTokenEntity.getAccessCode().equals(accessCode);
assert perryTokenEntity.getToken().equals(PERRY_TOKEN);
String perryToken = tokenService.getPerryTokenByAccessCode(accessCode);
assert perryToken != null;
assert perryToken.equals(PERRY_TOKEN);
perryTokenEntity = tokenRepository.findOne(PERRY_TOKEN);
assert perryTokenEntity.getAccessCode() == null;
}
Aggregations