Skip to content

Commit bf3e003

Browse files
author
Justin Richer
committed
initial refactor of userinfoview for new model components
1 parent 9debf14 commit bf3e003

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

openid-connect-server/src/main/java/org/mitre/openid/connect/view/UserInfoView.java

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public class UserInfoView extends AbstractView {
6161

6262
private static Logger logger = LoggerFactory.getLogger(UserInfoView.class);
6363

64-
@Autowired
65-
private JwtEncryptionAndDecryptionService encryptionService;
66-
6764
private Gson gson = new GsonBuilder()
6865
.setExclusionStrategies(new ExclusionStrategy() {
6966

@@ -117,29 +114,17 @@ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletReq
117114

118115
out = response.getWriter();
119116

120-
if (model.get("requestObject") != null) {
121-
122-
try {
123-
// FIXME: re-parse the request object
124-
String jwtString = (String)model.get("requestObject");
125-
JWT requestObject = JWTParser.parse(jwtString);
126-
if (requestObject instanceof EncryptedJWT) {
127-
// we need to re-decrypt it :(
128-
encryptionService.decryptJwt((EncryptedJWT) requestObject);
129-
}
130-
131-
// FIXME: move to GSON for easier processing
132-
JsonObject obj = (JsonObject) jsonParser.parse(requestObject.getJWTClaimsSet().toJSONObject().toJSONString());
133-
134-
gson.toJson(toJsonFromRequestObj(userInfo, scope, obj, claimsRequest), out);
135-
} catch (JsonSyntaxException e) {
136-
logger.error("JsonSyntaxException in UserInfoView.java: ", e);
137-
} catch (JsonIOException e) {
138-
logger.error("JsonIOException in UserInfoView.java: ", e);
139-
} catch (ParseException e) {
140-
logger.error("ParseException in UserInfoView.java: ", e);
141-
}
117+
JsonObject authorizedClaims = null;
118+
JsonObject requestedClaims = null;
119+
if (model.get("authorizedClaims") != null) {
120+
authorizedClaims = jsonParser.parse((String) model.get("authorizedClaims")).getAsJsonObject();
121+
}
122+
if (model.get("requestedClaims") != null) {
123+
requestedClaims = jsonParser.parse((String) model.get("requestedClaims")).getAsJsonObject();
124+
}
125+
if (authorizedClaims != null || requestedClaims != null) {
142126

127+
gson.toJson(toJsonFromRequestObj(userInfo, scope, authorizedClaims, requestedClaims), out);
143128
} else {
144129

145130
gson.toJson(toJson(userInfo, scope), out);
@@ -214,22 +199,19 @@ private JsonObject toJson(UserInfo ui, Set<String> scope) {
214199
*
215200
* @param ui
216201
* @param scope
217-
* @param requestObj
218-
* @param claimsRequest the claims request parameter object.
202+
* @param authorizedClaims
203+
* @param requestedClaims the claims request parameter object.
219204
* @return
220205
*/
221-
private JsonObject toJsonFromRequestObj(UserInfo ui, Set<String> scope, JsonObject requestObj, JsonObject claimsRequest) {
206+
private JsonObject toJsonFromRequestObj(UserInfo ui, Set<String> scope, JsonObject authorizedClaims, JsonObject requestedClaims) {
222207

208+
// get the base object
223209
JsonObject obj = toJson(ui, scope);
224210

225-
//Process list of requested claims out of the request object
226-
JsonElement claims = requestObj.get("claims");
227-
if (claims == null || !claims.isJsonObject()) {
228-
return obj;
229-
}
230-
231-
JsonElement userinfo = claims.getAsJsonObject().get("userinfo");
232-
if (userinfo == null || !userinfo.isJsonObject()) {
211+
JsonObject userinfoAuthorized = authorizedClaims.getAsJsonObject().get("userinfo").getAsJsonObject();
212+
JsonObject userinfoRequested = requestedClaims.getAsJsonObject().get("userinfo").getAsJsonObject();
213+
214+
if (userinfoAuthorized == null || !userinfoAuthorized.isJsonObject()) {
233215
return obj;
234216
}
235217

@@ -240,10 +222,10 @@ private JsonObject toJsonFromRequestObj(UserInfo ui, Set<String> scope, JsonObje
240222
// the same claim but have different 'individual claim values', causing the Entry<> to be unequal,
241223
// which doesn't allow the use of the more compact Sets.intersection() type method.
242224
Set<Entry<String, JsonElement>> requestClaimsSet = Sets.newHashSet();
243-
if (claimsRequest != null) {
225+
if (requestedClaims != null) {
244226

245-
for (Entry<String, JsonElement> entry : userinfo.getAsJsonObject().entrySet()) {
246-
if (claimsRequest.has(entry.getKey())) {
227+
for (Entry<String, JsonElement> entry : userinfoAuthorized.getAsJsonObject().entrySet()) {
228+
if (userinfoRequested.has(entry.getKey())) {
247229
requestClaimsSet.add(entry);
248230
}
249231
}

0 commit comments

Comments
 (0)