|
| 1 | +package org.oidc.msg.oidc; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +import org.oidc.msg.InvalidClaimException; |
| 7 | +import org.oidc.msg.ParameterVerification; |
| 8 | + |
| 9 | +/** ID Token as in http://openid.net/specs/openid-connect-core-1_0.html#IDToken. */ |
| 10 | +public class IDToken extends OpenIDSchema { |
| 11 | + |
| 12 | + { |
| 13 | + // Updating parameter requirements. |
| 14 | + paramVerDefs.put("iss", ParameterVerification.SINGLE_REQUIRED_STRING.getValue()); |
| 15 | + paramVerDefs.put("sub", ParameterVerification.SINGLE_REQUIRED_STRING.getValue()); |
| 16 | + paramVerDefs.put("aud", ParameterVerification.REQUIRED_LIST_OF_STRINGS.getValue()); |
| 17 | + paramVerDefs.put("exp", ParameterVerification.SINGLE_REQUIRED_INT.getValue()); |
| 18 | + paramVerDefs.put("iat", ParameterVerification.SINGLE_REQUIRED_INT.getValue()); |
| 19 | + paramVerDefs.put("auth_time", ParameterVerification.SINGLE_OPTIONAL_INT.getValue()); |
| 20 | + paramVerDefs.put("nonce", ParameterVerification.SINGLE_OPTIONAL_STRING.getValue()); |
| 21 | + paramVerDefs.put("at_hash", ParameterVerification.SINGLE_OPTIONAL_STRING.getValue()); |
| 22 | + paramVerDefs.put("c_hash", ParameterVerification.SINGLE_OPTIONAL_STRING.getValue()); |
| 23 | + paramVerDefs.put("acr", ParameterVerification.SINGLE_OPTIONAL_STRING.getValue()); |
| 24 | + paramVerDefs.put("amr", ParameterVerification.OPTIONAL_LIST_OF_STRINGS.getValue()); |
| 25 | + paramVerDefs.put("azp", ParameterVerification.SINGLE_OPTIONAL_STRING.getValue()); |
| 26 | + paramVerDefs.put("sub_jwk", ParameterVerification.SINGLE_OPTIONAL_STRING.getValue()); |
| 27 | + |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Constructor. |
| 32 | + */ |
| 33 | + public IDToken() { |
| 34 | + this(new HashMap<String, Object>()); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Constructor. |
| 39 | + * |
| 40 | + * @param claims |
| 41 | + * ID Token claims as described in |
| 42 | + * http://openid.net/specs/openid-connect-core-1_0.html#IDToken. |
| 43 | + */ |
| 44 | + public IDToken(Map<String, Object> claims) { |
| 45 | + super(claims); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Verifies the presence of required message parameters. Verifies the the format of message |
| 50 | + * parameters. |
| 51 | + * |
| 52 | + * @return true if parameters are successfully verified. |
| 53 | + * @throws InvalidClaimException |
| 54 | + * if verification fails. |
| 55 | + */ |
| 56 | + public boolean verify() throws InvalidClaimException { |
| 57 | + super.verify(); |
| 58 | + // TODO:Check issuer. Requires setter for issuer to compare against. |
| 59 | + // TODO:Check client_id is among aud. Requires a setter for client_id to compare against. |
| 60 | + // TODO:if multiple aud, check azp is in audience. |
| 61 | + // TODO:if client_id is set and azp exists, they must match. |
| 62 | + // TODO:check exp is not in the past. Requires setter for skew to allow skew. |
| 63 | + // TODO:check iat+NONCE_STORAGE_TIME < now - skew. Requires setter but leave it until |
| 64 | + // requirement is clear. NONCE_STORAGE_TIME = 4 * 3600 |
| 65 | + // TODO: Check nonce. Requires setter for nonce to compare against. |
| 66 | + return true; |
| 67 | + |
| 68 | + } |
| 69 | +} |
0 commit comments