本文整理汇总了Java中org.apache.shiro.web.util.WebUtils.getCleanParam方法的典型用法代码示例。如果您正苦于以下问题:Java WebUtils.getCleanParam方法的具体用法?Java WebUtils.getCleanParam怎么用?Java WebUtils.getCleanParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.web.util.WebUtils
的用法示例。
在下文中一共展示了WebUtils.getCleanParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerStep1
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
* 注册 - 提交手机号码
*/
@RequestMapping(value = "/register-step1-post")
public String registerStep1(HttpServletRequest request, HttpServletResponse response) {
if (!isValidApp(request)) {
return renderInvalidApp(response);
}
boolean result;
String message;
Map<String, Object> data = Maps.newHashMap();
String username = WebUtils.getCleanParam(request, FormAuthenticationFilter.DEFAULT_USERNAME_PARAM);
data.put("userLoginName", username);
if (ValidateUtils.isMobile(username)) {
result = true;
message = "";
} else {
result = false;
message = ValidateUtils.getErrMsg();
}
User user = userService.getByLoginName2(username);
if (user != null && StringUtils.isNotBlank(user.getId())) {
result = false;
message = "电话号码已存在";
} else {
//发送手机验证码
SmsUtils.sendRegisterCode(username);
}
return renderString(response, result, message, data);
}
示例2: getCaptchaId
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
* 获取验证ID
*
* @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;
}
示例3: registerStep2
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
* 注册 - 提交手机号码、密码
*/
@RequestMapping(value = "/register-step2-post")
public String registerStep2(HttpServletRequest request, HttpServletResponse response) {
if (!isValidApp(request)) {
return renderInvalidApp(response);
}
boolean result;
String message;
Map<String, Object> data = Maps.newHashMap();
String username = WebUtils.getCleanParam(request, FormAuthenticationFilter.DEFAULT_USERNAME_PARAM);
String password = WebUtils.getCleanParam(request, FormAuthenticationFilter.DEFAULT_PASSWORD_PARAM);
data.put("userLoginName", username);
data.put("userPassword", password);
if (ValidateUtils.isMobile(username) && ValidateUtils.isPassword(password)) {
result = true;
message = "";
} else {
result = false;
message = ValidateUtils.getErrMsg();
}
User user = userService.getByLoginName2(username);
if (user != null && StringUtils.isNotBlank(user.getId())) {
result = false;
message = "电话号码已存在";
}
return renderString(response, result, message, data);
}
示例4: decodeBase64Param
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
private String decodeBase64Param(final ServletRequest request, final String name) {
String encoded = WebUtils.getCleanParam(request, name);
if (encoded != null) {
return Strings2.decodeBase64(encoded);
}
return null;
}
示例5: login
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@RequestMapping(value = "/login" ,method = RequestMethod.POST)
public String login(User user, Model model, HttpServletRequest request) {
log.info("Login user=====" + user);
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword());
String remember = WebUtils.getCleanParam(request, "remember");
log.info("remember=" + remember);
try {
if(remember != null && remember.equalsIgnoreCase("on")) {
token.setRememberMe(true);
}
subject.login(token);
return "redirect:/index";
} catch(UnknownAccountException ue) {
token.clear();
model.addAttribute("error", "登录失败,您输入的账号不存在");
return "security/login";
} catch(IncorrectCredentialsException ie) {
token.clear();
model.addAttribute("username", user.getUsername());
model.addAttribute("error", "登录失败,密码不匹配");
return "security/login";
} catch(RuntimeException re) {
token.clear();
model.addAttribute("username", user.getUsername());
model.addAttribute("error", "登录失败");
return "security/login";
}
}
示例6: getCaptcha
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected String getCaptcha(ServletRequest request) {
return WebUtils.getCleanParam(request, Captcha.KEY);
}
示例7: login
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
@RequestMapping(value="/login", method=RequestMethod.POST)
public String login(String username, String password, HttpServletRequest request){
System.out.println("-------------------------------------------------------");
String rand = (String)request.getSession().getAttribute("rand");
String captcha = WebUtils.getCleanParam(request, "captcha");
System.out.println("用户["+username+"]登录时输入的验证码为["+captcha+"],HttpSession中的验证码为["+rand+"]");
if(!StringUtils.equals(rand, captcha)){
request.setAttribute("message_login", "验证码不正确");
return InternalResourceViewResolver.FORWARD_URL_PREFIX + "/";
}
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
token.setRememberMe(true);
System.out.print("为验证登录用户而封装的Token:");
System.out.println(ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE));
//获取当前的Subject
Subject currentUser = SecurityUtils.getSubject();
try {
//在调用了login方法后,SecurityManager会收到AuthenticationToken,并将其发送给已配置的Realm执行必须的认证检查
//每个Realm都能在必要时对提交的AuthenticationTokens作出反应
//所以这一步在调用login(token)方法时,它会走到MyRealm.doGetAuthenticationInfo()方法中,具体验证方式详见此方法
System.out.println("对用户[" + username + "]进行登录验证...验证开始");
currentUser.login(token);
System.out.println("对用户[" + username + "]进行登录验证...验证通过");
}catch(UnknownAccountException uae){
System.out.println("对用户[" + username + "]进行登录验证...验证未通过,未知账户");
request.setAttribute("message_login", "未知账户");
}catch(IncorrectCredentialsException ice){
System.out.println("对用户[" + username + "]进行登录验证...验证未通过,错误的凭证");
request.setAttribute("message_login", "密码不正确");
}catch(LockedAccountException lae){
System.out.println("对用户[" + username + "]进行登录验证...验证未通过,账户已锁定");
request.setAttribute("message_login", "账户已锁定");
}catch(ExcessiveAttemptsException eae){
System.out.println("对用户[" + username + "]进行登录验证...验证未通过,错误次数过多");
request.setAttribute("message_login", "用户名或密码错误次数过多");
}catch(AuthenticationException ae){
//通过处理Shiro的运行时AuthenticationException就可以控制用户登录失败或密码错误时的情景
System.out.println("对用户[" + username + "]进行登录验证...验证未通过,堆栈轨迹如下");
ae.printStackTrace();
request.setAttribute("message_login", "用户名或密码不正确");
}
//验证是否登录成功
if(currentUser.isAuthenticated()){
System.out.println("用户[" + username + "]登录认证通过(这里可进行一些认证通过后的系统参数初始化操作)");
return "main";
}else{
token.clear();
return InternalResourceViewResolver.FORWARD_URL_PREFIX + "/";
}
}
示例8: getCaptcha
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected String getCaptcha(ServletRequest request) {
return WebUtils.getCleanParam(request, getCaptchaParam());
}
示例9: getAuthorizationParameter
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
String getAuthorizationParameter(ServletRequest request) {
HttpServletRequest httpRequest = WebUtils.toHttp(request);
return WebUtils.getCleanParam(httpRequest, AUTHORIZATION_PARAM);
}
示例10: 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";
}
示例11: getCaptcha
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected String getCaptcha(ServletRequest request) {
return WebUtils.getCleanParam(request, getCaptchaParam());
}
示例12: 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";
}
示例13: getUsername
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected String getUsername(ServletRequest request) {
return WebUtils.getCleanParam(request, getUsernameParam());
}
示例14: getPassword
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected String getPassword(ServletRequest request) {
return WebUtils.getCleanParam(request, getPasswordParam());
}
示例15: getCaptcha
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
protected String getCaptcha(ServletRequest request) {
return WebUtils.getCleanParam(request, this.getCaptchaParam());
}