diff --git a/openid-connect-common/src/main/java/org/mitre/openid/connect/web/UserInfoInterceptor.java b/openid-connect-common/src/main/java/org/mitre/openid/connect/web/UserInfoInterceptor.java index 427570788..240685cfe 100644 --- a/openid-connect-common/src/main/java/org/mitre/openid/connect/web/UserInfoInterceptor.java +++ b/openid-connect-common/src/main/java/org/mitre/openid/connect/web/UserInfoInterceptor.java @@ -31,6 +31,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; +import com.google.gson.Gson; + /** * Injects the UserInfo object for the current user into the current model's context, if both exist. Allows JSPs and the like to call "userInfo.name" and other fields. * @@ -38,6 +40,8 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; * */ public class UserInfoInterceptor extends HandlerInterceptorAdapter { + + private Gson gson = new Gson(); @Autowired private UserInfoService userInfoService; @@ -53,6 +57,8 @@ public class UserInfoInterceptor extends HandlerInterceptorAdapter { // if they're logging into this server from a remote OIDC server, pass through their user info OIDCAuthenticationToken oidc = (OIDCAuthenticationToken) p; modelAndView.addObject("userInfo", oidc.getUserInfo()); + // TODO: this should use the same serializer as UserInfoView (#488) + modelAndView.addObject("userInfoJson", gson.toJson(oidc.getUserInfo())); } else { if (p != null && p.getName() != null) { // don't bother checking if we don't have a principal @@ -62,6 +68,8 @@ public class UserInfoInterceptor extends HandlerInterceptorAdapter { // if we have one, inject it so views can use it if (user != null) { modelAndView.addObject("userInfo", user); + // TODO: this should use the same serializer as UserInfoView (#488) + modelAndView.addObject("userInfoJson", gson.toJson(user)); } } } diff --git a/openid-connect-server/src/main/webapp/WEB-INF/tags/header.tag b/openid-connect-server/src/main/webapp/WEB-INF/tags/header.tag index 36dada829..10fee29c1 100644 --- a/openid-connect-server/src/main/webapp/WEB-INF/tags/header.tag +++ b/openid-connect-server/src/main/webapp/WEB-INF/tags/header.tag @@ -107,6 +107,11 @@ // safely set the title of the application function setPageTitle(title) { document.title = "${config.topbarTitle} - " + title; + } + + // get the info of the current user, if available (null otherwise) + function getUserInfo() { + return ${userInfoJson}; }