Revision 49847
Added by Sofia Baltzi over 6 years ago
JWTGenerator.java | ||
---|---|---|
46 | 46 |
JsonObject userInfo = authOIDC.getUserInfo().getSource(); |
47 | 47 |
Claims claims = Jwts.claims().setSubject(authOIDC.getUserInfo().getSub()); |
48 | 48 |
claims.put("fullname", URLEncoder.encode(authOIDC.getUserInfo().getName(), "UTF-8") + ""); |
49 |
claims.put("firstname", URLEncoder.encode(authOIDC.getUserInfo().getGivenName(), "UTF-8") + ""); |
|
50 |
claims.put("lastname", URLEncoder.encode(authOIDC.getUserInfo().getFamilyName(), "UTF-8") + ""); |
|
49 |
|
|
50 |
if (authOIDC.getUserInfo().getGivenName() == null){ |
|
51 |
logger.info("User: " + authOIDC.getUserInfo().getName() + "doesn't have first name"); |
|
52 |
claims.put("firstname", URLEncoder.encode(" ", "UTF-8") + ""); |
|
53 |
} else { |
|
54 |
claims.put("firstname", URLEncoder.encode(authOIDC.getUserInfo().getGivenName(), "UTF-8") + ""); |
|
55 |
|
|
56 |
} |
|
57 |
if (authOIDC.getUserInfo().getFamilyName() == null){ |
|
58 |
logger.info("User: " + authOIDC.getUserInfo().getName() + "doesn't have first name"); |
|
59 |
claims.put("lastname", URLEncoder.encode(" ", "UTF-8") + ""); |
|
60 |
} else { |
|
61 |
claims.put("lastname", URLEncoder.encode(authOIDC.getUserInfo().getFamilyName(), "UTF-8") + ""); |
|
62 |
|
|
63 |
} |
|
51 | 64 |
claims.put("email", authOIDC.getUserInfo().getEmail() + ""); |
52 |
claims.put("role", URLEncoder.encode(userInfo.getAsJsonArray("edu_person_entitlements").toString(), "UTF-8") + ""); |
|
65 |
// claims.put("role", URLEncoder.encode(userInfo.getAsJsonArray("edu_person_entitlements").toString(), "UTF-8") + ""); |
|
66 |
// |
|
53 | 67 |
|
68 |
// if (userInfo.getAsJsonArray("eduPersonScopedAffiliation").toString() != null) { |
|
69 |
// claims.put("role", URLEncoder.encode(userInfo.getAsJsonArray("edu_person_scoped_affiliations").toString(), "UTF-8") + ""); |
|
70 |
// } |
|
71 |
|
|
72 |
if (userInfo.getAsJsonArray("edu_person_entitlements") == null){ |
|
73 |
logger.info("User: " + authOIDC.getUserInfo().getName() + "doesn't have role"); |
|
74 |
claims.put("role", URLEncoder.encode(" ", "UTF-8") + ""); |
|
75 |
} else { |
|
76 |
claims.put("role", URLEncoder.encode(userInfo.getAsJsonArray("edu_person_entitlements").toString(), "UTF-8") + ""); |
|
77 |
} |
|
78 |
|
|
54 | 79 |
//TODO remove, We don't need it but if we are going to use it, we need to check if the user has affiliation |
55 | 80 |
//claims.put("edu_person_scoped_affiliations", URLEncoder.encode(userInfo.getAsJsonArray("edu_person_scoped_affiliations").toString(), "UTF-8") + ""); |
56 | 81 |
|
Also available in: Unified diff
Add error checking for empty first ame, last name and role