本文整理汇总了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());
}
}
示例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;
}
示例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()));
}
示例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);
}