Search in sources :

Example 16 with RequiredActionProviderRepresentation

use of org.keycloak.representations.idm.RequiredActionProviderRepresentation in project keycloak by keycloak.

the class AbstractWebAuthnVirtualTest method makePasswordlessRequiredActionDefault.

protected static void makePasswordlessRequiredActionDefault(RealmRepresentation realm) {
    RequiredActionProviderRepresentation webAuthnProvider = realm.getRequiredActions().stream().filter(f -> f.getProviderId().equals(WebAuthnRegisterFactory.PROVIDER_ID)).findFirst().orElse(null);
    assertThat(webAuthnProvider, notNullValue());
    webAuthnProvider.setEnabled(false);
    RequiredActionProviderRepresentation webAuthnPasswordlessProvider = realm.getRequiredActions().stream().filter(f -> f.getProviderId().equals(WebAuthnPasswordlessRegisterFactory.PROVIDER_ID)).findFirst().orElse(null);
    assertThat(webAuthnPasswordlessProvider, notNullValue());
    webAuthnPasswordlessProvider.setEnabled(true);
    webAuthnPasswordlessProvider.setDefaultAction(true);
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation)

Example 17 with RequiredActionProviderRepresentation

use of org.keycloak.representations.idm.RequiredActionProviderRepresentation in project keycloak by keycloak.

the class RequiredActionsTest method testCRUDRequiredAction.

@Test
public void testCRUDRequiredAction() {
    int lastPriority = authMgmtResource.getRequiredActions().get(authMgmtResource.getRequiredActions().size() - 1).getPriority();
    // Dummy RequiredAction is not registered in the realm and WebAuthn actions
    List<RequiredActionProviderSimpleRepresentation> result = authMgmtResource.getUnregisteredRequiredActions();
    Assert.assertEquals(4, result.size());
    RequiredActionProviderSimpleRepresentation action = result.get(0);
    Assert.assertEquals(DummyRequiredActionFactory.PROVIDER_ID, action.getProviderId());
    Assert.assertEquals("Dummy Action", action.getName());
    // Register it
    authMgmtResource.registerRequiredAction(action);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authMgmtBasePath() + "/register-required-action", action, ResourceType.REQUIRED_ACTION);
    // Try to find not-existent action - should fail
    try {
        authMgmtResource.getRequiredAction("not-existent");
        Assert.fail("Didn't expect to find requiredAction of alias 'not-existent'");
    } catch (NotFoundException nfe) {
    // Expected
    }
    // Find existent
    RequiredActionProviderRepresentation rep = authMgmtResource.getRequiredAction(DummyRequiredActionFactory.PROVIDER_ID);
    compareRequiredAction(rep, newRequiredAction(DummyRequiredActionFactory.PROVIDER_ID, "Dummy Action", true, false, Collections.<String, String>emptyMap()));
    // Confirm the registered priority - should be N + 1
    Assert.assertEquals(lastPriority + 1, rep.getPriority());
    // Update not-existent - should fail
    try {
        authMgmtResource.updateRequiredAction("not-existent", rep);
        Assert.fail("Not expected to update not-existent requiredAction");
    } catch (NotFoundException nfe) {
    // Expected
    }
    // Update (set it as defaultAction)
    rep.setDefaultAction(true);
    authMgmtResource.updateRequiredAction(DummyRequiredActionFactory.PROVIDER_ID, rep);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authRequiredActionPath(rep.getAlias()), rep, ResourceType.REQUIRED_ACTION);
    compareRequiredAction(rep, newRequiredAction(DummyRequiredActionFactory.PROVIDER_ID, "Dummy Action", true, true, Collections.<String, String>emptyMap()));
    // Remove unexistent - should fail
    try {
        authMgmtResource.removeRequiredAction("not-existent");
        Assert.fail("Not expected to remove not-existent requiredAction");
    } catch (NotFoundException nfe) {
    // Expected
    }
    // Remove success
    authMgmtResource.removeRequiredAction(DummyRequiredActionFactory.PROVIDER_ID);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.DELETE, AdminEventPaths.authRequiredActionPath(rep.getAlias()), ResourceType.REQUIRED_ACTION);
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) NotFoundException(javax.ws.rs.NotFoundException) RequiredActionProviderSimpleRepresentation(org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation) Test(org.junit.Test)

Example 18 with RequiredActionProviderRepresentation

use of org.keycloak.representations.idm.RequiredActionProviderRepresentation in project keycloak by keycloak.

the class RequiredActionsTest method newRequiredAction.

private RequiredActionProviderRepresentation newRequiredAction(String alias, String name, boolean enabled, boolean defaultAction, Map<String, String> conf) {
    RequiredActionProviderRepresentation action = new RequiredActionProviderRepresentation();
    action.setAlias(alias);
    action.setName(name);
    action.setEnabled(enabled);
    action.setDefaultAction(defaultAction);
    action.setConfig(conf);
    return action;
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation)

