当前位置: 首页>>代码示例>>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;未经允许,请勿转载。