mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 00:30:21 +01:00
Enumerate rate limit challenge options
This commit is contained in:
committed by
Jon Chambers
parent
2b07a21477
commit
6af4d41322
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2025 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.limits;
|
||||
|
||||
public enum RateLimitChallengeOption {
|
||||
CAPTCHA("captcha"),
|
||||
PUSH_CHALLENGE("pushChallenge");
|
||||
|
||||
private final String apiName;
|
||||
|
||||
RateLimitChallengeOption(final String apiName) {
|
||||
this.apiName = apiName;
|
||||
}
|
||||
|
||||
public String getApiName() {
|
||||
return apiName;
|
||||
}
|
||||
}
|
||||
@@ -13,26 +13,23 @@ public class RateLimitChallengeOptionManager {
|
||||
|
||||
private final RateLimiters rateLimiters;
|
||||
|
||||
public static final String OPTION_CAPTCHA = "captcha";
|
||||
public static final String OPTION_PUSH_CHALLENGE = "pushChallenge";
|
||||
|
||||
public RateLimitChallengeOptionManager(final RateLimiters rateLimiters) {
|
||||
this.rateLimiters = rateLimiters;
|
||||
}
|
||||
|
||||
public List<String> getChallengeOptions(final Account account) {
|
||||
final List<String> options = new ArrayList<>(2);
|
||||
public List<RateLimitChallengeOption> getChallengeOptions(final Account account) {
|
||||
final List<RateLimitChallengeOption> options = new ArrayList<>(2);
|
||||
|
||||
if (rateLimiters.getCaptchaChallengeAttemptLimiter().hasAvailablePermits(account.getUuid(), 1) &&
|
||||
rateLimiters.getCaptchaChallengeSuccessLimiter().hasAvailablePermits(account.getUuid(), 1)) {
|
||||
|
||||
options.add(OPTION_CAPTCHA);
|
||||
options.add(RateLimitChallengeOption.CAPTCHA);
|
||||
}
|
||||
|
||||
if (rateLimiters.getPushChallengeAttemptLimiter().hasAvailablePermits(account.getUuid(), 1) &&
|
||||
rateLimiters.getPushChallengeSuccessLimiter().hasAvailablePermits(account.getUuid(), 1)) {
|
||||
|
||||
options.add(OPTION_PUSH_CHALLENGE);
|
||||
options.add(RateLimitChallengeOption.PUSH_CHALLENGE);
|
||||
}
|
||||
|
||||
return options;
|
||||
|
||||
Reference in New Issue
Block a user