Search in sources :

Example 1 with AssertionImpl

use of com.ctrip.infosec.sso.client.principal.AssertionImpl in project x-pipe by ctripcorp.

the class CtripSSOFilter method getAssertionIncache.

private Assertion getAssertionIncache(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (cookies == null) {
        return null;
    }
    String memCacheAssertionID = null;
    String cookieName = generateCookieName(request.getContextPath());
    for (Cookie cookie : cookies) {
        if (cookie.getName().equalsIgnoreCase(cookieName)) {
            memCacheAssertionID = cookie.getValue();
            break;
        }
    }
    Assertion assertionInCache = null;
    try {
        CloseableHttpResponse response = httpClient.execute(new HttpGet(casServerUrlPrefix + "/client/principal?principalId=" + memCacheAssertionID + "&callback=" + serverName));
        String result = EntityUtils.toString(response.getEntity(), "utf-8");
        JSONObject jsonObject = JSON.parseObject(result);
        if (jsonObject.getJSONObject("result") != null) {
            Map user = jsonObject.getJSONObject("result");
            assertionInCache = new AssertionImpl(new AttributePrincipalImpl((String) user.get("name"), user));
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
    }
    return assertionInCache;
}
Also used : Cookie(javax.servlet.http.Cookie) AssertionImpl(com.ctrip.infosec.sso.client.principal.AssertionImpl) JSONObject(com.alibaba.fastjson.JSONObject) HttpGet(org.apache.http.client.methods.HttpGet) Assertion(com.ctrip.infosec.sso.client.principal.Assertion) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) AttributePrincipalImpl(com.ctrip.infosec.sso.client.principal.AttributePrincipalImpl) TicketValidationException(com.ctrip.infosec.sso.client.validate.TicketValidationException) IOException(java.io.IOException)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 Assertion (com.ctrip.infosec.sso.client.principal.Assertion)1 AssertionImpl (com.ctrip.infosec.sso.client.principal.AssertionImpl)1 AttributePrincipalImpl (com.ctrip.infosec.sso.client.principal.AttributePrincipalImpl)1 TicketValidationException (com.ctrip.infosec.sso.client.validate.TicketValidationException)1 IOException (java.io.IOException)1 Cookie (javax.servlet.http.Cookie)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1