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 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        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        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        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        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        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        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        String getJWTID();
076
077
078        /**
079         * Gets a custom (non-registered) claim.
080         * 
081         * @param name The name of the custom claim. Must not be {@code null}.
082         *
083         * @return The value of the custom claim, {@code null} if not 
084         *         specified.
085         */
086        Object getCustomClaim(final String name);
087
088
089        /**
090         * Gets the custom (non-registered) claims.
091         *
092         * @return The custom claims, as a unmodifiable map, empty map if none.
093         */
094        Map<String,Object> getCustomClaims();
095        
096
097        /**
098         * Gets the specified claim (registered or custom).
099         * 
100         * @param name The name of the claim. Must not be {@code null}.
101         * 
102         * @return The value of the claim, {@code null} if not specified.
103         */
104        Object getClaim(final String name);
105        
106        
107        /**
108         * Gets the specified claim (registered or custom) as
109         * {@link java.lang.String}.
110         * 
111         * @param name The name of the claim. Must not be {@code null}.
112         * 
113         * @return The value of the claim, {@code null} if not specified.
114         * 
115         * @throws ParseException If the claim value is not of the required
116         *                        type.
117         */
118        String getStringClaim(final String name)
119                throws ParseException;
120
121
122        /**
123         * Gets the specified claims (registered or custom) as a
124         * {@link java.lang.String} array.
125         *
126         * @param name The name of the claim. Must not be {@code null}.
127         *
128         * @return The value of the claim, {@code null} if not specified.
129         *
130         * @throws ParseException If the claim value is not of the required
131         *                        type.
132         */
133        String[] getStringArrayClaim(final String name)
134                throws ParseException;
135
136
137        /**
138         * Gets the specified claims (registered or custom) as a
139         * {@link java.lang.String} list.
140         *
141         * @param name The name of the claim. Must not be {@code null}.
142         *
143         * @return The value of the claim, {@code null} if not specified.
144         *
145         * @throws ParseException If the claim value is not of the required
146         *                        type.
147         */
148        List<String> getStringListClaim(final String name)
149                throws ParseException;
150
151        
152        /**
153         * Gets the specified claim (registered or custom) as
154         * {@link java.lang.Boolean}.
155         * 
156         * @param name The name of the claim. Must not be {@code null}.
157         * 
158         * @return The value of the claim, {@code null} if not specified.
159         * 
160         * @throws ParseException If the claim value is not of the required
161         *                        type.
162         */
163        Boolean getBooleanClaim(final String name)
164                throws ParseException;
165        
166        
167        /**
168         * Gets the specified claim (registered or custom) as
169         * {@link java.lang.Integer}.
170         * 
171         * @param name The name of the claim. Must not be {@code null}.
172         * 
173         * @return The value of the claim, {@code null} if not specified.
174         * 
175         * @throws ParseException If the claim value is not of the required
176         *                        type.
177         */
178        Integer getIntegerClaim(final String name)
179                throws ParseException;
180        
181        
182        /**
183         * Gets the specified claim (registered or custom) as
184         * {@link java.lang.Long}.
185         * 
186         * @param name The name of the claim. Must not be {@code null}.
187         * 
188         * @return The value of the claim, {@code null} if not specified.
189         * 
190         * @throws ParseException If the claim value is not of the required
191         *                        type.
192         */
193        Long getLongClaim(final String name)
194                throws ParseException;
195        
196        
197        /**
198         * Gets the specified claim (registered or custom) as
199         * {@link java.lang.Float}.
200         * 
201         * @param name The name of the claim. Must not be {@code null}.
202         * 
203         * @return The value of the claim, {@code null} if not specified.
204         * 
205         * @throws ParseException If the claim value is not of the required
206         *                        type.
207         */
208        Float getFloatClaim(final String name)
209                throws ParseException;
210        
211        
212        /**
213         * Gets the specified claim (registered or custom) as
214         * {@link java.lang.Double}.
215         * 
216         * @param name The name of the claim. Must not be {@code null}.
217         * 
218         * @return The value of the claim, {@code null} if not specified.
219         * 
220         * @throws ParseException If the claim value is not of the required
221         *                        type.
222         */
223        Double getDoubleClaim(final String name)
224                throws ParseException;
225
226
227        /**
228         * Gets all claims, both registered and custom, as a single map.
229         *
230         * <p>Note that the registered claims Expiration-Time ({@code exp}),
231         * Not-Before-Time ({@code nbf}) and Issued-At ({@code iat}) will be
232         * returned as {@code java.util.Date} instances.
233         * 
234         * @return All claims, as an unmodifiable map, empty map if none.
235         */
236        Map<String,Object> getAllClaims();
237
238
239        /**
240         * Returns the JSON object representation of the claims set. The claims
241         * are serialised according to their insertion order.
242         *
243         * @return The JSON object representation.
244         */
245        JSONObject toJSONObject();
246}