Example usage for org.apache.shiro.web.util WebUtils isTrue

List of usage examples for org.apache.shiro.web.util WebUtils isTrue

Introduction

In this page you can find the example usage for org.apache.shiro.web.util WebUtils isTrue.

Prototype

public static boolean isTrue(ServletRequest request, String paramName) 

Source Link

Document

Checks to see if a request param is considered true using a loose matching strategy for general values that indicate that something is true or enabled, etc.

Values that are considered "true" include (case-insensitive): true, t, 1, enabled, y, yes, on.

Usage

From source file:cn.dreampie.common.plugin.shiro.MyFormAuthenticationFilter.java

License:Apache License

protected boolean isRememberMe(ServletRequest request) {
    return WebUtils.isTrue(request, getRememberMeParam());
}

From source file:com.fengduo.spark.commons.shiro.session.SessionManager.java

License:Open Source License

@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);/*  w  w  w .j  av  a  2 s. c o m*/
            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);
    }
}

From source file:com.funtl.framework.smoke.core.modules.sys.security.FormAuthenticationFilter.java

License:Apache License

protected boolean isMobileLogin(ServletRequest request) {
    return WebUtils.isTrue(request, getMobileLoginParam());
}

From source file:com.funtl.framework.smoke.core.modules.sys.web.LoginController.java

License:Apache License

/**
 * POSTFilter?//from w  w w .  j  a  va2s .  c  om
 */
@RequestMapping(value = "${adminPath}/login", method = RequestMethod.POST)
public String loginFail(HttpServletRequest request, HttpServletResponse response, Model model) {
    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";
}

From source file:com.whatlookingfor.modules.sys.web.LoginController.java

License:Apache License

/**
 * POSTFilter?/*from ww w. jav a2s  .  c  o m*/
 */
@RequestMapping(value = "${adminPath}/login", method = RequestMethod.POST)
public String loginFail(HttpServletRequest request, HttpServletResponse response, Model model) {
    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);
    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_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());

    return "modules/sys/login";
}

From source file:org.sonatype.nexus.rapture.internal.security.SessionAuthenticationFilter.java

License:Open Source License

@Override
protected boolean isRememberMe(final ServletRequest request) {
    // TODO: Allow feature to be disabled globally by property, probably here is a good place?
    return WebUtils.isTrue(request, P_REMEMBER_ME);
}

From source file:waffle.shiro.negotiate.NegotiateAuthenticationFilter.java

License:Open Source License

@Override
protected boolean isRememberMe(final ServletRequest request) {
    return WebUtils.isTrue(request, this.getRememberMeParam());
}