001package com.nimbusds.jwt; 002 003 004import java.text.ParseException; 005import java.util.Date; 006import java.util.List; 007import java.util.Map; 008 009import net.minidev.json.JSONObject; 010 011 012/** 013 * Read-only view of a {@link JWTClaimsSet}. 014 * 015 * @author Vladimir Dzhuvinov 016 * @author Justin Richer 017 * @version $version$ (2013-10-07) 018 */ 019public interface ReadOnlyJWTClaimsSet { 020 021 022 /** 023 * Gets the issuer ({@code iss}) claim. 024 * 025 * @return The issuer claim, {@code null} if not specified. 026 */ 027 public String getIssuer(); 028 029 030 /** 031 * Gets the subject ({@code sub}) claim. 032 * 033 * @return The subject claim, {@code null} if not specified. 034 */ 035 public String getSubject(); 036 037 038 /** 039 * Gets the audience ({@code aud}) clam. 040 * 041 * @return The audience claim, {@code null} if not specified. 042 */ 043 public List<String> getAudience(); 044 045 046 /** 047 * Gets the expiration time ({@code exp}) claim. 048 * 049 * @return The expiration time, {@code null} if not specified. 050 */ 051 public Date getExpirationTime(); 052 053 054 /** 055 * Gets the not-before ({@code nbf}) claim. 056 * 057 * @return The not-before claim, {@code null} if not specified. 058 */ 059 public Date getNotBeforeTime(); 060 061 062 /** 063 * Gets the issued-at ({@code iat}) claim. 064 * 065 * @return The issued-at claim, {@code null} if not specified. 066 */ 067 public Date getIssueTime(); 068 069 070 /** 071 * Gets the JWT ID ({@code jti}) claim. 072 * 073 * @return The JWT ID claim, {@code null} if not specified. 074 */ 075 public String getJWTID(); 076 077 078 /** 079 * Gets the type ({@code typ}) claim. 080 * 081 * @return The type claim, {@code null} if not specified. 082 */ 083 public String getType(); 084 085 086 /** 087 * Gets a custom (non-registered) claim. 088 * 089 * @param name The name of the custom claim. Must not be {@code null}. 090 * 091 * @return The value of the custom claim, {@code null} if not 092 * specified. 093 */ 094 public Object getCustomClaim(final String name); 095 096 097 /** 098 * Gets the custom (non-registered) claims. 099 * 100 * @return The custom claims, as a unmodifiable map, empty map if none. 101 */ 102 public Map<String,Object> getCustomClaims(); 103 104 105 /** 106 * Gets the specified claim (registered or custom). 107 * 108 * @param name The name of the claim. Must not be {@code null}. 109 * 110 * @return The value of the claim, {@code null} if not specified. 111 */ 112 public Object getClaim(final String name); 113 114 115 /** 116 * Gets the specified claim (registered or custom) as 117 * {@link java.lang.String}. 118 * 119 * @param name The name of the claim. Must not be {@code null}. 120 * 121 * @return The value of the claim, {@code null} if not specified. 122 * 123 * @throws ParseException If the claim value is not of the required 124 * type. 125 */ 126 public String getStringClaim(final String name) 127 throws ParseException; 128 129 /** 130 * Gets the specified claim (registered or custom) as 131 * {@link java.lang.Boolean}. 132 * 133 * @param name The name of the claim. Must not be {@code null}. 134 * 135 * @return The value of the claim, {@code null} if not specified. 136 * 137 * @throws ParseException If the claim value is not of the required 138 * type. 139 */ 140 public Boolean getBooleanClaim(final String name) 141 throws ParseException; 142 143 144 /** 145 * Gets the specified claim (registered or custom) as 146 * {@link java.lang.Integer}. 147 * 148 * @param name The name of the claim. Must not be {@code null}. 149 * 150 * @return The value of the claim, {@code null} if not specified. 151 * 152 * @throws ParseException If the claim value is not of the required 153 * type. 154 */ 155 public Integer getIntegerClaim(final String name) 156 throws ParseException; 157 158 159 /** 160 * Gets the specified claim (registered or custom) as 161 * {@link java.lang.Long}. 162 * 163 * @param name The name of the claim. Must not be {@code null}. 164 * 165 * @return The value of the claim, {@code null} if not specified. 166 * 167 * @throws ParseException If the claim value is not of the required 168 * type. 169 */ 170 public Long getLongClaim(final String name) 171 throws ParseException; 172 173 174 /** 175 * Gets the specified claim (registered or custom) as 176 * {@link java.lang.Float}. 177 * 178 * @param name The name of the claim. Must not be {@code null}. 179 * 180 * @return The value of the claim, {@code null} if not specified. 181 * 182 * @throws ParseException If the claim value is not of the required 183 * type. 184 */ 185 public Float getFloatClaim(final String name) 186 throws ParseException; 187 188 189 /** 190 * Gets the specified claim (registered or custom) as 191 * {@link java.lang.Double}. 192 * 193 * @param name The name of the claim. Must not be {@code null}. 194 * 195 * @return The value of the claim, {@code null} if not specified. 196 * 197 * @throws ParseException If the claim value is not of the required 198 * type. 199 */ 200 public Double getDoubleClaim(final String name) 201 throws ParseException; 202 203 204 /** 205 * Gets all claims, both registered and custom, as a single map. 206 * 207 * <p>Note that the registered claims Expiration-Time ({@code exp}), 208 * Not-Before-Time ({@code nbf}) and Issued-At ({@code iat}) will be 209 * returned as {@code java.util.Date} instances. 210 * 211 * @return All claims, as an unmodifiable map, empty map if none. 212 */ 213 public Map<String, Object> getAllClaims(); 214 215 216 /** 217 * Returns the JSON object representation of the claims set. 218 * 219 * @return The JSON object representation. 220 */ 221 public JSONObject toJSONObject(); 222}