Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-5322 limit latest logins by time #2750

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1685,13 +1685,15 @@ private List<UserLoginRecord> getLatestUserLogins(Connection dbCon, String authP
" {table_prefix}CB_AUTH_ATTEMPT attempt" +
" JOIN" +
" {table_prefix}CB_AUTH_ATTEMPT_INFO info ON attempt.AUTH_ID = info.AUTH_ID" +
" WHERE AUTH_PROVIDER_ID = ? AND AUTH_USERNAME = ?" +
" WHERE AUTH_PROVIDER_ID = ? AND AUTH_USERNAME = ? AND attempt.CREATE_TIME > ?" +
" ORDER BY attempt.CREATE_TIME DESC " +
database.getDialect().getOffsetLimitQueryPart(0, smConfig.getMaxFailedLogin())
)
)) {
dbStat.setString(1, authProviderId);
dbStat.setString(2, inputLogin);
dbStat.setTimestamp(3,
Timestamp.valueOf(LocalDateTime.now().minusSeconds(smConfig.getBlockLoginPeriod())));
try (ResultSet dbResult = dbStat.executeQuery()) {
while (dbResult.next()) {
UserLoginRecord loginDto = new UserLoginRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@

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 latestLogin = latestLogins.get(0);
checkLoginInterval(latestLogin.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 = latestLogin.time().plusSeconds(blockPeriod);
LocalDateTime unblockTime = oldestLoginAttempt.time().plusSeconds(blockPeriod);

LocalDateTime now = LocalDateTime.now();
shouldBlock = unblockTime.isAfter(now);
Expand All @@ -54,7 +55,7 @@
Duration lockDuration = Duration.ofSeconds(smConfig.getBlockLoginPeriod());

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