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


Java WebUtils.saveRequest方法代码示例

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


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

示例1: redirectLogin

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected void redirectLogin(ServletRequest request, ServletResponse response) throws IOException {
      WebUtils.saveRequest(request);
      String path = WebUtils.getContextPath((HttpServletRequest) request);
      String url = loginUrl;
      if (StringUtils.isNotBlank(path) && path.length() > 1) {
      	url = path + url;
}
      
      if (isAjaxRequest((HttpServletRequest) request)) {
      	response.setContentType("application/json;charset=UTF-8");
	Gson gson = new Gson();
	response.getWriter().print(gson.toJson(Data.failure("您还没有登录!")));
      } else {
      	response.getWriter().write(new Formatter().format(JS, url).toString());
      }
  }
 
开发者ID:ThomasYangZi,项目名称:mblog,代码行数:17,代码来源:AuthenticatedFilter.java

示例2: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
	log.debug("username[{}] SimpleAuthFilter denied,未登陆,跳转到登陆页面");
	Subject subject = SecurityUtils.getSubject();
	subject.logout();
	/**
	 * 保存Request,用来保存当前Request,然后登录后可以跳转到当前浏览的页面. 比如:
	 * 我要访问一个URL地址,/admin/index.html,这个页面是要登录.然后要跳转到登录页面,但是登录后要跳转回来到/admin/
	 * index.html这个地址,怎么办?
	 * 传统的解决方法是变成/user/login.shtml?redirectUrl=/admin/index.html.
	 * shiro的解决办法不是这样的.需要:<code>WebUtils.getSavedRequest(request);</code>
	 * 然后:{@link UserLoginController.submitLogin(...)}中的
	 * <code>String url = WebUtils.getSavedRequest(request).getRequestUrl();</code>
	 */
	WebUtils.saveRequest(request);
	// 再重定向
	WebUtils.issueRedirect(request, response, "/toLogin.htm");
	return false;
}
 
开发者ID:ls960972314,项目名称:report,代码行数:20,代码来源:SimpleAuthFilter.java

示例3: unauthenticated

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@ExceptionHandler(value = {UnauthenticatedException.class})
public RedirectView unauthenticated(WebRequest request) {
    // @RequiresUser등으로 로그인으로 강제 전환이 이루어질때, 다시 돌아올 위치를 저장.
    if (request instanceof ServletWebRequest) {
        ServletWebRequest swr = (ServletWebRequest) request;
        if (swr.getRequest() != null) {
            // NOTE: ...이거 이외에도 ㅎㅎㅎ 페이지들 jsp으로 그대로 redirect해버림.
            final String s = ObjectUtils.toString(swr.getRequest().getRequestURL());
            if (false == (s.startsWith("/WEB-INF/") && s.endsWith(".jsp"))) {
                LOG.debug(String.format("SAVE REQUEST FOR LOGIN-SUCCESS-REDIRECT = [%s]", swr.getRequest().getRequestURL()));
                WebUtils.saveRequest(swr.getRequest());
            }
        }
    }
    return new RedirectView(String.format("%s/a/error/unauthenticated", WebappPath.getWebappPath()));
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:17,代码来源:ErrorController.java

示例4: saveRequest

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * Convenience method merely delegates to
 * {@link WebUtils#saveRequest(javax.servlet.ServletRequest) WebUtils.saveRequest(request)} to save the request
 * state for reuse later.  This is mostly used to retain user request state when a redirect is issued to
 * return the user to their originally requested url/resource.
 * <p/>
 * If you need to save and then immediately redirect the user to login, consider using
 * {@link #saveRequestAndRedirectToLogin(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
 * saveRequestAndRedirectToLogin(request,response)} directly.
 *
 * @param request the incoming ServletRequest to save for re-use later (for example, after a redirect).
 */
protected void saveRequest(ServletRequest request) {
    WebUtils.saveRequest(request);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:16,代码来源:AccessControlFilter.java


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