当前位置: 首页>>代码示例>>Java>>正文


Java WebUtils.getHttpRequest方法代码示例

本文整理汇总了Java中org.apache.shiro.web.util.WebUtils.getHttpRequest方法的典型用法代码示例。如果您正苦于以下问题:Java WebUtils.getHttpRequest方法的具体用法?Java WebUtils.getHttpRequest怎么用?Java WebUtils.getHttpRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.web.util.WebUtils的用法示例。


在下文中一共展示了WebUtils.getHttpRequest方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSession

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
public Session getSession(SessionKey key) throws SessionException {
    if (!WebUtils.isHttp(key)) {
        String msg = "SessionKey must be an HTTP compatible implementation.";
        throw new IllegalArgumentException(msg);
    }

    HttpServletRequest request = WebUtils.getHttpRequest(key);

    Session session = null;

    HttpSession httpSession = request.getSession(false);
    if (httpSession != null) {
        session = createSession(httpSession, request.getRemoteHost());
    }

    return session;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:18,代码来源:ServletContainerSessionManager.java

示例2: createSession

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * @since 1.0
 */
protected Session createSession(SessionContext sessionContext) throws AuthorizationException {
    if (!WebUtils.isHttp(sessionContext)) {
        String msg = "SessionContext must be an HTTP compatible implementation.";
        throw new IllegalArgumentException(msg);
    }

    HttpServletRequest request = WebUtils.getHttpRequest(sessionContext);

    HttpSession httpSession = request.getSession();

    //SHIRO-240: DO NOT use the 'globalSessionTimeout' value here on the acquired session.
    //see: https://issues.apache.org/jira/browse/SHIRO-240

    String host = getHost(sessionContext);

    return createSession(httpSession, host);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:21,代码来源:ServletContainerSessionManager.java

示例3: onStart

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * Stores the Session's ID, usually as a Cookie, to associate with future requests.
 *
 * @param session the session that was just {@link #createSession created}.
 */
@Override
protected void onStart(Session session, SessionContext context) {
    super.onStart(session, 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;

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

    if (isSessionIdCookieEnabled()) {
        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);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:29,代码来源:DefaultWebSessionManager.java

示例4: rememberSerializedIdentity

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * Base64-encodes the specified serialized byte array and sets that base64-encoded String as the cookie value.
 * <p/>
 * The {@code subject} instance is expected to be a {@link WebSubject} instance with an HTTP Request/Response pair
 * so an HTTP cookie can be set on the outgoing response.  If it is not a {@code WebSubject} or that
 * {@code WebSubject} does not have an HTTP Request/Response pair, this implementation does nothing.
 *
 * @param subject    the Subject for which the identity is being serialized.
 * @param serialized the serialized bytes to be persisted.
 */
protected void rememberSerializedIdentity(Subject subject, byte[] serialized) {

    if (!WebUtils.isHttp(subject)) {
        if (log.isDebugEnabled()) {
            String msg = "Subject argument is not an HTTP-aware instance.  This is required to obtain a servlet " +
                    "request and response in order to set the rememberMe cookie. Returning immediately and " +
                    "ignoring rememberMe operation.";
            log.debug(msg);
        }
        return;
    }


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

    //base 64 encode it and store as a cookie:
    String base64 = Base64.encodeToString(serialized);

    Cookie template = getCookie(); //the class attribute is really a template for the outgoing cookies
    Cookie cookie = new SimpleCookie(template);
    cookie.setValue(base64);
    cookie.saveTo(request, response);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:35,代码来源:CookieRememberMeManager.java

示例5: rememberSerializedIdentity

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected void rememberSerializedIdentity(Subject subject, byte[] serialized) {
    if (!WebUtils.isHttp(subject)) {
        if (LOGGER.isDebugEnabled()) {
            String msg = "Subject argument is not an HTTP-aware instance.  This is required to obtain a servlet " +
                    "request and response in order to set the rememberMe cookie. Returning immediately and " +
                    "ignoring rememberMe operation.";
            LOGGER.debug(msg);
        }
        
        return;
    }


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

    // base 64 encode it and store as a cookie:
    String base64 = Base64.encodeToString(serialized);

    // the class attribute is really a template for the outgoing cookies
    Cookie cookie = getCookie(); 
    cookie.setValue(base64);
    cookie.saveTo(request, response);
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:26,代码来源:CookieRememberMeManager.java

示例6: onStart

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected void onStart(final Session session, final SessionContext context) {
    if (!WebUtils.isHttp(context)) {
        LOGGER.debug("SessionContext argument is not HTTP compatible or does not have an HTTP request/response " +
                "pair. No session ID cookie will be set.");
        return;
    }
    
    final HttpServletRequest request = WebUtils.getHttpRequest(context);
    final HttpServletResponse response = WebUtils.getHttpResponse(context);

    if (isSessionIdCookieEnabled()) {
        final Serializable sessionId = session.getId();
        storeSessionId(sessionId, request, response);
    } else {
        LOGGER.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);
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:22,代码来源:DefaultWebSessionManager.java

示例7: start

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
public Session start( SessionContext context ) throws AuthorizationException {
    if ( !WebUtils.isHttp( context ) ) {
        String msg = "SessionContext must be an HTTP compatible implementation.";
        throw new IllegalArgumentException( msg );
    }

    HttpServletRequest request = WebUtils.getHttpRequest( context );

    String host = getHost( context );

    Session session = createSession( request, host );
    request.setAttribute( REQUEST_ATTRIBUTE_KEY, session );

    return session;
}
 
开发者ID:apache,项目名称:usergrid,代码行数:17,代码来源:HttpRequestSessionManager.java

示例8: onStop

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected void onStop(Session session, SessionKey key) {
    super.onStop(session, key);
    if (WebUtils.isHttp(key)) {
        HttpServletRequest request = WebUtils.getHttpRequest(key);
        HttpServletResponse response = WebUtils.getHttpResponse(key);
        log.debug("Session has been stopped (subject logout or explicit stop).  Removing session ID cookie.");
        removeSessionIdCookie(request, response);
    } else {
        log.debug("SessionKey argument is not HTTP compatible or does not have an HTTP request/response " +
                "pair. Session ID cookie will not be removed due to stopped session.");
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:14,代码来源:DefaultWebSessionManager.java

示例9: onStart

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * Stores the Session's ID, usually as a Cookie, to associate with future
 * requests.
 *
 * @param session
 *            the session that was just {@link #createSession created}.
 */
@Override
protected void onStart(Session session, SessionContext context) {
	super.onStart(session, 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;

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

	if (isSessionIdCookieEnabled()) {
		Serializable sessionId = session.getId();
		if (sessionId != null) {
			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);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:34,代码来源:SimpleWebSessionManager.java

示例10: onStop

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected void onStop(Session session, SessionKey key) {
	super.onStop(session, key);
	if (WebUtils.isHttp(key)) {
		HttpServletRequest request = WebUtils.getHttpRequest(key);
		HttpServletResponse response = WebUtils.getHttpResponse(key);
		log.debug("Session has been stopped (subject logout or explicit stop).  Removing session ID cookie.");
		removeSessionIdCookie(request, response);
	} else {
		log.debug("SessionKey argument is not HTTP compatible or does not have an HTTP request/response "
				+ "pair. Session ID cookie will not be removed due to stopped session.");
	}
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:14,代码来源:SimpleWebSessionManager.java

示例11: getSession

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
public Session getSession( SessionKey key ) throws SessionException {
    if ( !WebUtils.isHttp( key ) ) {
        String msg = "SessionKey must be an HTTP compatible implementation.";
        throw new IllegalArgumentException( msg );
    }

    HttpServletRequest request = WebUtils.getHttpRequest( key );

    return ( Session ) request.getAttribute( REQUEST_ATTRIBUTE_KEY );
}
 
开发者ID:apache,项目名称:usergrid,代码行数:12,代码来源:HttpRequestSessionManager.java

示例12: getRememberedSerializedIdentity

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * Returns a previously serialized identity byte array or {@code null} if the byte array could not be acquired.
 * This implementation retrieves an HTTP cookie, Base64-decodes the cookie value, and returns the resulting byte
 * array.
 * <p/>
 * The {@code SubjectContext} instance is expected to be a {@link WebSubjectContext} instance with an HTTP
 * Request/Response pair so an HTTP cookie can be retrieved from the incoming request.  If it is not a
 * {@code WebSubjectContext} or that {@code WebSubjectContext} does not have an HTTP Request/Response pair, this
 * implementation returns {@code null}.
 *
 * @param subjectContext the contextual data, usually provided by a {@link Subject.Builder} implementation, that
 *                       is being used to construct a {@link Subject} instance.  To be used to assist with data
 *                       lookup.
 * @return a previously serialized identity byte array or {@code null} if the byte array could not be acquired.
 */
protected byte[] getRememberedSerializedIdentity(SubjectContext subjectContext) {

    if (!WebUtils.isHttp(subjectContext)) {
        if (log.isDebugEnabled()) {
            String msg = "SubjectContext argument is not an HTTP-aware instance.  This is required to obtain a " +
                    "servlet request and response in order to retrieve the rememberMe cookie. Returning " +
                    "immediately and ignoring rememberMe operation.";
            log.debug(msg);
        }
        return null;
    }

    WebSubjectContext wsc = (WebSubjectContext) subjectContext;
    if (isIdentityRemoved(wsc)) {
        return null;
    }

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

    String base64 = getCookie().readValue(request, response);
    // Browsers do not always remove cookies immediately (SHIRO-183)
    // ignore cookies that are scheduled for removal
    if (Cookie.DELETED_COOKIE_VALUE.equals(base64)) return null;

    if (base64 != null) {
        base64 = ensurePadding(base64);
        if (log.isTraceEnabled()) {
            log.trace("Acquired Base64 encoded identity [" + base64 + "]");
        }
        byte[] decoded = Base64.decode(base64);
        if (log.isTraceEnabled()) {
            log.trace("Base64 decoded byte array length: " + (decoded != null ? decoded.length : 0) + " bytes.");
        }
        return decoded;
    } else {
        //no cookie set - new site visitor?
        return null;
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:56,代码来源:CookieRememberMeManager.java

示例13: forgetIdentity

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * Removes the 'rememberMe' cookie from the associated {@link WebSubject}'s request/response pair.
 * <p/>
 * The {@code subject} instance is expected to be a {@link WebSubject} instance with an HTTP Request/Response pair.
 * If it is not a {@code WebSubject} or that {@code WebSubject} does not have an HTTP Request/Response pair, this
 * implementation does nothing.
 *
 * @param subject the subject instance for which identity data should be forgotten from the underlying persistence
 */
protected void forgetIdentity(Subject subject) {
    if (WebUtils.isHttp(subject)) {
        HttpServletRequest request = WebUtils.getHttpRequest(subject);
        HttpServletResponse response = WebUtils.getHttpResponse(subject);
        forgetIdentity(request, response);
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:17,代码来源:CookieRememberMeManager.java


注:本文中的org.apache.shiro.web.util.WebUtils.getHttpRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。