Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ObjectMapper from JSONParser to support JSON objects and arrays as claims #11723

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.nimbusds.jwt.JWTClaimsSet;
import net.minidev.json.parser.JSONParser;
import net.minidev.json.parser.ParseException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -226,12 +228,13 @@ public String buildBody(TokenValidationContext validationContext) throws APIMana
String claimURI = it.next();
String claimVal = standardClaims.get(claimURI);
List<String> claimList = new ArrayList<String>();
if (claimVal != null && claimVal.contains("{")) {
ObjectMapper mapper = new ObjectMapper();
if (claimVal != null && ((claimVal.startsWith("[") && claimVal.endsWith("]"))
|| claimVal.contains("{"))) {
JSONParser jsonParser = new JSONParser(JSONParser.ACCEPT_SIMPLE_QUOTE);
try {
Map<String, String> map = mapper.readValue(claimVal, Map.class);
jwtClaimsSetBuilder.claim(claimURI, map);
} catch (IOException e) {
Object jsonObj = jsonParser.parse(claimVal);
jwtClaimsSetBuilder.claim(claimURI, jsonObj);
} catch (ParseException e) {
// Exception isn't thrown in order to generate jwt without claim, even if an error is
// occurred during the retrieving claims.
log.error(String.format("Error while reading claim values for %s", claimVal), e);
Expand Down