| 28 | import java.util.Set; |
| 29 | |
| 30 | public class DefaultClaims extends ParameterMap implements Claims { |
| 31 | |
| 32 | private static final String CONVERSION_ERROR_MSG = "Cannot convert existing claim value of type '%s' to desired type " + |
| 33 | "'%s'. JJWT only converts simple String, Date, Long, Integer, Short and Byte types automatically. " + |
| 34 | "Anything more complex is expected to be already converted to your desired type by the JSON Deserializer " + |
| 35 | "implementation. You may specify a custom Deserializer for a JwtParser with the desired conversion " + |
| 36 | "configuration via the JwtParserBuilder.deserializer() method. " + |
| 37 | "See https://github.com/jwtk/jjwt#custom-json-processor for more information. If using Jackson, you can " + |
| 38 | "specify custom claim POJO types as described in https://github.com/jwtk/jjwt#json-jackson-custom-types"; |
| 39 | |
| 40 | static final Parameter<String> ISSUER = Parameters.string(Claims.ISSUER, "Issuer"); |
| 41 | static final Parameter<String> SUBJECT = Parameters.string(Claims.SUBJECT, "Subject"); |
| 42 | static final Parameter<Set<String>> AUDIENCE = Parameters.stringSet(Claims.AUDIENCE, "Audience"); |
| 43 | static final Parameter<Date> EXPIRATION = Parameters.rfcDate(Claims.EXPIRATION, "Expiration Time"); |
| 44 | static final Parameter<Date> NOT_BEFORE = Parameters.rfcDate(Claims.NOT_BEFORE, "Not Before"); |
| 45 | static final Parameter<Date> ISSUED_AT = Parameters.rfcDate(Claims.ISSUED_AT, "Issued At"); |
| 46 | static final Parameter<String> JTI = Parameters.string(Claims.ID, "JWT ID"); |
| 47 | |
| 48 | static final Registry<String, Parameter<?>> PARAMS = |
| 49 | Parameters.registry(ISSUER, SUBJECT, AUDIENCE, EXPIRATION, NOT_BEFORE, ISSUED_AT, JTI); |
| 50 | |
| 51 | protected DefaultClaims() { // visibility for testing |
| 52 | super(PARAMS); |
| 53 | } |
| 54 | |
| 55 | public DefaultClaims(ParameterMap m) { |
| 56 | super(m.PARAMS, m); |
| 57 | } |
| 58 | |
| 59 | public DefaultClaims(Map<String, ?> map) { |
| 60 | super(PARAMS, map); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public String getName() { |
| 65 | return "JWT Claims"; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public String getIssuer() { |
| 70 | return get(ISSUER); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public String getSubject() { |
| 75 | return get(SUBJECT); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public Set<String> getAudience() { |
| 80 | return get(AUDIENCE); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public Date getExpiration() { |
| 85 | return get(EXPIRATION); |
| 86 | } |
| 87 | |