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


Java WebUtils类代码示例

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


WebUtils类属于org.apache.shiro.web.util包,在下文中一共展示了WebUtils类的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: getSessionId

import org.apache.shiro.web.util.WebUtils; //导入依赖的package包/类
@Override
protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
	// 如果参数中包含“__sid”参数,则使用此sid会话。 例如:http://localhost/project?__sid=xxx&__cookie=true
	String sid = request.getParameter("__sid");
	if (StringUtils.isNotBlank(sid)) {
		// 是否将sid保存到cookie,浏览器模式下使用此参数。
		if (WebUtils.isTrue(request, "__cookie")) {
			HttpServletRequest rq = (HttpServletRequest) request;
			HttpServletResponse rs = (HttpServletResponse) response;
			Cookie template = getSessionIdCookie();
			Cookie cookie = new SimpleCookie(template);
			cookie.setValue(sid);
			cookie.saveTo(rq, rs);
		}
		// 设置当前session状态
		request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE, ShiroHttpServletRequest.URL_SESSION_ID_SOURCE); // session来源与url
		request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID, sid);
		request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_IS_VALID, Boolean.TRUE);
		return sid;
	} else {
		return super.getSessionId(request, response);
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:24,代码来源:SessionManager.java

示例4: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //导入依赖的package包/类
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
	HttpServletRequest req = (HttpServletRequest) request;
	HttpServletResponse res = (HttpServletResponse) response;
	if(isAsynRequest(req, res)){
		WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
		Result<Object> result = new Result<Object>();
		result.setCode("401");
		result.setSuccess(false);
		result.setMessage(Messages.getMessage(getDefaultNoPermissionMessageI18nCode(), null, getDefaultNoPermissionMessage()));
		res.setCharacterEncoding("UTF-8");
		res.setContentType("application/json;charset=UTF-8");
		PrintWriter out = res.getWriter();
		out.println(JsonUtils.object2Json(result));
		out.flush();
		out.close();
		return false;
	}else{
		return super.onAccessDenied(request, response);
	}
}
 
开发者ID:penggle,项目名称:xproject,代码行数:21,代码来源:GlobalUrlPermissionFilter.java

示例5: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //导入依赖的package包/类
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
	HttpServletRequest req = (HttpServletRequest) request;
	HttpServletResponse res = (HttpServletResponse) response;
	if(isAsynRequest(req, res)){
		WebUtils.toHttp(response).sendError(HttpServletResponse.SC_UNAUTHORIZED);
		Result<Object> result = new Result<Object>();
		result.setCode("401");
		result.setSuccess(false);
		result.setMessage(Messages.getMessage(getDefaultNoPermissionMessageI18nCode(), null, getDefaultNoPermissionMessage()));
		res.setCharacterEncoding("UTF-8");
		res.setContentType("application/json;charset=UTF-8");
		PrintWriter out = res.getWriter();
		out.println(JsonUtils.object2Json(result));
		out.flush();
		out.close();
		return false;
	}else{
		return super.onAccessDenied(request, response);
	}
}
 
开发者ID:penggle,项目名称:xproject,代码行数:21,代码来源:GlobalFormAuthenticationFilter.java

示例6: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //导入依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    StringBuffer sso_server_url = new StringBuffer(PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.sso.server.url"));
    // server需要登录
    String upmsType = PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.type");
    if ("server".equals(upmsType)) {
        WebUtils.toHttp(response).sendRedirect(sso_server_url.append("/sso/login").toString());
        return false;
    }
    sso_server_url.append("/sso/index").append("?").append("appid").append("=").append(PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.appID"));
    // 回跳地址
    HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
    StringBuffer backurl = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        backurl.append("?").append(queryString);
    }
    sso_server_url.append("&").append("backurl").append("=").append(URLEncoder.encode(backurl.toString(), "utf-8"));
    WebUtils.toHttp(response).sendRedirect(sso_server_url.toString());
    return false;
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:22,代码来源:UpmsAuthenticationFilter.java

示例7: 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

示例8: isAccessAllowed

