import com.nimbusds.jwt.JWTClaimsSet; //导入方法依赖的package包/类
/**
* Parses authz code from string (JSON)
*
* @param authorizeCodeClaimsSet
* JSON String representation of the code
* @return AuthorizeCodeClaimsSet instance if parsing is successful.
* @throws ParseException
* if parsing fails for example due to incompatible types.
*/
public static AuthorizeCodeClaimsSet parse(String authorizeCodeClaimsSet) throws ParseException {
JWTClaimsSet acClaimsSet = JWTClaimsSet.parse(authorizeCodeClaimsSet);
// Check existence and type of mandatory fields and values
if (!VALUE_TYPE_AC.equals(acClaimsSet.getClaims().get(KEY_TYPE))) {
throw new ParseException("claim type must have value ac", 0);
}
//Mandatory fields
if (acClaimsSet.getStringClaim(KEY_ISSUER) == null) {
throw new ParseException("claim iss must exist and not be null", 0);
}
if (acClaimsSet.getStringClaim(KEY_USER_PRINCIPAL) == null) {
throw new ParseException("claim sub must exist and not be null", 0);
}
if (acClaimsSet.getStringArrayClaim(KEY_CLIENTID) == null) {
throw new ParseException("claim aud must exist and not be null", 0);
}
if (acClaimsSet.getDateClaim(KEY_EXPIRATION_TIME) == null) {
throw new ParseException("claim exp must exist and not be null", 0);
}
if (acClaimsSet.getDateClaim(KEY_ISSUED_AT) == null) {
throw new ParseException("claim iat must exist and not be null", 0);
}
if (acClaimsSet.getStringClaim(KEY_AC_ID) == null) {
throw new ParseException("claim jti must exist and not be null", 0);
}
if (acClaimsSet.getStringClaim(KEY_ACR) == null) {
throw new ParseException("claim acr must exist and not be null", 0);
}
if (acClaimsSet.getDateClaim(KEY_AUTH_TIME) == null) {
throw new ParseException("claim auth_time must exist and not be null", 0);
}
if (acClaimsSet.getStringClaim(KEY_REDIRECT_URI) == null) {
throw new ParseException("claim redirect_uri must exist and not be null", 0);
}
if (acClaimsSet.getStringClaim(KEY_SCOPE) == null) {
throw new ParseException("claim scope must exist and not be null", 0);
}
//Voluntary fields
if (acClaimsSet.getClaims().containsKey(KEY_CLAIMS)) {
acClaimsSet.getJSONObjectClaim(KEY_CLAIMS);
}
if (acClaimsSet.getClaims().containsKey(KEY_NONCE)) {
acClaimsSet.getStringClaim(KEY_NONCE);
}
return new AuthorizeCodeClaimsSet(acClaimsSet);
}