Search in sources :

Example 1 with ScaleTokenUser

use of com.tremolosecurity.scalejs.token.data.ScaleTokenUser in project OpenUnison by TremoloSecurity.

the class ScaleToken method doFilter.

@Override
public void doFilter(HttpFilterRequest request, HttpFilterResponse response, HttpFilterChain chain) throws Exception {
    Gson gson = new Gson();
    request.getServletRequest().setAttribute("com.tremolosecurity.unison.proxy.noRedirectOnError", "com.tremolosecurity.unison.proxy.noRedirectOnError");
    if (request.getRequestURI().endsWith("/token/config")) {
        response.setContentType("application/json");
        ScaleJSUtils.addCacheHeaders(response);
        response.getWriter().println(gson.toJson(scaleConfig).trim());
    } else if (request.getMethod().equalsIgnoreCase("GET") && request.getRequestURI().endsWith("/token/user")) {
        AuthInfo userData = ((AuthController) request.getSession().getAttribute(ProxyConstants.AUTH_CTL)).getAuthInfo();
        ScaleTokenUser stu = new ScaleTokenUser();
        Attribute displayNameAttribute = userData.getAttribs().get(this.scaleConfig.getDisplayNameAttribute());
        if (displayNameAttribute != null) {
            stu.setDisplayName(displayNameAttribute.getValues().get(0));
        } else {
            stu.setDisplayName("Unknown");
        }
        stu.setToken(this.tokenLoader.loadToken(userData, request.getSession()));
        ScaleJSUtils.addCacheHeaders(response);
        response.setContentType("application/json");
        response.getWriter().println(gson.toJson(stu).trim());
    }
}
Also used : ScaleTokenUser(com.tremolosecurity.scalejs.token.data.ScaleTokenUser) AuthInfo(com.tremolosecurity.proxy.auth.AuthInfo) Attribute(com.tremolosecurity.saml.Attribute) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)1 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)1 Attribute (com.tremolosecurity.saml.Attribute)1 ScaleTokenUser (com.tremolosecurity.scalejs.token.data.ScaleTokenUser)1