This commit is contained in:
Anthony Stirling 2023-12-25 15:15:46 +00:00
parent 7fb8f5ed28
commit a286a92ede
5 changed files with 4 additions and 23 deletions

View file

@ -37,7 +37,8 @@ public class InitialSecuritySetup {
initialPassword = "stirling"; initialPassword = "stirling";
userService.saveUser(initialUsername, initialPassword, Role.ADMIN.getRoleId(), true); userService.saveUser(initialUsername, initialPassword, Role.ADMIN.getRoleId(), true);
} }
}
if(!userService.usernameExists(Role.INTERNAL_API_USER.getRoleId())) {
userService.saveUser(Role.INTERNAL_API_USER.getRoleId(), UUID.randomUUID().toString(), Role.INTERNAL_API_USER.getRoleId()); userService.saveUser(Role.INTERNAL_API_USER.getRoleId(), UUID.randomUUID().toString(), Role.INTERNAL_API_USER.getRoleId());
userService.addApiKeyToUser(Role.INTERNAL_API_USER.getRoleId()); userService.addApiKeyToUser(Role.INTERNAL_API_USER.getRoleId());
} }

View file

@ -9,17 +9,15 @@ import stirling.software.SPDF.model.AttemptCounter;
@Service @Service
public class LoginAttemptService { public class LoginAttemptService {
private final int MAX_ATTEMPTS = 2; private final int MAX_ATTEMPTS = 10;
private final long ATTEMPT_INCREMENT_TIME = TimeUnit.MINUTES.toMillis(1); private final long ATTEMPT_INCREMENT_TIME = TimeUnit.MINUTES.toMillis(1);
private final ConcurrentHashMap<String, AttemptCounter> attemptsCache = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, AttemptCounter> attemptsCache = new ConcurrentHashMap<>();
public void loginSucceeded(String key) { public void loginSucceeded(String key) {
System.out.println("here3 reset ");
attemptsCache.remove(key); attemptsCache.remove(key);
} }
public boolean loginAttemptCheck(String key) { public boolean loginAttemptCheck(String key) {
System.out.println("here");
attemptsCache.compute(key, (k, attemptCounter) -> { attemptsCache.compute(key, (k, attemptCounter) -> {
if (attemptCounter == null || attemptCounter.shouldReset(ATTEMPT_INCREMENT_TIME)) { if (attemptCounter == null || attemptCounter.shouldReset(ATTEMPT_INCREMENT_TIME)) {
return new AttemptCounter(); return new AttemptCounter();
@ -28,7 +26,6 @@ public class LoginAttemptService {
return attemptCounter; return attemptCounter;
} }
}); });
System.out.println("here2 = " + attemptsCache.get(key).getAttemptCount());
return attemptsCache.get(key).getAttemptCount() >= MAX_ATTEMPTS; return attemptsCache.get(key).getAttemptCount() >= MAX_ATTEMPTS;
} }

View file

@ -96,7 +96,7 @@ public class SecurityConfiguration {
@Bean @Bean
public IPRateLimitingFilter rateLimitingFilter() { public IPRateLimitingFilter rateLimitingFilter() {
int maxRequestsPerIp = 10000; // Example limit int maxRequestsPerIp = 1000000; // Example limit TODO add config level
return new IPRateLimitingFilter(maxRequestsPerIp, maxRequestsPerIp); return new IPRateLimitingFilter(maxRequestsPerIp, maxRequestsPerIp);
} }

View file

@ -1,5 +1,4 @@
package stirling.software.SPDF.controller.api.pipeline; package stirling.software.SPDF.controller.api.pipeline;
public interface UserServiceInterface { public interface UserServiceInterface {
// Define methods that you need
String getApiKeyForUser(String username); String getApiKeyForUser(String username);
} }

View file

@ -1,16 +0,0 @@
package stirling.software.SPDF.controller.api.pipeline;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
@Service
@ConditionalOnProperty(name = "DOCKER_ENABLE_SECURITY", havingValue = "false")
public class UserServiceNoOpImpl implements UserServiceInterface {
// Implement the methods with no-op
@Override
public String getApiKeyForUser(String username) {
// No-op implementation
return "";
}
}