本文整理汇总了Java中org.apache.shiro.authc.ExcessiveAttemptsException类的典型用法代码示例。如果您正苦于以下问题:Java ExcessiveAttemptsException类的具体用法?Java ExcessiveAttemptsException怎么用?Java ExcessiveAttemptsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExcessiveAttemptsException类属于org.apache.shiro.authc包,在下文中一共展示了ExcessiveAttemptsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeLogin
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
@Override
public boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception {
AuthenticationToken token = createToken(request, response);
if (token == null) {
String msg = "createToken method implementation returned null. A valid non-null AuthenticationToken "
+ "must be created in order to execute a login attempt.";
throw new IllegalStateException(msg);
}
if (checkIfAccountLocked(request)) {
return onLoginFailure(token, new ExcessiveAttemptsException(), request, response);
} else {
if (!doLogin(request, response, token)) {
resetAccountLock(getUsername(request));
return false;
}
return true;
}
}
示例2: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的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;
}
示例3: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
String userName = (String)token.getPrincipal();
final String key = REDIS_KEY_PREFIX + userName;
long maxRetry = redisTemplate.opsForValue().increment(key, 1);
if(maxRetry == 1){ //首次输入密码
redisTemplate.expire(key, passwordRetryWaitMinutes, TimeUnit.MINUTES);
}
if(maxRetry >= passwordRetryLimit){
throw new ExcessiveAttemptsException(passwordRetryLimit + "");
}
boolean matches = super.doCredentialsMatch(token, info);
if(matches) {
redisTemplate.delete(key);
}
return matches;
}
示例4: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info){
String username = (String) token.getPrincipal();
Element element = passwordRetryCache.get(username);
if(element == null){
element = new Element(username, new AtomicInteger(0));
passwordRetryCache.put(element);
}
AtomicInteger retryCount = (AtomicInteger) element.getObjectValue();
if(retryCount.incrementAndGet() > 5){
throw new ExcessiveAttemptsException();
}
boolean matches = super.doCredentialsMatch(token, info);
if(matches){
passwordRetryCache.remove(username);
}
return matches;
}
示例5: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
if (token instanceof UsernamePasswordToken) {
String username = ((UsernamePasswordToken) token).getUsername();
AtomicInteger retryCount = passwordRetryCache.get(username);
if (retryCount == null) {
retryCount = new AtomicInteger(0);
passwordRetryCache.put(username, retryCount);
}
if (retryCount.incrementAndGet() > maxRetryCount) {
throw new ExcessiveAttemptsException();
}
boolean matched = super.doCredentialsMatch(token, info);
if (matched) {
passwordRetryCache.remove(username);
}
return matched;
}
return super.doCredentialsMatch(token, info);
}
示例6: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
@Override
public boolean doCredentialsMatch(AuthenticationToken token,
AuthenticationInfo info) {
String username = (String) token.getPrincipal();
// retry count + 1
if (passwordRetryCache != null) {
AtomicInteger retryCount = passwordRetryCache.get(username);
if (retryCount == null) {
retryCount = new AtomicInteger(0);
passwordRetryCache.put(username, retryCount);
}
if (retryCount.incrementAndGet() > 5) {
// if retry count > 5 throw
throw new ExcessiveAttemptsException();
}
}
boolean matches = super.doCredentialsMatch(token, info);
if (matches && passwordRetryCache != null) {
// clear retry count
passwordRetryCache.remove(username);
}
return matches;
}
示例7: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
String username = (String) token.getPrincipal();
//retry count + 1
AtomicInteger retryCount = (AtomicInteger) SilentGo.me().getConfig().getCacheManager().get("passwordRetryCache", username);
if (retryCount == null) {
retryCount = new AtomicInteger(0);
SilentGo.me().getConfig().getCacheManager().set("passwordRetryCache", username, retryCount);
}
if (retryCount.incrementAndGet() > 5) {
//if retry count > 5 throw
throw new ExcessiveAttemptsException();
}
boolean matches = super.doCredentialsMatch(token, info);
if (matches) {
//clear retry count
SilentGo.me().getConfig().getCacheManager().evict("passwordRetryCache", username);
}
return matches;
}
示例8: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
public boolean doCredentialsMatch(final AuthenticationToken token, final AuthenticationInfo info) {
Object _principal = token.getPrincipal();
final String username = ((String) _principal);
AtomicInteger retryCount = this.passwordRetryCache.get(username);
boolean _equals = Objects.equal(retryCount, null);
if (_equals) {
AtomicInteger _atomicInteger = new AtomicInteger(0);
retryCount = _atomicInteger;
this.passwordRetryCache.put(username, retryCount);
}
int _incrementAndGet = retryCount.incrementAndGet();
boolean _greaterThan = (_incrementAndGet > 5);
if (_greaterThan) {
throw new ExcessiveAttemptsException();
}
final boolean matches = super.doCredentialsMatch(token, info);
if (matches) {
this.passwordRetryCache.remove(username);
}
return matches;
}
示例9: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
String username = (String)token.getPrincipal();
//retry count + 1
AtomicInteger retryCount = passwordRetryCache.get(username);
if(retryCount == null) {
retryCount = new AtomicInteger(0);
passwordRetryCache.put(username, retryCount);
}
if(retryCount.incrementAndGet() > 5) {
//if retry count > 5 throw
throw new ExcessiveAttemptsException();
}
boolean matches = super.doCredentialsMatch(token, info);
if(matches) {
//clear retry count
passwordRetryCache.remove(username);
}
return matches;
}
开发者ID:yudar1024,项目名称:spring4-springmvc4-mybatis3-activiti,代码行数:22,代码来源:RetryLimitHashedCredentialsMatcher.java
示例10: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
@Override
public boolean doCredentialsMatch(AuthenticationToken token,
AuthenticationInfo info) {
String username = (String) token.getPrincipal();
// retry count + 1
AtomicInteger retryCount = faultPasswordCache.get(username);
if (null == retryCount) {
retryCount = new AtomicInteger(0);
faultPasswordCache.put(username, retryCount);
}
if (retryCount.incrementAndGet() > 5) {
// if retry count > 5 throw
throw new ExcessiveAttemptsException();
}
boolean matches = super.doCredentialsMatch(token, info);
if (matches) {
// clear retry count
faultPasswordCache.remove(username);
}
return matches;
}
示例11: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
String username = (String)token.getPrincipal();
AtomicInteger retryCount = passwordRetryCache.get(username);
if (retryCount == null) {
retryCount = new AtomicInteger(0);
passwordRetryCache.put(username, retryCount);
}
if (retryCount.incrementAndGet() > 10) {
throw new ExcessiveAttemptsException("您重试密码超过10次,账号已被锁定!");
}
boolean matches = super.doCredentialsMatch(token, info);
if (matches) {
passwordRetryCache.remove(username);
}
return matches;
}
示例12: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
String username = (String)token.getPrincipal();
//retry count + 1
AtomicInteger retryCount = passwordRetryCache.get(username);
if(retryCount == null) {
retryCount = new AtomicInteger(0);
passwordRetryCache.put(username, retryCount);
}
if(retryCount.incrementAndGet() > 5) {
//if retry count > 5 throw
throw new ExcessiveAttemptsException("您已连续5次密码输入错误,请过1小时之后再重试!");
}
boolean matches = super.doCredentialsMatch(token, info);
if(matches) {
//clear retry count
passwordRetryCache.remove(username);
}
return matches;
}
示例13: login
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的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 + "/";
}
}
示例14: logining
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
/**
* 用户登录
* @return
*/
@MumuLog(name = "用户登录",operater = "POST")
@RequestMapping(value = "/login",method = {RequestMethod.POST})
public ModelAndView logining(HttpServletRequest request){
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(ExcessiveAttemptsException.class.getName().equals(exceptionClassName)){
error = "输入错误次数太过,请稍后重试";
} else if(DisabledAccountException.class.getName().equals(exceptionClassName)){
error="账户被锁定,请联系管理员";
}else if(AccountUnActiveException.class.getName().equals(exceptionClassName)){
error="账户未激活,请登录邮箱激活账号!";
}else if (exceptionClassName != null) {
error = "错误提示:" + exceptionClassName;
}
Map<String,String> map=new HashMap<String,String>();
if(error!=null){
request.setAttribute("shiroLoginFailure", error);
map.put("code","500");
map.put("msg","failure");
map.put("data",error);
return new ModelAndView("login",map);
}
map.put("code","200");
map.put("msg","success");
map.put("data","登录成功");
return new ModelAndView("redirect:/system/index",map);
}
示例15: doCredentialsMatch
import org.apache.shiro.authc.ExcessiveAttemptsException; //导入依赖的package包/类
/**
* 做认证匹配
*/
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
//获取缓存key
String loginName=(String) token.getPrincipal();
String cacheName=getCacheName(loginName);
// retry count + 1
String retryCount=jedisClient.get(cacheName);
if (retryCount == null) {
//缓存两小时
jedisClient.incr(cacheName);
jedisClient.expire(cacheName,60*60*2);
}else{
int counter=Integer.parseInt(retryCount);
if(counter<5){
jedisClient.incr(cacheName);
}else{
throw new ExcessiveAttemptsException();
}
}
if(loginCredentialsHandler!=null){
loginCredentialsHandler.before();
}
boolean matches = super.doCredentialsMatch(token, info);
if (matches) {
// clear retry count
jedisClient.del(cacheName);
//用户认证成功之后 进行相关操作
if(loginCredentialsHandler!=null){
loginCredentialsHandler.after();
}
}else{
SysUser unloginUser=new SysUser();
unloginUser.setUserName(loginName);
unloginUser.setPassword(token.getCredentials().toString());
SecurityUtils.getSubject().getSession(true).setAttribute(SysUser.SYS_USER, unloginUser);
}
return matches;
}