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

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

Introduction

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

Prototype

public static String getCleanParam(ServletRequest request, String paramName) 

Source Link

Document

Convenience method that returns a request parameter value, first running it through StringUtils#clean(String) .

Usage

From source file:apm.modules.sys.security.FormAuthenticationFilter.java

License:Open Source License

protected String getCaptcha(ServletRequest request) {
    return WebUtils.getCleanParam(request, getCaptchaParam());
}

From source file:cn.com.cowboy.project.web.filter.CustomFormAuthenticationFilter.java

License:Apache License

protected String getCaptcha(ServletRequest request) {

    return WebUtils.getCleanParam(request, getCaptchaParam());

}

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

License:Apache License

protected String getCaptcha(ServletRequest request) {
    return WebUtils.getCleanParam(request, AppConstants.CAPTCHA_NAME);
}

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

License:Apache License

protected String getUsername(ServletRequest request) {
    return WebUtils.getCleanParam(request, getUsernameParam());
}

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

License:Apache License

protected String getPassword(ServletRequest request) {
    return WebUtils.getCleanParam(request, getPasswordParam());
}

From source file:cn.dreampie.shiro.ShiroAuthenticatingFilter.java

License:Apache License

protected String getCaptcha(ServletRequest request) {
    return WebUtils.getCleanParam(request, DEFAULT_CAPTCHA_PARAM);
}

From source file:cn.mario256.blog.filter.AuthenticationFilter.java

License:Open Source License

/**
 * ??ID//from www  .  j av a2s. com
 * 
 * @param servletRequest
 *            ServletRequest
 * @return ?ID
 */
protected String getCaptchaId(ServletRequest servletRequest) {
    String captchaId = WebUtils.getCleanParam(servletRequest, captchaIdParam);
    if (captchaId == null) {
        captchaId = ((HttpServletRequest) servletRequest).getSession().getId();
    }
    return captchaId;
}

From source file:cn.mario256.blog.filter.AuthenticationFilter.java

License:Open Source License

/**
 * ???//from   w ww  . ja v  a2 s.  c  o  m
 * 
 * @param servletRequest
 *            ServletRequest
 * @return ??
 */
protected String getCaptcha(ServletRequest servletRequest) {
    return WebUtils.getCleanParam(servletRequest, captchaParam);
}

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

License:Apache License

/**
 * POSTFilter?/*from w w w  .j a  v  a  2 s. co 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);
    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.kelson.keeku.security.MyFormAuthenticationFilter.java

License:Apache License

@Override
protected boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception {
    String username = getUsername(request);
    String password = getPassword(request);
    boolean isAjaxLogin = StringUtils.equals(WebUtils.getCleanParam(request, "ajaxLogin"), "1");
    boolean rememberMe = isRememberMe(request);
    String host = getHost(request);
    UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe, host);

    try {/*from  w w w .  j a  v a  2  s.co  m*/
        Subject subject = getSubject(request, response);
        subject.login(token);
        Session session = subject.getSession();
        Integer userId = (Integer) session.getAttribute("userId");
        LoggerUtil.operation(Operation.Login, String.valueOf(userId) + "has logined",
                (HttpServletRequest) request);
        if (isAjaxLogin) {
            if (StringUtils.equals(WebUtils.getCleanParam(request, "needRedirect"), "1")) {//when login successfully by ajax login and redirect to backurl
                SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request);
                if (savedRequest != null
                        && savedRequest.getMethod().equalsIgnoreCase(AccessControlFilter.GET_METHOD)) {
                    request.setAttribute("backUrl", savedRequest.getRequestUrl());
                }
            }
            return true;
        } else {
            return onLoginSuccess(token, subject, request, response);
        }
    } catch (AuthenticationException e) {
        if (SecurityUtils.getSubject().getSession(false) != null) {
            SecurityUtils.getSubject().getSession(false).removeAttribute("userId");
        }
        return onLoginFailure(token, e, request, response);
    }
}