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


Java WebUtils.issueRedirect方法代码示例

本文整理汇总了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);
}
 
开发者ID:liaojiacan,项目名称:zkAdmin,代码行数:18,代码来源:LoginFilter.java

示例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);
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:21,代码来源:CmsAuthenticationFilter.java

示例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);
}
 
开发者ID:babymm,项目名称:mumu,代码行数:23,代码来源:OAuth2AuthenticationFilter.java

示例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;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:27,代码来源:PermissionFilter.java

示例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;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:28,代码来源:KickoutAuthFilter.java

示例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;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:27,代码来源:RoleFilter.java

示例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;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:20,代码来源:URLFilter.java

示例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;
}
 
开发者ID:ls960972314,项目名称:report,代码行数:20,代码来源:SimpleAuthFilter.java

示例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);
//		}
	}
 
开发者ID:whatlookingfor,项目名称:spring-boot-sample,代码行数:11,代码来源:FormAuthenticationFilter.java

示例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());
}
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:18,代码来源:GreenStepMobileFormAuthenticationFilter.java

示例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;
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:8,代码来源:UpmsSessionForceLogoutFilter.java

示例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);
    // }
}
 
开发者ID:ansafari,项目名称:melon,代码行数:10,代码来源:FormAuthenticationFilter.java

示例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;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:36,代码来源:PortFilter.java

示例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);
        }
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:31,代码来源:FormAuthcFilter.java

示例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());
 }
 
开发者ID:billchen198318,项目名称:bamboobsc,代码行数:30,代码来源:GreenStepBaseFormAuthenticationFilter.java


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