Example usage for org.apache.shiro.web.util WebUtils getHttpResponse

List of usage examples for org.apache.shiro.web.util WebUtils getHttpResponse

Introduction

In this page you can find the example usage for org.apache.shiro.web.util WebUtils getHttpResponse.

Prototype

public static HttpServletResponse getHttpResponse(Object requestPairSource) 

Source Link

Usage

From source file:org.sonatype.nexus.security.StatelessAndStatefulWebSessionManager.java

License:Open Source License

@Override
protected void onStart(Session session, SessionContext context) {
    if (!WebUtils.isHttp(context)) {
        log.debug("SessionContext argument is not HTTP compatible or does not have an HTTP request/response "
                + "pair. No session ID cookie will be set.");
        return;// ww  w. j  a  va 2s  .  co  m

    }
    HttpServletRequest request = WebUtils.getHttpRequest(context);
    HttpServletResponse response = WebUtils.getHttpResponse(context);

    if (isSessionIdCookieEnabled(request, response)) {
        Serializable sessionId = session.getId();
        storeSessionId(sessionId, request, response);
    } else {
        log.debug("Session ID cookie is disabled.  No cookie has been set for new session with id {}",
                session.getId());
    }

    request.removeAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE);
    request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_IS_NEW, Boolean.TRUE);
}

From source file:org.tolven.shiro.web.session.mgt.TolvenWebSessionManager.java

License:Open Source License

@Override
protected void onStart(Session session, SessionContext context) {
    super.onStart(session, context);
    HttpServletRequest request = WebUtils.getHttpRequest(context);
    HttpServletResponse response = WebUtils.getHttpResponse(context);
    //Remove cookie added by super class
    Cookie template = getSessionIdCookie();
    Cookie cookie = new SimpleCookie(template);
    cookie.removeFrom(request, response);
    /*//from ww w. j  a  v  a  2s. com
     * Now place the secret key in a cookie by combining it with the sessionId using a
     * two way algorithm
     */
    if (logger.isDebugEnabled()) {
        logger.debug("Creating secret key cookie for cookie template name: " + template.getName());
    }
    String sessionId = session.getId().toString();
    cookie.setValue(SecretKeyThreadLocal.getExtendedSessionId(sessionId, SecretKeyThreadLocal.get()));
    cookie.saveTo(request, response);
    if (logger.isDebugEnabled()) {
        logger.debug("Saved secret key cookie to response for session: " + sessionId);
    }
}