本文整理汇总了Java中org.apache.shiro.web.util.WebUtils.issueRedirect方法的典型用法代码示例。如果您正苦于以下问题:Java WebUtils.issueRedirect方法的具体用法?Java WebUtils.issueRedirect怎么用?Java WebUtils.issueRedirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.web.util.WebUtils
的用法示例。
在下文中一共展示了WebUtils.issueRedirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPreHandle
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
public boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
if (this.isAccessAllowed(request, response, mappedValue) && this.isLoginRequest(request, response)) {
if (((HttpServletRequest)request).getRequestURL().toString().endsWith(".json")){
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter out = response.getWriter();
out.println("{\"code\":200,\"info\":\"already logined\"}");
out.flush();
out.close();
}else {
WebUtils.issueRedirect(request,response,this.getSuccessUrl());
}
return false;
}
return super.onPreHandle(request, response, mappedValue);
}
示例2: issueSuccessRedirect
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected void issueSuccessRedirect(ServletRequest request, ServletResponse response)
throws Exception {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
String successUrl = req.getParameter(RETURN_URL);
if (StringUtils.isBlank(successUrl)) {
if (req.getRequestURI().startsWith(
req.getContextPath() + getAdminPrefix())) {
// 后台直接返回首页
successUrl = getAdminIndex();
// 清除SavedRequest
WebUtils.getAndClearSavedRequest(request);
WebUtils.issueRedirect(request, response, successUrl, null,true);
return;
} else {
successUrl = getSuccessUrl();
}
}
WebUtils.redirectToSavedRequest(req, res, successUrl);
}
示例3: onAccessDenied
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
String error = request.getParameter("error");
String errorDescription = request.getParameter("error_description");
if(!StringUtils.isEmpty(error)) {//如果服务端返回了错误
WebUtils.issueRedirect(request, response, failureUrl + "?error=" + error + "error_description=" + errorDescription);
return false;
}
Subject subject = getSubject(request, response);
if(!subject.isAuthenticated()) {
if(StringUtils.isEmpty(request.getParameter(authcCodeParam))) {
//如果用户没有身份验证,且没有auth code,则重定向到服务端授权
saveRequestAndRedirectToLogin(request, response);
return false;
}
}
return executeLogin(request, response);
}
示例4: onAccessDenied
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request,
ServletResponse response) throws Exception {
Subject subject = getSubject(request, response);
if (null == subject.getPrincipal()) {//表示没有登录,重定向到登录页面
saveRequest(request);
WebUtils.issueRedirect(request, response, ShiroUtils.LOGIN_URL);
} else {
if(ShiroUtils.isAjax(request)){
Map<String, Object> result = new HashMap<String, Object>();
result.put("status", "401");
result.put("message", "sorry,您没有权限");
result.put("url", ShiroUtils.UNAUTHORIZED);
ShiroUtils.writeJson(response, result);
}else
{
if (StringUtils.hasText(ShiroUtils.UNAUTHORIZED)) {//如果有未授权页面跳转过去
WebUtils.issueRedirect(request, response, ShiroUtils.UNAUTHORIZED);
} else {//否则返回401未授权状态码
WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
}
return Boolean.FALSE;
}
示例5: onAccessDenied
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request,
ServletResponse response) throws Exception {
//先退出
Subject subject = getSubject(request, response);
subject.logout();
/**
* shiro保存上次请求地址:
* WebUtils.getSavedRequest(request);
* 然后在需要使用的地方:String url = WebUtils.getSavedRequest(request).getRequestUrl();
*/
//判断是不是Ajax请求
if (ShiroUtils.isAjax(request) ) {
Map<String, Object> result = new HashMap<String, Object>();
logger.debug("当前用户已经被踢出,并且是Ajax请求!");
result.put("status", "403");
result.put("message", "您已经被踢出,请重新登录!");
result.put("url", ShiroUtils.LOGIN_URL);
ShiroUtils.writeJson(response, result);
}else
{
WebUtils.getSavedRequest(request);
//再重定向
WebUtils.issueRedirect(request, response, ShiroUtils.LOGIN_URL);
}
return false;
}
示例6: onAccessDenied
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request,
ServletResponse response) throws Exception {
Subject subject = getSubject(request, response);
if (subject.getPrincipal() == null) {//表示没有登录,重定向到登录页面
saveRequest(request);
WebUtils.issueRedirect(request, response, ShiroUtils.LOGIN_URL);
} else {
if(ShiroUtils.isAjax(request)){
Map<String, Object> result = new HashMap<String, Object>();
result.put("status", "401");
result.put("message", "sorry,您没有权限");
result.put("url", ShiroUtils.UNAUTHORIZED);
ShiroUtils.writeJson(response, result);
}else
{
if (StringUtils.hasText(ShiroUtils.UNAUTHORIZED)) {//如果有未授权页面跳转过去
WebUtils.issueRedirect(request, response, ShiroUtils.UNAUTHORIZED);
} else {//否则返回401未授权状态码
WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
}
return false;
}
示例7: onAccessDenied
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request,
ServletResponse response) throws Exception {
if(ShiroUtils.isAjax(request)){
Map<String, Object> result = new HashMap<String, Object>();
result.put("status", "401");
result.put("message", "非法操作");
result.put("url", ShiroUtils.INDEX_URL);
ShiroUtils.writeJson(response, result);
}else
{
if (StringUtils.hasText(ShiroUtils.INDEX_URL)) {//如果有未授权页面跳转过去
WebUtils.issueRedirect(request, response, ShiroUtils.INDEX_URL);
} else {//否则返回401未授权状态码
WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
return Boolean.FALSE;
}
示例8: 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;
}
示例9: issueSuccessRedirect
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected void issueSuccessRedirect(ServletRequest request,
ServletResponse response) throws Exception {
// Principal p = UserUtils.getPrincipal();
// if (p != null && !p.isMobileLogin()){
WebUtils.issueRedirect(request, response, getSuccessUrl(), null, true);
// }else{
// super.issueSuccessRedirect(request, response);
// }
}
示例10: redirectToLogin
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
if (isAjaxRequest((HttpServletRequest)request)) {
response.setCharacterEncoding( Constants.BASE_ENCODING );
response.setContentType("application/json");
response.getWriter().write(Constants.NO_LOGIN_JSON_DATA);
return;
}
if (this.isIframeMode((HttpServletRequest)request)) { // iframe 不要導向 login.action 因為畫面會怪怪的
WebUtils.issueRedirect(request, response, "/pages/system/error_static.jsp");
return;
}
if (this.isDojoxContentPane((HttpServletRequest)request)) { // 在 dojox.layout.ContentPane 不要出現 login.action 頁面
WebUtils.issueRedirect(request, response, Constants.DOJOX_CONTENT_PANE_XHR_RE_LOGIN_PAGE);
return;
}
WebUtils.issueRedirect(request, response, getLoginUrl());
}
示例11: onAccessDenied
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
getSubject(request, response).logout();
String loginUrl = getLoginUrl() + (getLoginUrl().contains("?") ? "&" : "?") + "forceLogout=1";
WebUtils.issueRedirect(request, response, loginUrl);
return false;
}
示例12: issueSuccessRedirect
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected void issueSuccessRedirect(ServletRequest request, ServletResponse response) throws Exception {
// Principal p = UserUtils.getPrincipal();
// if (p != null && !p.isMobileLogin()){
WebUtils.issueRedirect(request, response, getSuccessUrl(), null, true);
// }else{
// super.issueSuccessRedirect(request, response);
// }
}
示例13: onAccessDenied
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
* Redirects the request to the same exact incoming URL, but with the port listed in the filter's configuration.
*
* @param request the incoming <code>ServletRequest</code>
* @param response the outgoing <code>ServletResponse</code>
* @param mappedValue the config specified for the filter in the matching request's filter chain.
* @return {@code false} always to force a redirect.
*/
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response, Object mappedValue) throws IOException {
//just redirect to the specified port:
int port = toPort(mappedValue);
String scheme = getScheme(request.getScheme(), port);
StringBuilder sb = new StringBuilder();
sb.append(scheme).append("://");
sb.append(request.getServerName());
if (port != DEFAULT_HTTP_PORT && port != SslFilter.DEFAULT_HTTPS_PORT) {
sb.append(":");
sb.append(port);
}
if (request instanceof HttpServletRequest) {
sb.append(WebUtils.toHttp(request).getRequestURI());
String query = WebUtils.toHttp(request).getQueryString();
if (query != null) {
sb.append("?").append(query);
}
}
WebUtils.issueRedirect(request, response, sb.toString());
return false;
}
示例14: redirectToLogin
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@Override
protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
PrintWriter printWriter = null;
try {
String loginUrl = getLoginUrl();
//ajax请求
HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
HttpServletResponse httpServletResponse = WebUtils.toHttp(response);
if ("XMLHttpRequest".equalsIgnoreCase(httpServletRequest.getHeader("X-Requested-With"))) {
httpServletResponse.setContentType("text/json; charset=utf-8");
Map<String, Object> json = new HashMap<String, Object>();
json.put("status", HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
json.put("message", "Authentication fail");
httpServletResponse.setStatus(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED);
printWriter = httpServletResponse.getWriter();
printWriter.write(JsonUtils.toJsonString(json));
} else {
WebUtils.issueRedirect(request, response, loginUrl);
}
} finally {
try {
if (printWriter != null) {
printWriter.close();
}
response.flushBuffer();
} catch (IOException e) {
logger.warn(e.getMessage(), e);
}
}
}
示例15: redirectToLogin
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
if ( !Constants.getSystem().equals( Constants.getMainSystem() ) && !isAjaxRequest((HttpServletRequest)request) ) { // 非 core-web
try {
if ( this.loginUseCurrentCookieForGeneralPackage(request, response) ) { // no need to login-page
String url = SimpleUtils.getHttpRequestUrl( (HttpServletRequest)request );
logger.warn("URL = " + url );
WebUtils.issueRedirect(request, response, url);
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (isAjaxRequest((HttpServletRequest)request)) {
response.setCharacterEncoding( Constants.BASE_ENCODING );
response.setContentType("application/json");
response.getWriter().write(Constants.NO_LOGIN_JSON_DATA);
return;
}
if (this.isIframeMode((HttpServletRequest)request)) { // iframe 不要導向 login.action 因為畫面會怪怪的
WebUtils.issueRedirect(request, response, "/pages/system/error_static.jsp");
return;
}
if (this.isDojoxContentPane((HttpServletRequest)request)) { // 在 dojox.layout.ContentPane 不要出現 login.action 頁面
WebUtils.issueRedirect(request, response, Constants.DOJOX_CONTENT_PANE_XHR_RE_LOGIN_PAGE);
return;
}
WebUtils.issueRedirect(request, response, getLoginUrl());
}