View Javadoc

1   package com.atlassian.asap.api;
2   
3   import javax.json.JsonObject;
4   import java.time.Instant;
5   import java.util.Optional;
6   import java.util.Set;
7   
8   /**
9    * Represents the claims of an ASAP JWT payload.
10   *
11   * @see <a href="https://tools.ietf.org/html/rfc7519">JSON Web Token</a>
12   */
13  public interface JwtClaims {
14      /**
15       * @return the value of the 'iss' claim. That is, the principal or application that issued the token.
16       */
17      String getIssuer();
18  
19      /**
20       * @return the value of the 'sub' claim (optional). That is, the principal that a request is being made on the behalf of.
21       */
22      Optional<String> getSubject();
23  
24      /**
25       * @return the value of the 'aud' claim. That is, the principal(s) or application(s) that the token is addressed to.
26       */
27      Set<String> getAudience();
28  
29      /**
30       * @return the value of the 'exp' claim. That is, the expiration time after which the token MUST NOT be accepted for processing.
31       */
32      Instant getExpiry();
33  
34      /**
35       * @return the value of the 'nbf' claim (optional). That is, the time before which the token MUST NOT be accepted for processing.
36       */
37      Optional<Instant> getNotBefore();
38  
39      /**
40       * @return the value of the 'iat' claim. That is, the time at which the token was issued.
41       */
42      Instant getIssuedAt();
43  
44      /**
45       * @return the value of the 'jti' claim. That is, the a unique identifier for the token.
46       */
47      String getJwtId();
48  
49      /**
50       * @return all the claims, as a JSON object
51       */
52      JsonObject getJson();
53  
54      /**
55       * The registered claims of a JWT claims payload as per JWT spec.
56       */
57      enum RegisteredClaim {
58          ISSUER("iss"),
59          SUBJECT("sub"),
60          AUDIENCE("aud"),
61          EXPIRY("exp"),
62          NOT_BEFORE("nbf"),
63          ISSUED_AT("iat"),
64          JWT_ID("jti");
65  
66          private final String key;
67  
68          RegisteredClaim(String key) {
69              this.key = key;
70          }
71  
72          public String key() {
73              return key;
74          }
75      }
76  }