[keycloak-user] Getting user information for a service behind a reverse proxy running keycloak

Subodh Joshi subodhcjoshi82 at gmail.com
Thu May 17 05:51:22 EDT 2018


We achieve  it like this way

        userId = httpRequest.getRemoteUser();
        CasAuthenticationToken castoken = (CasAuthenticationToken)
httpRequest.getUserPrincipal();
        String castgtToken =
castoken.getAssertion().getPrincipal().getAttributes().get("tgtToken").toString();

        log.info("CAS Logged in User "+userId);
        log.info("CAS Token Attribute-->
"+castoken.getAssertion().getPrincipal().getAttributes());
        password =
castoken.getAssertion().getPrincipal().getAttributes().get("password").toString();
        tgtToken = getToken(userId,castgtToken);
        String urlEncodeToken = URLEncoder.encode(tgtToken, "UTF-8");
       KeycloakSecurityContext securityContext = (KeycloakSecurityContext)
httpRequest.getAttribute(KeycloakSecurityContext.class.getName());
        System.out.println(httpRequest.getHeaderNames());
        Map<String, String> map = new HashMap<String, String>();

        Enumeration headerNames = httpRequest.getHeaderNames();
        while (headerNames.hasMoreElements()) {
            String key = (String) headerNames.nextElement();
            String value = httpRequest.getHeader(key);
            map.put(key, value);
        }
        System.out.println(map);
        if(map.containsKey("authorization")){
            tgtToken = map.get("authorization");
        }

You can separate out the code ,i simply copy-paste the code. Our JSF
application behind Kong/Nginx.

Thanks & regards

On Thu, May 17, 2018 at 2:10 PM Omri Tavor <omri.tavor at forcepoint.com>
wrote:

> Hi,
> Quick question. I have an Apache httpd server running the OIDC httpd
> adapter. This httpd server acts a reverse proxy to another Tomcat server
> running legacy JSF code (httpServletRequest).
> What would be the correct (and simplest) way of getting the user
> information from within that tomcat scope? (I've tried
> request.getUserPrincipal() but got a null value).
> I would appreciate any help!
> Omri.
> _______________________________________________
> keycloak-user mailing list
> keycloak-user at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/keycloak-user
>


-- 
Subodh Chandra Joshi
subodh1_joshi82 at yahoo.co.in
http://www.trendsinnews.com


More information about the keycloak-user mailing list