Example 19 with RequiredActionProviderRepresentation

use of org.keycloak.representations.idm.RequiredActionProviderRepresentation in project keycloak by keycloak.

the class RequiredActionsTest method testRequiredActions.

@Test
public void testRequiredActions() {
    List<RequiredActionProviderRepresentation> result = authMgmtResource.getRequiredActions();
    List<RequiredActionProviderRepresentation> expected = new ArrayList<>();
    addRequiredAction(expected, "CONFIGURE_TOTP", "Configure OTP", true, false, null);
    addRequiredAction(expected, "UPDATE_PASSWORD", "Update Password", true, false, null);
    addRequiredAction(expected, "UPDATE_PROFILE", "Update Profile", true, false, null);
    addRequiredAction(expected, "VERIFY_EMAIL", "Verify Email", true, false, null);
    addRequiredAction(expected, "delete_account", "Delete Account", false, false, null);
    addRequiredAction(expected, "terms_and_conditions", "Terms and Conditions", false, false, null);
    addRequiredAction(expected, "update_user_locale", "Update User Locale", true, false, null);
    compareRequiredActions(expected, sort(result));
    RequiredActionProviderRepresentation forUpdate = newRequiredAction("VERIFY_EMAIL", "Verify Email", false, false, null);
    authMgmtResource.updateRequiredAction(forUpdate.getAlias(), forUpdate);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authRequiredActionPath(forUpdate.getAlias()), ResourceType.REQUIRED_ACTION);
    result = authMgmtResource.getRequiredActions();
    RequiredActionProviderRepresentation updated = findRequiredActionByAlias(forUpdate.getAlias(), result);
    Assert.assertNotNull("Required Action still there", updated);
    compareRequiredAction(forUpdate, updated);
    forUpdate.setConfig(Collections.<String, String>emptyMap());
    authMgmtResource.updateRequiredAction(forUpdate.getAlias(), forUpdate);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authRequiredActionPath(forUpdate.getAlias()), ResourceType.REQUIRED_ACTION);
    result = authMgmtResource.getRequiredActions();
    updated = findRequiredActionByAlias(forUpdate.getAlias(), result);
    Assert.assertNotNull("Required Action still there", updated);
    compareRequiredAction(forUpdate, updated);
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 20 with RequiredActionProviderRepresentation

use of org.keycloak.representations.idm.RequiredActionProviderRepresentation in project keycloak by keycloak.

the class BrowserFlowTest method testLoginWithWithNoOTPCredentialAndRequiredActionProviderDisabled.

/**
 * This test checks that if a REQUIRED authentication execution which has isUserSetupAllowed -> true
 * has its requiredActionProvider disabled, then it will not try to create the required action,
 * and will instead raise an credential setup required error.
 */
@Test
@AuthServerContainerExclude(REMOTE)
public void testLoginWithWithNoOTPCredentialAndRequiredActionProviderDisabled() {
    String newFlowAlias = "browser - copy 1";
    configureBrowserFlowWithRequiredOTP(newFlowAlias);
    RequiredActionProviderRepresentation otpRequiredAction = testRealm().flows().getRequiredAction("CONFIGURE_TOTP");
    otpRequiredAction.setEnabled(false);
    testRealm().flows().updateRequiredAction("CONFIGURE_TOTP", otpRequiredAction);
    try {
        provideUsernamePassword("test-user@localhost");
        // Assert that the login evaluates to an error, as all required elements to not validate to successful
        errorPage.assertCurrent();
    } finally {
        revertFlows("browser - copy 1");
        otpRequiredAction.setEnabled(true);
        testRealm().flows().updateRequiredAction("CONFIGURE_TOTP", otpRequiredAction);
    }
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) Matchers.containsString(org.hamcrest.Matchers.containsString) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) SocialLoginTest(org.keycloak.testsuite.broker.SocialLoginTest) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AbstractAuthenticationTest(org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)

Aggregations

RequiredActionProviderRepresentation (org.keycloak.representations.idm.RequiredActionProviderRepresentation)33 Test (org.junit.Test)13 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)6 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)5 ArrayList (java.util.ArrayList)4 RealmResource (org.keycloak.admin.client.resource.RealmResource)4 RequiredActionProviderSimpleRepresentation (org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation)4 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)4 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Before (org.junit.Before)3 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)3 SocialLoginTest (org.keycloak.testsuite.broker.SocialLoginTest)3 HashMap (java.util.HashMap)2 NotFoundException (javax.ws.rs.NotFoundException)2 SigningInPage (org.keycloak.testsuite.ui.account2.page.SigningInPage)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1