Browse Source

jwt structures are claims based

pull/59/head
Justin Richer 13 years ago
parent
commit
febad61730
  1. 12
      src/main/java/org/mitre/jwt/model/JwtClaims.java
  2. 10
      src/main/java/org/mitre/jwt/model/JwtHeader.java
  3. 4
      src/test/java/org/mitre/jwt/JwtTest.java

12
src/main/java/org/mitre/jwt/model/JwtClaims.java

@ -50,12 +50,14 @@ public class JwtClaims extends ClaimSet {
setJwtId(element.getValue().getAsString());
} else if (element.getKey().equals(TYPE)) {
setType(element.getValue().getAsString());
} else if (element.getValue().isJsonPrimitive()){
// we handle all primitives in here
JsonPrimitive prim = element.getValue().getAsJsonPrimitive();
setClaim(element.getKey(), prim);
} else {
setClaim(element.getKey(), element.getValue());
if (element.getValue().isJsonPrimitive()){
// we handle all primitives in here
JsonPrimitive prim = element.getValue().getAsJsonPrimitive();
setClaim(element.getKey(), prim);
} else {
setClaim(element.getKey(), element.getValue());
}
}
}
}

10
src/main/java/org/mitre/jwt/model/JwtHeader.java

@ -6,6 +6,7 @@ import java.util.Map.Entry;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
public class JwtHeader extends ClaimSet {
@ -34,8 +35,13 @@ public class JwtHeader extends ClaimSet {
} else if (element.getKey().equals(ENCRYPTION_METHOD)) {
this.setEncryptionMethod(json.get(ENCRYPTION_METHOD).getAsString());
} else {
// TODO: this assumes string encoding for extensions, probably not quite correct
setClaim(element.getKey(), element.getValue().getAsString());
if (element.getValue().isJsonPrimitive()){
// we handle all primitives in here
JsonPrimitive prim = element.getValue().getAsJsonPrimitive();
setClaim(element.getKey(), prim);
} else {
setClaim(element.getKey(), element.getValue());
}
}
}
}

4
src/test/java/org/mitre/jwt/JwtTest.java

@ -21,8 +21,8 @@ public class JwtTest {
public void testToStringPlaintext() {
Jwt jwt = new Jwt();
jwt.getHeader().setAlgorithm("none");
jwt.getClaims().setIssuer("joe");
jwt.getClaims().setExpiration(new Date(1300819380L * 1000L));
jwt.getClaims().setIssuer("joe");
jwt.getClaims().setClaim("http://example.com/is_root", Boolean.TRUE);
// sign it with a blank signature
@ -48,8 +48,8 @@ public class JwtTest {
Jwt jwt = new Jwt();
jwt.getHeader().setType("JWT");
jwt.getHeader().setAlgorithm("HS256");
jwt.getClaims().setIssuer("joe");
jwt.getClaims().setExpiration(new Date(1300819380L * 1000L));
jwt.getClaims().setIssuer("joe");
jwt.getClaims().setClaim("http://example.com/is_root", Boolean.TRUE);
// sign it

Loading…
Cancel
Save