internal API plus brute force security

This commit is contained in:
Anthony Stirling
2023-12-24 17:12:32 +00:00
parent 120b017b1a
commit 2f5d7ed712
9 changed files with 149 additions and 12 deletions

View File

@@ -0,0 +1,27 @@
package stirling.software.SPDF.model;
public class AttemptCounter {
private int attemptCount;
private long firstAttemptTime;
public AttemptCounter() {
this.attemptCount = 1;
this.firstAttemptTime = System.currentTimeMillis();
}
public void increment() {
this.attemptCount++;
this.firstAttemptTime = System.currentTimeMillis();
}
public int getAttemptCount() {
return attemptCount;
}
public long getFirstAttemptTime() {
return firstAttemptTime;
}
public boolean shouldReset(long ATTEMPT_INCREMENT_TIME) {
return System.currentTimeMillis() - firstAttemptTime > ATTEMPT_INCREMENT_TIME;
}
}

View File

@@ -14,7 +14,10 @@ public enum Role {
EXTRA_LIMITED_API_USER("ROLE_EXTRA_LIMITED_API_USER", 20, 20),
// 0 API calls per day and 20 web calls
WEB_ONLY_USER("ROLE_WEB_ONLY_USER", 0, 20);
WEB_ONLY_USER("ROLE_WEB_ONLY_USER", 0, 20),
INTERNAL_API_USER("STIRLING-PDF-BACKEND-API-USER", Integer.MAX_VALUE, Integer.MAX_VALUE);
private final String roleId;
private final int apiCallsPerDay;