1
1
package org .mitre .openid .connect .view ;
2
2
3
+ import java .lang .reflect .Field ;
3
4
import java .lang .reflect .InvocationTargetException ;
4
5
import java .lang .reflect .Method ;
5
6
import java .util .Map .Entry ;
6
7
import java .util .Set ;
7
8
9
+ import org .mitre .openid .connect .model .DefaultUserInfo ;
8
10
import org .mitre .openid .connect .model .UserInfo ;
9
11
import org .mitre .openid .connect .service .ScopeClaimTranslationService ;
10
12
import org .slf4j .Logger ;
11
13
import org .slf4j .LoggerFactory ;
14
+ import org .springframework .util .ReflectionUtils ;
12
15
13
16
import com .google .common .base .CaseFormat ;
14
17
import com .google .common .collect .Sets ;
@@ -19,7 +22,7 @@ public class UserInfoSerializer {
19
22
20
23
private static Logger logger = LoggerFactory .getLogger (UserInfoSerializer .class );
21
24
22
- private ScopeClaimTranslationService translator = new ScopeClaimTranslationService ();
25
+ private static ScopeClaimTranslationService translator = new ScopeClaimTranslationService ();
23
26
24
27
/**
25
28
* Build a JSON response according to the request object received.
@@ -67,6 +70,8 @@ public static JsonObject toJsonFromRequestObj(UserInfo ui, Set<String> scope, Js
67
70
//TODO: is there a way to use bean processors to do bean.getfield(name)?
68
71
//Method reflection is OK, but need a service to translate scopes into claim names => field names
69
72
73
+
74
+
70
75
// TODO: this method is likely to be fragile if the data model changes at all
71
76
72
77
//For each claim found, add it if not already present
@@ -75,6 +80,14 @@ public static JsonObject toJsonFromRequestObj(UserInfo ui, Set<String> scope, Js
75
80
if (!obj .has (claimName )) {
76
81
String value = "" ;
77
82
83
+ String fieldName = translator .getFieldNameForClaim (claimName );
84
+ Field field = ReflectionUtils .findField (DefaultUserInfo .class , fieldName );
85
+
86
+ Object val = ReflectionUtils .getField (field , userinfo );
87
+
88
+ //TODO:how to convert val to a String? Most claims can be converted directly; address is compound
89
+
90
+
78
91
//Process claim names to go from "claim_name" to "ClaimName"
79
92
String camelClaimName = CaseFormat .LOWER_UNDERSCORE .to (CaseFormat .UPPER_CAMEL , claimName );
80
93
//Now we have "getClaimName"
0 commit comments