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


Java WebUtils.isTrue方法代码示例

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


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

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

示例2: 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:ansafari,项目名称:melon,代码行数:26,代码来源:SessionManager.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:egojit8,项目名称:easyweb,代码行数:24,代码来源:SessionManager.java

示例4: isMobileLogin

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected boolean isMobileLogin(ServletRequest request) {
    return WebUtils.isTrue(request, getMobileLoginParam());
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:4,代码来源:FormAuthenticationFilter.java

示例5: loginFail

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * 登录失败,真正登录的POST请求由Filter完成
 */
@RequestMapping(value = "${adminPath}/login", method = RequestMethod.POST)
public String loginFail(HttpServletRequest request, HttpServletResponse response, Model model) {
    SystemAuthorizingRealm.Principal principal = UserUtils.getPrincipal();

    // 如果已经登录,则跳转到管理首页
    if (principal != null) {
        return "redirect:" + adminPath;
    }

    String username = WebUtils.getCleanParam(request, FormAuthenticationFilter.DEFAULT_USERNAME_PARAM);
    boolean rememberMe = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_REMEMBER_ME_PARAM);
    boolean mobile = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_MOBILE_PARAM);
    String exception = (String) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
    String message = (String) request.getAttribute(FormAuthenticationFilter.DEFAULT_MESSAGE_PARAM);

    if (StringUtils.isBlank(message) || StringUtils.equals(message, "null")) {
        message = "用户或密码错误, 请重试.";
    }

    model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, username);
    model.addAttribute(FormAuthenticationFilter.DEFAULT_REMEMBER_ME_PARAM, rememberMe);
    model.addAttribute(FormAuthenticationFilter.DEFAULT_MOBILE_PARAM, mobile);
    model.addAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME, exception);
    model.addAttribute(FormAuthenticationFilter.DEFAULT_MESSAGE_PARAM, message);

    if (logger.isDebugEnabled()) {
        logger.debug("login fail, active session size: {}, message: {}, exception: {}",
                sessionDAO.getActiveSessions(false).size(), message, exception);
    }

    // 非授权异常,登录失败,验证码加1。
    if (!UnauthorizedException.class.getName().equals(exception)) {
        model.addAttribute("isValidateCodeLogin", isValidateCodeLogin(username, true, false));
    }

    // 验证失败清空验证码
    request.getSession().setAttribute(ValidateCodeServlet.VALIDATE_CODE, IdGen.uuid());

    // 如果是手机登录,则返回JSON字符串
    if (mobile) {
        return renderString(response, model);
    }

    return "modules/sys/sysLogin";
}
 
开发者ID:ansafari,项目名称:melon,代码行数:49,代码来源:LoginController.java

示例6: loginFail

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
 * 登录失败,真正登录的POST请求由Filter完成
 */
@RequestMapping(value = "${adminPath}/login", method = RequestMethod.POST)
public String loginFail(HttpServletRequest request, HttpServletResponse response, Model model) {
	String from = request.getParameter("from");
	SystemAuthorizingRealm.Principal principal = UserUtils.getPrincipal();
	
	// 如果已经登录,则跳转到管理首页
	if(principal != null){
		if (from != null && from.equals("app"))
			return "redirect:/app/user.html";
		else
			return "redirect:" + adminPath;
	}

	String username = WebUtils.getCleanParam(request, FormAuthenticationFilter.DEFAULT_USERNAME_PARAM);
	boolean rememberMe = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_REMEMBER_ME_PARAM);
	boolean mobile = WebUtils.isTrue(request, FormAuthenticationFilter.DEFAULT_MOBILE_PARAM);
	String exception = (String)request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
	String message = (String)request.getAttribute(FormAuthenticationFilter.DEFAULT_MESSAGE_PARAM);
	
	if (StringUtils.isBlank(message) || StringUtils.equals(message, "null")){
		message = "用户或密码错误, 请重试.";
	}

	model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, username);
	model.addAttribute(FormAuthenticationFilter.DEFAULT_REMEMBER_ME_PARAM, rememberMe);
	model.addAttribute(FormAuthenticationFilter.DEFAULT_MOBILE_PARAM, mobile);
	model.addAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME, exception);
	model.addAttribute(FormAuthenticationFilter.DEFAULT_MESSAGE_PARAM, message);
	
	if (logger.isDebugEnabled()){
		logger.debug("login fail, active session size: {}, message: {}, exception: {}", 
				sessionDAO.getActiveSessions(false).size(), message, exception);
	}
	
	// 非授权异常,登录失败,验证码加1。
	if (!UnauthorizedException.class.getName().equals(exception)){
		model.addAttribute("isValidateCodeLogin", isValidateCodeLogin(username, true, false));
	}
	
	// 验证失败清空验证码
	request.getSession().setAttribute(ValidateCodeServlet.VALIDATE_CODE, IdGen.uuid());
	
	// 如果是手机登录,则返回JSON字符串
	if (mobile){
        return renderString(response, model);
	}
	
	if (from != null && from.equals("app"))
		return "modules/app/user/login";
	else
		return "modules/sys/sysLogin";
}
 
开发者ID:EleTeam,项目名称:Shop-for-JavaWeb,代码行数:56,代码来源:LoginController.java

示例7: isRememberMe

import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected boolean isRememberMe(ServletRequest request) {
    return WebUtils.isTrue(request, getRememberMeParam());
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:4,代码来源:FormAuthenticationFilter.java


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