Class JWTBuilder


  • public final class JWTBuilder
    extends java.lang.Object
    A class that encapsulates the logic required to generate JWT tokens for users.
    Author:
    Alex Kalderimis
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JWTBuilder.Algorithm
      The signing algorithms this builder supports.
    • Constructor Summary

      Constructors 
      Constructor Description
      JWTBuilder​(java.security.PrivateKey key, java.lang.String issuer)
      Constructor
      JWTBuilder​(JWTBuilder.Algorithm algorithm, java.security.PrivateKey key, java.lang.String issuer)
      Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object other)  
      int hashCode()  
      java.lang.String issueToken​(Profile profile, int validForSeconds)
      Issue a new token for the given profile.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • JWTBuilder

        public JWTBuilder​(java.security.PrivateKey key,
                          java.lang.String issuer)
        Constructor
        Parameters:
        key - The private key to sign the tokens with.
        issuer - The identity of this builder, reported in the 'iss' header claim.
      • JWTBuilder

        public JWTBuilder​(JWTBuilder.Algorithm algorithm,
                          java.security.PrivateKey key,
                          java.lang.String issuer)
        Constructor
        Parameters:
        algorithm - The signing algorithm
        key - The key used to sign the token.
        issuer - The identity of this builder, reported in the 'iss' header claim.
    • Method Detail

      • issueToken

        public java.lang.String issueToken​(Profile profile,
                                           int validForSeconds)
                                    throws java.security.InvalidKeyException,
                                           java.security.SignatureException
        Issue a new token for the given profile.
        Parameters:
        profile - The profile to issue a token for.
        validForSeconds - The number of seconds the token should be valid for.
        Returns:
        The JWT token
        Throws:
        java.security.InvalidKeyException - If the private key is not valid.
        java.security.SignatureException - If we cannot sign the token.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object