Merge pull request #3039 from stianst/KEYCLOAK-3192

KEYCLOAK-3192 Ignore disabled required action
This commit is contained in:
Stian Thorgersen 2016-07-15 10:38:49 +02:00 committed by GitHub
commit 1ce17c459d
2 changed files with 27 additions and 0 deletions

View file

@ -570,6 +570,10 @@ public class AuthenticationManager {
Set<String> requiredActions) {
for (String action : requiredActions) {
RequiredActionProviderModel model = realm.getRequiredActionProviderByAlias(action);
if (!model.isEnabled()) {
continue;
}
RequiredActionFactory factory = (RequiredActionFactory)session.getKeycloakSessionFactory().getProviderFactory(RequiredActionProvider.class, model.getProviderId());
if (factory == null) {
throw new RuntimeException("Unable to find factory for Required Action: " + model.getProviderId() + " did you forget to declare it in a META-INF/services file?");

View file

@ -23,6 +23,8 @@ import org.keycloak.authentication.requiredactions.TermsAndConditions;
import org.keycloak.events.Details;
import org.keycloak.events.Errors;
import org.keycloak.events.EventType;
import org.keycloak.models.RequiredActionProviderModel;
import org.keycloak.representations.idm.RequiredActionProviderRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
import org.keycloak.testsuite.AssertEvents;
import org.keycloak.testsuite.pages.AppPage;
@ -66,6 +68,10 @@ public class TermsAndConditionsTest extends TestRealmKeycloakTest {
UserRepresentation user = ActionUtil.findUserWithAdminClient(adminClient, "test-user@localhost");
UserBuilder.edit(user).requiredAction(TermsAndConditions.PROVIDER_ID);
adminClient.realm("test").users().get(user.getId()).update(user);
RequiredActionProviderRepresentation rep = adminClient.realm("test").flows().getRequiredAction("terms_and_conditions");
rep.setEnabled(true);
adminClient.realm("test").flows().updateRequiredAction("terms_and_conditions", rep);
}
@Test
@ -128,4 +134,21 @@ public class TermsAndConditionsTest extends TestRealmKeycloakTest {
}
@Test
// KEYCLOAK-3192
public void termsDisabled() {
RequiredActionProviderRepresentation rep = adminClient.realm("test").flows().getRequiredAction("terms_and_conditions");
rep.setEnabled(false);
adminClient.realm("test").flows().updateRequiredAction("terms_and_conditions", rep);
loginPage.open();
loginPage.login("test-user@localhost", "password");
assertTrue(appPage.isCurrent());
events.expectLogin().assertEvent();
}
}