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$ (2015-01-12) 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 /** 131 * Gets the specified claims (registered or custom) as a 132 * {@link java.lang.String} array. 133 * 134 * @param name The name of the claim. Must not be {@code null}. 135 * 136 * @return The value of the claim, {@code null} if not specified. 137 * 138 * @throws ParseException If the claim value is not of the required 139 * type. 140 */ 141 public String[] getStringArrayClaim(final String name) 142 throws ParseException; 143 144 145 /** 146 * Gets the specified claims (registered or custom) as a 147 * {@link java.lang.String} list. 148 * 149 * @param name The name of the claim. Must not be {@code null}. 150 * 151 * @return The value of the claim, {@code null} if not specified. 152 * 153 * @throws ParseException If the claim value is not of the required 154 * type. 155 */ 156 public List<String> getStringListClaim(final String name) 157 throws ParseException; 158 159 160 /** 161 * Gets the specified claim (registered or custom) as 162 * {@link java.lang.Boolean}. 163 * 164 * @param name The name of the claim. Must not be {@code null}. 165 * 166 * @return The value of the claim, {@code null} if not specified. 167 * 168 * @throws ParseException If the claim value is not of the required 169 * type. 170 */ 171 public Boolean getBooleanClaim(final String name) 172 throws ParseException; 173 174 175 /** 176 * Gets the specified claim (registered or custom) as 177 * {@link java.lang.Integer}. 178 * 179 * @param name The name of the claim. Must not be {@code null}. 180 * 181 * @return The value of the claim, {@code null} if not specified. 182 * 183 * @throws ParseException If the claim value is not of the required 184 * type. 185 */ 186 public Integer getIntegerClaim(final String name) 187 throws ParseException; 188 189 190 /** 191 * Gets the specified claim (registered or custom) as 192 * {@link java.lang.Long}. 193 * 194 * @param name The name of the claim. Must not be {@code null}. 195 * 196 * @return The value of the claim, {@code null} if not specified. 197 * 198 * @throws ParseException If the claim value is not of the required 199 * type. 200 */ 201 public Long getLongClaim(final String name) 202 throws ParseException; 203 204 205 /** 206 * Gets the specified claim (registered or custom) as 207 * {@link java.lang.Float}. 208 * 209 * @param name The name of the claim. Must not be {@code null}. 210 * 211 * @return The value of the claim, {@code null} if not specified. 212 * 213 * @throws ParseException If the claim value is not of the required 214 * type. 215 */ 216 public Float getFloatClaim(final String name) 217 throws ParseException; 218 219 220 /** 221 * Gets the specified claim (registered or custom) as 222 * {@link java.lang.Double}. 223 * 224 * @param name The name of the claim. Must not be {@code null}. 225 * 226 * @return The value of the claim, {@code null} if not specified. 227 * 228 * @throws ParseException If the claim value is not of the required 229 * type. 230 */ 231 public Double getDoubleClaim(final String name) 232 throws ParseException; 233 234 235 /** 236 * Gets all claims, both registered and custom, as a single map. 237 * 238 * <p>Note that the registered claims Expiration-Time ({@code exp}), 239 * Not-Before-Time ({@code nbf}) and Issued-At ({@code iat}) will be 240 * returned as {@code java.util.Date} instances. 241 * 242 * @return All claims, as an unmodifiable map, empty map if none. 243 */ 244 public Map<String,Object> getAllClaims(); 245 246 247 /** 248 * Returns the JSON object representation of the claims set. 249 * 250 * @return The JSON object representation. 251 */ 252 public JSONObject toJSONObject(); 253}