Skip to content

Commit

Permalink
CB-5322 naming
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-skoblikov committed Jul 1, 2024
1 parent f254613 commit 1db8315
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ public class BruteForceUtils {

private static final Log log = Log.getLog(BruteForceUtils.class);

public static void checkBruteforce(SMControllerConfiguration smConfig, List<UserLoginRecord> latestLogins) throws DBException {
if (latestLogins.isEmpty()) {
public static void checkBruteforce(SMControllerConfiguration smConfig, List<UserLoginRecord> latestLoginAttempts)

Check warning on line 33 in server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/bruteforce/BruteForceUtils.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/bruteforce/BruteForceUtils.java#L33

Missing a Javadoc comment.
throws DBException {

Check warning on line 34 in server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/bruteforce/BruteForceUtils.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.service.security/src/io/cloudbeaver/service/security/bruteforce/BruteForceUtils.java#L34

throws has incorrect indentation level 8, expected level should be 12.
if (latestLoginAttempts.isEmpty()) {
return;
}

var oldestLogin = latestLogins.get(latestLogins.size() - 1);
checkLoginInterval(oldestLogin.time(), smConfig.getMinimumLoginTimeout());
var oldestLoginAttempt = latestLoginAttempts.get(latestLoginAttempts.size() - 1);
checkLoginInterval(oldestLoginAttempt.time(), smConfig.getMinimumLoginTimeout());

long errorsCount = latestLogins.stream()
long errorsCount = latestLoginAttempts.stream()
.filter(authAttemptSessionInfo -> authAttemptSessionInfo.smAuthStatus() == SMAuthStatus.ERROR).count();

boolean shouldBlock = errorsCount >= smConfig.getMaxFailedLogin();
if (shouldBlock) {
int blockPeriod = smConfig.getBlockLoginPeriod();
LocalDateTime unblockTime = oldestLogin.time().plusSeconds(blockPeriod);
LocalDateTime unblockTime = oldestLoginAttempt.time().plusSeconds(blockPeriod);

LocalDateTime now = LocalDateTime.now();
shouldBlock = unblockTime.isAfter(now);
Expand All @@ -54,7 +55,7 @@ public static void checkBruteforce(SMControllerConfiguration smConfig, List<User
Duration lockDuration = Duration.ofSeconds(smConfig.getBlockLoginPeriod());

throw new SMException("Blocked the possibility of login for this user for " +
lockDuration.minus(Duration.between(oldestLogin.time(), now)).getSeconds() + " seconds");
lockDuration.minus(Duration.between(oldestLoginAttempt.time(), now)).getSeconds() + " seconds");
}
}
}
Expand Down

0 comments on commit 1db8315

Please sign in to comment.