Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. @ApplicationScoped
  2. public class TokenManager {
  3. public String createToken(final CreateTokenRequest createTokenRequest, final User user) {
  4. final Instant now = Instant.now();
  5. try {
  6. return JwtBuilder.create("jwtBuilder")
  7. .subject(user.getName())
  8. .expirationTime(
  9. now.plusMillis(createTokenRequest.getValidityDurationMillis()).getEpochSecond()
  10. )
  11. .claim(“upn”, user.getName())
  12. .claim(“groups”, createTokenRequest.getRoles())
  13. .buildJwt()
  14. .compact();
  15. } catch (final JwtException | InvalidBuilderException | InvalidClaimException e) {
  16. throw new IllegalStateException("could not create JWT", e);
  17. }
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement