當前位置: 首頁>>代碼示例>>Java>>正文


Java IncorrectCredentialsException類代碼示例

本文整理匯總了Java中org.apache.shiro.authc.IncorrectCredentialsException的典型用法代碼示例。如果您正苦於以下問題:Java IncorrectCredentialsException類的具體用法?Java IncorrectCredentialsException怎麽用?Java IncorrectCredentialsException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IncorrectCredentialsException類屬於org.apache.shiro.authc包,在下文中一共展示了IncorrectCredentialsException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doCredentialsMatch

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) throws ExcessiveAttemptsException {
    String username = (String)token.getPrincipal();
    AtomicInteger retryCount = passwordRetryCache.get(username);

    if(retryCount == null) {
        retryCount = new AtomicInteger(0);
        passwordRetryCache.put(username, retryCount);
    }
    if(retryCount.incrementAndGet() > retryMax) {
        throw new ExcessiveAttemptsException("您已連續錯誤達" + retryMax + "次!請10分鍾後再試");
    }

    boolean matches = super.doCredentialsMatch(token, info);
    if(matches) {
        passwordRetryCache.remove(username);
    }else {
        throw new IncorrectCredentialsException("密碼錯誤,已錯誤" + retryCount.get() + "次,最多錯誤" + retryMax + "次");
    }
    return true;
}
 
開發者ID:johntostring,項目名稱:spring-boot-shiro,代碼行數:22,代碼來源:RetryLimitHashedCredentialsMatcher.java

示例2: dashboard

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@RequestMapping(value = "/login", method = {
        RequestMethod.POST})
public String dashboard(ModelMap map, Admin admin) {
    String error = null;
    UsernamePasswordToken token = new UsernamePasswordToken(admin.getUsername(), admin.getPassword());
    token.setRememberMe(false);
    try {
        SecurityUtils.getSubject().login(token);
        return "redirect:/video/all";
    } catch (UnknownAccountException uae) {
        error = "用戶名錯誤!";
    } catch (IncorrectCredentialsException ice) {
        error = "密碼錯誤!";
    } catch (LockedAccountException lae) {
        error = "用戶被鎖定!";
    }
    map.addAttribute("error", error);
    return "login.ftl";
}
 
開發者ID:melonlee,項目名稱:LazyAdmin,代碼行數:20,代碼來源:AuthController.java

示例3: showLoginForm

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@RequestMapping(value = "/login")
public String showLoginForm(HttpServletRequest req, Model model) {
    if(req.getMethod().equalsIgnoreCase("get")){
        return "login";
    }
    String exceptionClassName = (String)req.getAttribute("shiroLoginFailure");
    String error = null;
    if(UnknownAccountException.class.getName().equals(exceptionClassName)) {
        error = "用戶名/密碼錯誤";
    } else if(IncorrectCredentialsException.class.getName().equals(exceptionClassName)) {
        error = "用戶名/密碼錯誤";
    } else if(exceptionClassName != null) {
        error = "其他錯誤:" + exceptionClassName;
    }
    if(error!=null){
        model.addAttribute("shiroLoginFailure", error);
        return "login";
    }
    return "redirect:/main";

}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:22,代碼來源:LoginController.java

示例4: tryLogin

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
public boolean tryLogin(String email, String password, Boolean rememberMe) {
    org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(email, password);
    token.setRememberMe(rememberMe);

    try {
        currentUser.login(token);
        System.out.println("User [" + currentUser.getPrincipal().toString() + "] logged in successfully.");
        // save username in the session
        currentUser.getSession().setAttribute("username", email);
        return true;
    } catch (UnknownAccountException uae) {
        System.out.println("There is no user with username of " + token.getPrincipal());
    } catch (IncorrectCredentialsException ice) {
        System.out.println("Password for account " + token.getPrincipal() + " was incorrect!");
    } catch (LockedAccountException lae) {
        System.out.println("The account for username " + token.getPrincipal() + " is locked.  " + "Please contact your administrator to unlock it.");
    }

    return false;
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:22,代碼來源:BibliometricReportRetrievalServlet.java

示例5: login

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@RequestMapping("/login")
public String login(HttpServletRequest request) throws Exception{
	String exceptionClassName = (String) request.getAttribute("shiroLoginFailure");
	//根據shiro返回的異常類路徑判斷,拋出指定異常信息
	if(exceptionClassName!=null){
		if (UnknownAccountException.class.getName().equals(exceptionClassName)) {
			//最終會拋給異常處理器
			throw new UnknownAccountException("賬號不存在");
		} else if (IncorrectCredentialsException.class.getName().equals(
				exceptionClassName)) {
			throw new IncorrectCredentialsException("用戶名/密碼錯誤");
		}else {
			throw new Exception();//最終在異常處理器生成未知錯誤
		}
	}
	return "login";
}
 
開發者ID:fuyunwang,項目名稱:SSMShiro,代碼行數:18,代碼來源:IndexController.java

示例6: onLoginFailure

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
/**
 * 登錄失敗調用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token,
                                    AuthenticationException e, ServletRequest request, ServletResponse response) {
	String className = e.getClass().getName(), message = "";
	if (IncorrectCredentialsException.class.getName().equals(className)
			|| UnknownAccountException.class.getName().equals(className)){
		message = "用戶或密碼錯誤, 請重試.";
	}
	else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")){
		message = StringUtils.replace(e.getMessage(), "msg:", "");
	}
	else{
		message = "係統出現點問題,請稍後再試!";
		e.printStackTrace(); // 輸出到控製台
	}
       request.setAttribute(getFailureKeyAttribute(), className);
       request.setAttribute(getMessageParam(), message);
       return true;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:23,代碼來源:FormAuthenticationFilter.java

示例7: signin

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@RequestMapping(value = "/signin", method = {
        RequestMethod.POST})
public String signin(ModelMap map, User user, HttpServletRequest request) {

    String error;
    UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPasswd());
    token.setRememberMe(null != request.getParameter("rememberme") ? true : false);
    try {
        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        subject.getSession().setAttribute("curUser", userService.findByUsername((String) subject.getPrincipal()));
        return "redirect:/dashboard/console";
    } catch (UnknownAccountException uae) {
        error = "用戶名錯誤!";
    } catch (IncorrectCredentialsException ice) {
        error = "密碼錯誤!";
    } catch (LockedAccountException lae) {
        error = "用戶被鎖定!";
    }
    map.addAttribute("error", error);
    return "signin";
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:23,代碼來源:AuthController.java

示例8: changepwd

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@RequestMapping(value = "/changepwd", method = {
        RequestMethod.POST})
public String changepwd(ModelMap map, User user, @RequestParam(value = "passwdnew", required = true) String passwdnew) {

    //驗證當前賬號
    UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPasswd());
    token.setRememberMe(false);
    try {
        SecurityUtils.getSubject().login(token);
        //驗證通過更新用戶密碼
        user.setId(getCurrentUser().getId());
        user.setPasswd(passwdnew);
        passwordHelper.encryptPassword(user);
        userService.updateById(user);
        return "redirect:/dashboard/console";
    } catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) {
        map.addAttribute("exception", e.getMessage());
        return "common/error";
    }
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:21,代碼來源:DashboardController.java

示例9: onLoginFailure

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
/**
 * 登錄失敗調用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request,
                                 ServletResponse response) {
    String className = e.getClass().getName(), message = "";
    if (IncorrectCredentialsException.class.getName().equals(className)
            || UnknownAccountException.class.getName().equals(className)) {
        message = "用戶或密碼錯誤, 請重試.";
    } else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")) {
        message = StringUtils.replace(e.getMessage(), "msg:", "");
    } else {
        message = "係統出現點問題,請稍後再試!";
        e.printStackTrace(); // 輸出到控製台
    }
    request.setAttribute(getFailureKeyAttribute(), className);
    request.setAttribute(getMessageParam(), message);
    return true;
}
 
開發者ID:ansafari,項目名稱:melon,代碼行數:21,代碼來源:FormAuthenticationFilter.java

示例10: doGetAuthenticationInfo

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String phoneNumber = (String)token.getPrincipal();
       if(StringUtils.trimToNull(phoneNumber) == null){
           throw new IncorrectCredentialsException();//賬號或密碼錯誤
       }
	CdMember query = new CdMember();
	query.setPhoneNumber(phoneNumber);
       CdMember member = memberService.findMember(query);
       if(member == null) {
           throw new UnknownAccountException();//沒找到帳號
       }
       SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
               phoneNumber, //用戶名
               member.getPassword(), //密碼
               ByteSource.Util.bytes(AppConstants.PC_PASSWORD_SALT),//salt=phoneNumber
               getName()  //realm name
       );
       return authenticationInfo;
}
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:21,代碼來源:MemberRealm.java

示例11: login

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@RequestMapping(value = "/member/login", method = RequestMethod.POST)
  public ResponseEntity login(HttpServletRequest request, Model model){
Map<String, Object> result = new HashMap<>();
      if(SecurityUtils.getSubject().isAuthenticated()){
	String username = (String) SecurityUtils.getSubject().getPrincipal();
	result.put("status", 200);
	result.put("username", username);
          return new ResponseEntity(result, HttpStatus.OK);
      }
String exceptionClassName = (String) request.getAttribute(FormAuthenticationFilterExt.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
      String error = null;
RestError restError = new RestError();
restError.setTimestamp(new Date());
      if(DisabledAccountException.class.getName().equals(exceptionClassName)){
	restError.setMessage("該賬號已被鎖定,請聯係客服。");
}else if(UnknownAccountException.class.getName().equals(exceptionClassName)) {
	restError.setMessage("用戶名不存在");
      } else if(IncorrectCredentialsException.class.getName().equals(exceptionClassName)) {
	restError.setMessage("用戶名或密碼錯誤");
      } else if(exceptionClassName != null) {
	restError.setMessage( "登錄失敗:" + exceptionClassName);
      }
restError.setStatus(401);
return new ResponseEntity(restError, HttpStatus.UNAUTHORIZED);
  }
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:26,代碼來源:CommonMemberController.java

示例12: login

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@RequestMapping(value = "/login")
public String login(HttpServletRequest request, Model model){
    if(SecurityUtils.getSubject().isAuthenticated()){
        return "redirect:/";
    }
    String exceptionClassName = (String)request.getAttribute("shiroLoginFailure");
    String error = null;
    if(UnknownAccountException.class.getName().equals(exceptionClassName)) {
        error = "用戶名/密碼錯誤";
    } else if(IncorrectCredentialsException.class.getName().equals(exceptionClassName)) {
        error = "用戶名/密碼錯誤";
    } else if(exceptionClassName != null) {
        error = "其他錯誤:" + exceptionClassName;
    }
    model.addAttribute("error", error);
    return "login";
}
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:18,代碼來源:CoreController.java

示例13: login

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@POST
@Path("login")
public Response login(@NotNull @FormParam("username") String username,
                      @NotNull @FormParam("password") String password,
                      @NotNull @FormParam("rememberMe") boolean rememberMe,
                      @Context HttpServletRequest request) {

    boolean justLogged = SecurityUtils.getSubject().isAuthenticated();

    try {
        SecurityUtils.getSubject().login(new UsernamePasswordToken(username, password, rememberMe));
    } catch (Exception e) {
        throw new IncorrectCredentialsException("Unknown user, please try again");
    }

    SavedRequest savedRequest = WebUtils.getAndClearSavedRequest(request);
    monitoring.fire(new AuthenticationEvent(username, AuthenticationEvent.Type.LOGIN));
    if (savedRequest != null) {
        return this.getRedirectResponse(savedRequest.getRequestUrl(), request);
    } else {
        if (justLogged) {
            return this.getRedirectResponse(WebPages.DASHBOARD_URL, request);
        }
        return this.getRedirectResponse(WebPages.HOME_URL, request);
    }
}
 
開發者ID:nebrass,項目名稱:pairing-shiro-javaee7,代碼行數:27,代碼來源:AuthenticationResource.java

示例14: login

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public Result<User> login(String username, String password)
		throws IOException {
	// response.setHeader("resetCookie", "true");
	if (TextUtil.isEmpty(username) || TextUtil.isEmpty(password)) {
		return new Result<User>(false, "用戶名或密碼為空",
				null);
	}
	Result<User> result;
	try {
		User returnUser = accountService.login(username, password);
		if (returnUser != null) {
			// response.setHeader("resetCookie", "true");
			result = new Result<User>(true, null, returnUser);
		} else {
			result = new Result<User>(false, "登錄失敗.", null);
		}
	} catch (IncorrectCredentialsException e) {
		result = new Result<User>(false, "帳號密碼錯誤", null);
	} catch (UnknownAccountException e1) {
		result = new Result<User>(false, "帳號密碼錯誤", null);
	}
	return result;
}
 
開發者ID:inexistence,項目名稱:VideoMeeting,代碼行數:26,代碼來源:AccountController.java

示例15: onLoginFailure

import org.apache.shiro.authc.IncorrectCredentialsException; //導入依賴的package包/類
/**
 * 登錄失敗調用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token,
                                 AuthenticationException e, ServletRequest request, ServletResponse response) {
	String className = e.getClass().getName(), message = "";
	if (IncorrectCredentialsException.class.getName().equals(className)
			|| UnknownAccountException.class.getName().equals(className)){
		message = "用戶或密碼錯誤, 請重試.";
	}
	else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")){
		message = StringUtils.replace(e.getMessage(), "msg:", "");
	}
	else{
		message = "係統出現點問題,請稍後再試!";
		e.printStackTrace(); // 輸出到控製台
	}
       request.setAttribute(getFailureKeyAttribute(), className);
       request.setAttribute(getMessageParam(), message);
       return true;
}
 
開發者ID:whatlookingfor,項目名稱:spring-boot-sample,代碼行數:23,代碼來源:FormAuthenticationFilter.java


注:本文中的org.apache.shiro.authc.IncorrectCredentialsException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。