Search in sources :

Example 1 with SimplePrincipal

use of org.gluu.oxauth.client.authentication.SimplePrincipal in project oxTrust by GluuFederation.

the class HttpServletRequestWrapperFilter method retrievePrincipalFromSessionOrRequest.

protected SimplePrincipal retrievePrincipalFromSessionOrRequest(final ServletRequest servletRequest) {
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpSession session = request.getSession(false);
    final OAuthData oAuthData = (OAuthData) (session == null ? request.getAttribute(Configuration.SESSION_OAUTH_DATA) : session.getAttribute(Configuration.SESSION_OAUTH_DATA));
    if (oAuthData == null) {
        log.trace("There is no OAuthData in session");
        return null;
    }
    SimplePrincipal principanl = new SimplePrincipal(oAuthData.getUserUid());
    return principanl;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) OAuthData(org.gluu.oxauth.client.session.OAuthData) SimplePrincipal(org.gluu.oxauth.client.authentication.SimplePrincipal)

Example 2 with SimplePrincipal

use of org.gluu.oxauth.client.authentication.SimplePrincipal in project oxTrust by GluuFederation.

the class HttpServletRequestWrapperFilter method doFilter.

/**
     * Wraps the HttpServletRequest in a wrapper class that delegates
     * <code>request.getRemoteUser</code> to the underlying OAuthData object
     * stored in the user session.
     */
@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
    final SimplePrincipal principal = retrievePrincipalFromSessionOrRequest(servletRequest);
    if (principal == null) {
        log.trace("There is no principal");
        filterChain.doFilter(servletRequest, servletResponse);
    } else {
        filterChain.doFilter(new OAuthHttpServletRequestWrapper((HttpServletRequest) servletRequest, principal), servletResponse);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SimplePrincipal(org.gluu.oxauth.client.authentication.SimplePrincipal)

Aggregations

HttpServletRequest (javax.servlet.http.HttpServletRequest)2 SimplePrincipal (org.gluu.oxauth.client.authentication.SimplePrincipal)2 HttpSession (javax.servlet.http.HttpSession)1 OAuthData (org.gluu.oxauth.client.session.OAuthData)1