Revert "updated jwtHeader typ to use an enum" -- set things back to using a string

This reverts commit 3b2268c622.
pull/165/merge
Justin Richer 2012-08-02 14:16:55 -04:00
parent 9a7e40fee7
commit 51b8dbe065
3 changed files with 4 additions and 92 deletions

View File

@ -15,7 +15,6 @@
******************************************************************************/
package org.mitre.jwt.model;
import java.text.ParseException;
import java.util.Map.Entry;
import com.google.gson.JsonElement;
@ -60,12 +59,7 @@ public class JwtHeader extends ClaimSet {
if (element.getValue().isJsonNull()) {
pass.add(element.getKey(), element.getValue());
} else if (element.getKey().equals(TYPE)) {
try {
this.setType(element.getValue().getAsString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.setType(element.getValue().getAsString());
} else if (element.getKey().equals(ALGORITHM)) {
this.setAlgorithm(element.getValue().getAsString());
} else if (element.getKey().equals(ENCRYPTION_METHOD)) {
@ -91,13 +85,9 @@ public class JwtHeader extends ClaimSet {
/**
* @param type the type to set
* @throws ParseException
*/
public void setType(String type) throws ParseException {
if(type == null) {
throw new NullPointerException("JWT header type value must not be null");
}
setClaim(TYPE, Type.parse(type));
public void setType(String type) {
setClaim(TYPE, type);
}

View File

@ -1,72 +0,0 @@
package org.mitre.jwt.model;
public enum Type {
/**
* Type ({@code typ}) parameter indicating a JWT.
*
* <p>Corresponds to the follwoing {@code typ} values:
*
* <ul>
* <li>"JWT"
* <li>"urn:ietf:params:oauth:token-type:jwt"
* </ul>
*/
JWT,
/**
* Type ({@code typ}) parameter indicating a nested JWS.
*
* <p>Corresponds to the following {@code typ} value:
*
* <ul>
* <li>"JWS"
* </ul>
*/
JWS,
/**
* Type ({@code typ}) parameter indicating a nested JWE.
*
* <p>Corresponds to the follwoing {@code typ} value:
*
* <ul>
* <li>"JWE"
* </ul>
*/
JWE;
/**
* Parses the specified type string (case sensitive).
*
* <p>Note that both "JWT" and
* "urn:ietf:params:oauth:token-type:jwt" resolve to
* {@link #JWT}.
*
* @param s The string to parse.
*
* @throws java.text.ParseException If the string couldn't be
* parsed to a supported JWT
* header type.
*/
public static Type parse(final String s)
throws java.text.ParseException {
if (s == null)
throw new NullPointerException("The parsed JWT header \"typ\" value must not be null");
if (s.equals("JWT") || s.equals("urn:ietf:params:oauth:token-type:jwt"))
return JWT;
if (s.equals("JWS"))
return JWS;
if (s.equals("JWE"))
return JWE;
throw new java.text.ParseException("Unsupported JWT header \"typ\" value: " + s, 0);
}
}

View File

@ -27,7 +27,6 @@ import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.text.ParseException;
import java.util.Date;
import org.bouncycastle.jce.X509Principal;
@ -58,12 +57,7 @@ public class JwtTest {
@Test
public void testGenerateHmacSignature() {
Jwt jwt = new Jwt();
try {
jwt.getHeader().setType("JWT");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
jwt.getHeader().setType("JWT");
jwt.getHeader().setAlgorithm("HS256");
jwt.getClaims().setExpiration(new Date(1300819380L * 1000L));
jwt.getClaims().setIssuer("joe");