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.jws; 018 019/** 020 * An Enum for the JWS Header parameter names. 021 * <p> 022 * As described in the JWS specification, the reserved JWS header parameters are listed, 023 * <ul> 024 * <li>"jku"</li> 025 * <li>"jwk"</li> 026 * <li>"x5u"</li> 027 * <li>"x5t"</li> 028 * <li>"x5c"</li> 029 * <li>"kid"</li> 030 * <li>"cty"</li> 031 * <li>"crit"</li> 032 * </ul> 033 * Any other header parameter name is deemed as a "custom" header parameter. 034 * 035 * @since 2.0.0 036 */ 037public enum JwsHeaderKey { 038 039 /** 040 * JWK Set URL header parameter. 041 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.2"> 042 * JWS Specification JWK Set URL Header Parameter</a> 043 */ 044 JKU, 045 /** 046 * JSON Web Key header parameter. 047 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.3"> 048 * JWS Specification JWK Web Key Header Parameter</a> 049 */ 050 JWK, 051 /** 052 * X.509 URL header parameter. 053 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.4"> 054 * JWS Specification X.509 URL Header Parameter</a> 055 */ 056 X5U, 057 /** 058 * X.509 Certificate Thumbprint header parameter. 059 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.5"> 060 * JWS Specification X.509 Certificate Thumbprint Header Parameter</a> 061 **/ 062 X5T, //Base64url 063 /** 064 * X.509 Certificate Chain header parameter. 065 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.6"> 066 * JWS Specification X.509 Certificate Chain Header Parameter</a> 067 */ 068 X5C, //List<Base64> 069 /** 070 * Key ID header parameter. 071 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.7"> 072 * JWS Specification Key ID Header Parameter</a> 073 */ 074 KID, 075 /** 076 * Content Type header parameter. 077 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.8"> 078 * JWS Specification Content Type Header Parameter</a> 079 */ 080 CTY, 081 /** 082 * Critical header parameter. 083 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.10"> 084 * JWS Specification Critical Header Parameter</a> 085 */ 086 CRIT, 087 /** 088 * Generic header key for a custom header parameter. 089 * @see <a href="http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.3"> 090 * Private Header Parameter Names</a> 091 */ 092 CUSTOM; 093 094 /** 095 * Returns a lowercase String of the JwsHeaderKey constant. 096 * 097 * @return Lowercase String representation of the constant. 098 * @see #toString() 099 */ 100 public String value() { 101 return toString(); 102 } 103 104 /** 105 * Gets the JwsHeaderKey constant that matches the given String. 106 * <p> 107 * If the given String does not match any of the constants, then CUSTOM is returned. 108 * 109 * @param headerKey The String representation of a JwsHeaderKey. 110 * @return The matching JwsHeaderKey. 111 */ 112 public static JwsHeaderKey getHeaderKey(String headerKey) { 113 try { 114 return JwsHeaderKey.valueOf(headerKey); 115 } catch (IllegalArgumentException e) { 116 return CUSTOM; 117 } 118 } 119 120 /** 121 * Turns the JwsHeaderKey constant into a lowercase String. 122 * 123 * @return {@inheritDoc} 124 */ 125 @Override 126 public String toString() { 127 return super.toString().toLowerCase(); 128 } 129}