added jwt string stability to several places, fixed jwe parser
parent
7c33e19950
commit
164090e9d5
|
@ -40,6 +40,7 @@ public class Jwe extends Jwt {
|
|||
this.ciphertext = ciphertext;
|
||||
}
|
||||
|
||||
/*
|
||||
public Jwe(String headerBase64, String encryptedKeyBase64, String cipherTextBase64, String integrityValueBase64) {
|
||||
byte[] decodedEncryptedKey = Base64.decodeBase64(encryptedKeyBase64.getBytes());
|
||||
byte[] decodedCipherText = Base64.decodeBase64(cipherTextBase64.getBytes());
|
||||
|
@ -48,6 +49,7 @@ public class Jwe extends Jwt {
|
|||
this.ciphertext = decodedCipherText;
|
||||
setSignature(integrityValueBase64);
|
||||
}
|
||||
*/
|
||||
|
||||
public JweHeader getHeader() {
|
||||
return header;
|
||||
|
@ -75,11 +77,10 @@ public class Jwe extends Jwt {
|
|||
|
||||
@Override
|
||||
public String getSignatureBase() {
|
||||
JsonObject h = header.getAsJsonObject();
|
||||
byte[] c = ciphertext;
|
||||
byte[] e = encryptedKey;
|
||||
|
||||
String h64 = new String(Base64.encodeBase64URLSafe(h.toString().getBytes()));
|
||||
String h64 = new String(Base64.encodeBase64URLSafe(header.toJsonString().getBytes()));
|
||||
String e64 = new String(Base64.encodeBase64URLSafe(e));
|
||||
String c64 = new String(Base64.encodeBase64URLSafe(c));
|
||||
|
||||
|
@ -106,7 +107,10 @@ public class Jwe extends Jwt {
|
|||
String c64 = parts.get(2);
|
||||
String i64 = parts.get(3);
|
||||
|
||||
Jwe jwe = new Jwe(h64, e64, c64, i64);
|
||||
byte[] decodedEncryptedKey = Base64.decodeBase64(e64.getBytes());
|
||||
byte[] decodedCipherText = Base64.decodeBase64(c64.getBytes());
|
||||
|
||||
Jwe jwe = new Jwe(new JweHeader(h64), decodedEncryptedKey, decodedCipherText, i64);
|
||||
|
||||
return jwe;
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public class ClaimSet {
|
|||
* Set an extension claim
|
||||
*/
|
||||
public void setClaim(String key, Object value) {
|
||||
jsonString = null;
|
||||
invalidateString();
|
||||
claims.put(key, value);
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class ClaimSet {
|
|||
* Set a primitive claim
|
||||
*/
|
||||
public void setClaim(String key, JsonPrimitive prim) {
|
||||
jsonString = null;
|
||||
invalidateString();
|
||||
if (prim == null) {
|
||||
// in case we get here with a primitive null
|
||||
claims.put(key, prim);
|
||||
|
@ -116,12 +116,17 @@ public class ClaimSet {
|
|||
claims.put(key, prim.getAsString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void invalidateString() {
|
||||
jsonString = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an extension claim
|
||||
*/
|
||||
public Object removeClaim(String key) {
|
||||
invalidateString();
|
||||
return claims.remove(key);
|
||||
}
|
||||
|
||||
|
@ -131,6 +136,7 @@ public class ClaimSet {
|
|||
* @see java.util.Map#clear()
|
||||
*/
|
||||
public void clear() {
|
||||
invalidateString();
|
||||
claims.clear();
|
||||
}
|
||||
|
||||
|
@ -197,7 +203,7 @@ public class ClaimSet {
|
|||
}
|
||||
|
||||
/**
|
||||
* Load a new claims set from a Base64 encoded JSON Object string
|
||||
* Load a new claims set from a Base64 encoded JSON Object string and caches the string used
|
||||
*/
|
||||
public void loadFromBase64JsonObjectString(String b64) {
|
||||
byte[] b64decoded = Base64.decodeBase64(b64);
|
||||
|
@ -206,9 +212,12 @@ public class ClaimSet {
|
|||
JsonObject json = parser.parse(new InputStreamReader(new ByteArrayInputStream(b64decoded))).getAsJsonObject();
|
||||
|
||||
loadFromJsonObject(json);
|
||||
|
||||
// save the string we were passed in (decoded from base64)
|
||||
jsonString = new String(b64decoded);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
public String toJsonString() {
|
||||
if(jsonString == null) {
|
||||
jsonString = this.getAsJsonObject().toString();
|
||||
}
|
||||
|
|
|
@ -124,8 +124,8 @@ public class Jwt {
|
|||
*/
|
||||
public String getSignatureBase() {
|
||||
|
||||
String h64 = new String(Base64.encodeBase64URLSafe(header.toString().getBytes()));
|
||||
String c64 = new String(Base64.encodeBase64URLSafe(claims.toString().getBytes()));
|
||||
String h64 = new String(Base64.encodeBase64URLSafe(header.toJsonString().getBytes()));
|
||||
String c64 = new String(Base64.encodeBase64URLSafe(claims.toJsonString().getBytes()));
|
||||
|
||||
return h64 + "." + c64;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue