use of org.xdi.oxauth.model.exception.InvalidJwtException in project oxAuth by GluuFederation.
the class Jwt method parse.
public static Jwt parse(String encodedJwt) throws InvalidJwtException {
if (StringUtils.isBlank(encodedJwt)) {
return null;
}
String encodedHeader = null;
String encodedClaims = null;
String encodedSignature = null;
String[] jwtParts = encodedJwt.split("\\.");
if (jwtParts.length == 2) {
// Signature Algorithm NONE
encodedHeader = jwtParts[0];
encodedClaims = jwtParts[1];
encodedSignature = "";
} else if (jwtParts.length == 3) {
encodedHeader = jwtParts[0];
encodedClaims = jwtParts[1];
encodedSignature = jwtParts[2];
} else {
throw new InvalidJwtException("Invalid JWT format.");
}
Jwt jwt = new Jwt();
jwt.setHeader(new JwtHeader(encodedHeader));
jwt.setClaims(new JwtClaims(encodedClaims));
jwt.setEncodedSignature(encodedSignature);
jwt.encodedHeader = encodedHeader;
jwt.encodedClaims = encodedClaims;
jwt.loaded = true;
return jwt;
}
use of org.xdi.oxauth.model.exception.InvalidJwtException in project oxAuth by GluuFederation.
the class JwtClaimSet method toJsonObject.
public JSONObject toJsonObject() throws InvalidJwtException {
JSONObject jsonObject = new JSONObject();
try {
for (Map.Entry<String, Object> claim : claims.entrySet()) {
if (claim.getValue() instanceof Date) {
Date date = (Date) claim.getValue();
jsonObject.put(claim.getKey(), date.getTime() / 1000);
} else if (claim.getValue() instanceof JwtSubClaimObject) {
JwtSubClaimObject subClaimObject = (JwtSubClaimObject) claim.getValue();
jsonObject.put(subClaimObject.getName(), subClaimObject.toJsonObject());
} else {
jsonObject.put(claim.getKey(), claim.getValue());
}
}
} catch (JSONException e) {
throw new InvalidJwtException(e);
} catch (Exception e) {
throw new InvalidJwtException(e);
}
return jsonObject;
}
Aggregations