Bruteforce protector does not work when using organizations

Closes #31204

Signed-off-by: Pedro Igor <pigor.craveiro@gmail.com>
This commit is contained in:
Pedro Igor 2024-07-10 18:46:17 -03:00 committed by Alexander Schwartz
parent bd90ead892
commit da6c9ab7c1
2 changed files with 35 additions and 3 deletions

View file

@ -181,10 +181,12 @@ public class DefaultBruteForceProtector implements BruteForceProtector {
}
private void processLogin(RealmModel realm, UserModel user, ClientConnection clientConnection, boolean success) {
KeycloakSession session = factory.create();
ExecutorsProvider provider = session.getProvider(ExecutorsProvider.class);
ExecutorService executor = provider.getExecutor("bruteforce");
ExecutorService executor = KeycloakModelUtils.runJobInTransactionWithResult(factory, session -> {
ExecutorsProvider provider = session.getProvider(ExecutorsProvider.class);
return provider.getExecutor("bruteforce");
});
executor.execute(() -> KeycloakModelUtils.runJobInTransaction(factory, s -> {
s.getContext().setRealm(s.realms().getRealm(realm.getId()));
if (success) {
success(s, realm, user.getId());
} else {

View file

@ -0,0 +1,30 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.keycloak.testsuite.organization.member;
import org.keycloak.common.Profile.Feature;
import org.keycloak.testsuite.arquillian.annotation.EnableFeature;
import org.keycloak.testsuite.forms.BruteForceTest;
/**
* Remove this test class once the {@link Feature#ORGANIZATION} is supported
*/
@EnableFeature(Feature.ORGANIZATION)
public class OrganizationBruteForceTest extends BruteForceTest {
}