public abstract class RequestLimiter extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
CACHE_CAPTCHA_KEY
image captcha code verify key
|
static String |
CACHE_CODE_KEY
validation code verify key
|
static String |
CHECK_CODE_KEY |
static String |
CHECK_FREQ_KEY
limit operation key
|
static String |
CHECK_THRE_KEY |
static String |
TRACE_ACTION_KEY
count operation action key
|
| 构造器和说明 |
|---|
RequestLimiter() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
buildNonce(String code,
String salt)
生成nonce校验码(返回到用户端)
|
abstract void |
cacheCaptcha(String key,
String captcha,
int expire)
cache captcha of server generate
|
abstract void |
cacheCode(String key,
String code,
int ttl)
cache for the server generate validation code
|
boolean |
checkCaptcha(String key,
String captcha) |
abstract boolean |
checkCaptcha(String key,
String captcha,
boolean caseSensitive)
check captcha of user input
|
abstract RequestLimiter |
checkCode(String key,
String code,
int limit)
check the validation code of user input is equals server cache
|
abstract long |
countAction(String key)
统计周期内的行为量
用于登录失败达到一定次数后锁定账户等场景
|
static String |
format(int seconds)
时间格式化,5/6 rate
|
RequestLimiter |
limitFrequency(String key,
int period) |
abstract RequestLimiter |
limitFrequency(String key,
int period,
String message)
访问频率限制:一个周期内最多允许访问1次
比如短信60秒内只能发送一次
|
RequestLimiter |
limitThreshold(String key,
int period,
int limit) |
abstract RequestLimiter |
limitThreshold(String key,
int period,
int limit,
String message)
访问次数限制:一个周期内最多允许访问limit次
比如一个手机号一天只能发10次
|
abstract void |
recordAction(String key,
int period)
计数周期内的行为
用于登录失败达到一定次数后锁定账户等场景
|
abstract void |
resetAction(String key)
重置行为
|
static boolean |
verifyNonce(String nonce,
String code,
String salt)
校验nonce
|
public static final String CACHE_CAPTCHA_KEY
public final RequestLimiter limitFrequency(String key, int period) throws RequestLimitException
public abstract RequestLimiter limitFrequency(String key, int period, String message) throws RequestLimitException
比如短信60秒内只能发送一次
key - the keyperiod - the periodmessage - the messageRequestLimitException - if over limit occurspublic final RequestLimiter limitThreshold(String key, int period, int limit) throws RequestLimitException
public abstract RequestLimiter limitThreshold(String key, int period, int limit, String message) throws RequestLimitException
key - the keyperiod - the periodlimit - the limitmessage - the messageRequestLimitException - if over limit occurspublic abstract void cacheCode(String key, String code, int ttl)
key - the cache keycode - the validation code of server generatettl - the expire timepublic abstract RequestLimiter checkCode(String key, String code, int limit) throws RequestLimitException
key - the cache keycode - the validation code of user inputlimit - the maximum fail input timesRequestLimitException - if over limit occurspublic abstract void cacheCaptcha(String key, String captcha, int expire)
key - captcha - the image captcha code of server generateexpire - 缓存有效时间public abstract boolean checkCaptcha(String key, String captcha, boolean caseSensitive)
key - the cache keycaptcha - the captchacaseSensitive - is case sensitivepublic abstract void recordAction(String key, int period)
用于登录失败达到一定次数后锁定账户等场景
key - period - public abstract long countAction(String key)
用于登录失败达到一定次数后锁定账户等场景
key - the keypublic abstract void resetAction(String key)
key - the keypublic static String buildNonce(String code, String salt)
code - a string like as captcha codesalt - a string like as mobile phonepublic static boolean verifyNonce(String nonce, String code, String salt)
nonce - the noncecode - the codesalt - the salttrue is verify successpublic static String format(int seconds)
seconds - Copyright © 2023. All rights reserved.