You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package com.xmomen.module.account.credentials ;
import org.apache.shiro.authc.AuthenticationInfo ;
import org.apache.shiro.authc.AuthenticationToken ;
import org.apache.shiro.authc.ExcessiveAttemptsException ;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher ;
import org.apache.shiro.cache.Cache ;
import org.apache.shiro.cache.CacheManager ;
import java.util.concurrent.atomic.AtomicInteger ;
public class RetryLimitHashedCredentialsMatcher extends HashedCredentialsMatcher {
//密码重试缓存
private Cache < String , AtomicInteger > passwordRetryCache ;
//构造函数, 传入CacheManager
public RetryLimitHashedCredentialsMatcher ( CacheManager cacheManager ) {
passwordRetryCache = cacheManager . getCache ( "passwordRetryCache" ) ;
}
//重写doCredentialsMatch方法, 实现密码重试限制
@Override
public boolean doCredentialsMatch ( AuthenticationToken token , AuthenticationInfo info ) {
//获取用户名
String username = ( String ) token . getPrincipal ( ) ;
boolean matches = super . doCredentialsMatch ( token , info ) ;
if ( matches ) {
//clear retry count
passwordRetryCache . remove ( username ) ;
}
return matches ;
}
}