import org.apache.shiro.web.util.WebUtils; //导入依赖的package包/类
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue)
		throws Exception {
	// 1、设置验证码是否开启属性,页面可以根据该属性来决定是否显示验证码
	request.setAttribute("captchaEbabled", captchaEbabled);

	HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
	// 2、判断验证码是否禁用 或不是表单提交(允许访问)
	if (captchaEbabled == false || !"post".equalsIgnoreCase(httpServletRequest.getMethod())) {
		return true;
	}
	// 3、此时是表单提交,验证验证码是否正确
	// 获取页面提交的验证码
	String submitCaptcha = httpServletRequest.getParameter(captchaParam);
	// 获取session中的验证码
	String captcha = (String) httpServletRequest.getSession().getAttribute("rcCaptcha");
	if (submitCaptcha.equals(captcha)) {
		return true;
	}
	return false;
}
 
开发者ID:babymm,项目名称:mumu,代码行数:22,代码来源:RcCaptchaValidateFilter.java

示例9: doPost

import org.apache.shiro.web.util.WebUtils; //导入依赖的package包/类
public void doPost(MCRServletJob job) throws Exception {
	Element output = new Element("userLogging");
	String username = getParameter(job, "username");
	String password = getParameter(job, "password");
	boolean rememberMe = "true".equals(getParameter(job, "rememberMe"));

	boolean b = false;
	if (username == null)
		output.addContent((new Element("message")).addContent("login.message.noUserGiven"));

	else if (password == null)
		output.addContent((new Element("message")).addContent("login.message.noPasswordGiven"));

	else {
		b = tryLogin(username, password, rememberMe);
		if (b) {
			SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(job.getRequest());
			if (savedRequest != null)
				job.getResponse().sendRedirect(savedRequest.getRequestUrl());
			else
				job.getResponse().sendRedirect("analysis/start");
		} else
			output.addContent((new Element("message")).addContent("login.message.loginFailed"));
	}
	sendOutput(job, output);
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:27,代码来源:UserLoggingServlet.java

示例10: onPreHandle

import org.apache.shiro.web.util.WebUtils; //导入依赖的package包/类
@Override
protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
   	Subject subject = SecurityUtils.getSubject();
	if (!subject.isAuthenticated()) {
        HttpServletRequest httpRequest = WebUtils.toHttp(request);
        String authzHeader = httpRequest.getHeader(AUTHORIZATION_HEADER);
        if (authzHeader != null) {
            if (authzHeader.toLowerCase(Locale.ENGLISH).startsWith("basic") 
            		|| authzHeader.toLowerCase(Locale.ENGLISH).startsWith("token")) {
            	String authToken = StringUtils.substringAfter(authzHeader, " ");
                String decoded = Base64.decodeToString(authToken);
                String userName = StringUtils.substringBefore(decoded, ":").trim();
                String password = StringUtils.substringAfter(decoded, ":").trim();
                if (userName.length() != 0 && password.length() != 0) {
	                UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
                    subject.login(token);
                }
            }
        } 
	} 
	
	return true;
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:24,代码来源:BasicAuthenticationFilter.java

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: onAccessDenied

import org.apache.shiro.web.util.WebUtils; //导入依赖的package包/类
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    StringBuffer sso_server_url = new StringBuffer(PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.sso.server.url"));
    // server需要登录
    String upmsType = PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.type");
    if ("server".equals(upmsType)) {
        WebUtils.toHttp(response).sendRedirect(sso_server_url.append("/sso/login").toString());
        return false;
    }
    sso_server_url.append("/sso/index").append("?").append("appid").append("=").append(PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.appID"));
    // 回跳地址
    HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
    StringBuffer backurl = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        backurl.append("?").append(queryString);
    }
    sso_server_url.append("&").append("backurl").append("=").append(URLEncoder.encode(backurl.toString(), "utf-8"));
    WebUtils.toHttp(response).sendRedirect(sso_server_url.toString());
    return false;
}
 
开发者ID:sunzhen086,项目名称:lambo,代码行数:22,代码来源:UpmsAuthenticationFilter.java


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