當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。