001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2013-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.json.jose.jwt; 018 019/** 020 * An Enum for the JWT Claims Set names. 021 * <p> 022 * As described in the JWT specification, this Enum class represents all the reserved JWT Claim Names, any other Claim 023 * name is deemed as a "custom" Claim name. 024 * <p> 025 * @see <a href="http://tools.ietf.org/html/draft-jones-json-web-token-10#section-4.1">Reserved Claim Names</a> 026 * 027 * @since 2.0.0 028 */ 029public enum JwtClaimsSetKey { 030 031 /** 032 * Type Claim. 033 * <p> 034 * Used to declare a type for the contents of this JWT Claims Set. 035 * <p> 036 * The values used for the "typ" claim SHOULD come from the same value space as the "typ" header parameter, with 037 * the same rules applying. 038 */ 039 TYP, 040 /** 041 * JWT ID Claim. 042 * <p> 043 * Provides a unique identifier for the JWT. 044 */ 045 JTI, 046 /** 047 * Issuer Claim. 048 * <p> 049 * Identifies the principal that issued the JWT. 050 */ 051 ISS, 052 /** 053 * Subject Claim. 054 * <p> 055 * Identifies the subject of the JWT. 056 */ 057 SUB, 058 /** 059 * Audience Claim. 060 * <p> 061 * Identifies the audience that the JWT is intended for. 062 */ 063 AUD, 064 /** 065 * Issued At Claim. 066 * <p> 067 * Identifies the time at which the JWT was issued. This claim can be used to determine the age of the token. 068 */ 069 IAT, 070 /** 071 * Not Before Claim. 072 * <p> 073 * Identifies the time before which the token MUST NOT be accepted for processing. 074 */ 075 NBF, 076 /** 077 * Expiration Time Claim. 078 * <p> 079 * Identifies the expiration time on or after which the token MUST NOT be accepted for processing. 080 */ 081 EXP, 082 /** Custom (private) Claim. */ 083 CUSTOM; 084 085 /** 086 * Returns a lowercase String of the JwtClaimsSetKey constant. 087 * 088 * @return Lowercase String representation of the constant. 089 * @see #toString() 090 */ 091 public String value() { 092 return toString(); 093 } 094 095 /** 096 * Gets the JwtClaimsSetKey constant that matches the given String. 097 * <p> 098 * If the given String does not match any of the constants, then CUSTOM is returned. 099 * 100 * @param claimSetKey The String representation of a JwtClaimsSetKey. 101 * @return The matching JwtClaimsSetKey. 102 */ 103 public static JwtClaimsSetKey getClaimSetKey(String claimSetKey) { 104 try { 105 return JwtClaimsSetKey.valueOf(claimSetKey.toUpperCase()); 106 } catch (IllegalArgumentException e) { 107 return CUSTOM; 108 } 109 } 110 111 /** 112 * Turns the JwtClaimsSetKey constant into a lowercase String. 113 * 114 * @return {@inheritDoc} 115 */ 116 @Override 117 public String toString() { 118 return super.toString().toLowerCase(); 119 } 120}