本文整理匯總了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());
}