use of org.springframework.security.jwt.crypto.sign.SignerVerifier in project CzechIdMng by bcvsolutions.
the class JwtAuthenticationMapper method readToken.
/**
* Reads {@link IdmJwtAuthentication} from given token
*
* @param token
* @return
* @throws IOException
*/
public IdmJwtAuthentication readToken(String token) throws IOException {
if (StringUtils.isEmpty(token)) {
return null;
}
//
SignerVerifier verifier = getVerifier();
String decoded = JwtHelper.decodeAndVerify(token, verifier).getClaims();
return fromDto(mapper.readValue(decoded, IdmJwtAuthenticationDto.class));
}
use of org.springframework.security.jwt.crypto.sign.SignerVerifier in project theskeleton by codenergic.
the class TokenStoreServiceImpl method findAndVerifyToken.
@Override
public TokenStoreRestData findAndVerifyToken(String token) {
try {
Jwt jwt = JwtHelper.decode(token);
TokenStoreRestData data = objectMapper.readValue(jwt.getClaims(), TokenStoreRestData.class);
UserEntity user = userRepository.findById(data.getUserId()).orElseThrow(() -> new UsernameNotFoundException(data.getUserId()));
SignerVerifier verifier = createSignerVerifier(user);
jwt.verifySignature(verifier);
return ImmutableTokenStoreRestData.builder().from(data).signedToken(jwt.getEncoded()).user(user).build();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
use of org.springframework.security.jwt.crypto.sign.SignerVerifier in project theskeleton by codenergic.
the class TokenStoreServiceImpl method sendTokenNotification.
@Override
public TokenStoreRestData sendTokenNotification(TokenStoreType type, UserEntity user) {
try {
TokenStoreRestData data = ImmutableTokenStoreRestData.builder().userId(user.getId()).expiryDate(Date.from(Instant.now().plus(Period.ofDays(1)))).tokenType(type).uuid(UUID.randomUUID()).build();
SignerVerifier signer = createSignerVerifier(user);
Jwt token = JwtHelper.encode(objectMapper.writeValueAsString(data), signer);
sendEmail(token.getEncoded(), type, user.getEmail());
return ImmutableTokenStoreRestData.builder().from(data).signedToken(token.getEncoded()).user(user).build();
} catch (JsonProcessingException e) {
throw new IllegalStateException(e);
}
}
Aggregations