Search in sources :

Example 26 with RequiredActionProviderRepresentation

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

the class AppInitiatedActionTest method executeDisabledAction.

@Test
public void executeDisabledAction() {
    RequiredActionProviderRepresentation configureTotp = testRealm().flows().getRequiredAction("CONFIGURE_TOTP");
    configureTotp.setEnabled(false);
    try {
        testRealm().flows().updateRequiredAction("CONFIGURE_TOTP", configureTotp);
        oauth.kcAction(UserModel.RequiredAction.CONFIGURE_TOTP.name()).openLoginForm();
        loginPage.login("test-user@localhost", "password");
        assertTrue(appPage.isCurrent());
        String kcActionStatus = oauth.getCurrentQuery().get("kc_action_status");
        assertEquals("error", kcActionStatus);
    } finally {
        configureTotp.setEnabled(true);
        testRealm().flows().updateRequiredAction("CONFIGURE_TOTP", configureTotp);
    }
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 27 with RequiredActionProviderRepresentation

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

the class ExportImportTest method testFullExportImport.

private void testFullExportImport() throws LifecycleException {
    testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
    testingClient.testing().exportImport().setRealmName("");
    testingClient.testing().exportImport().runExport();
    removeRealm("test");
    removeRealm("test-realm");
    Assert.assertNames(adminClient.realms().findAll(), "master");
    Map<String, RequiredActionProviderRepresentation> requiredActionsBeforeImport = new HashMap<>();
    adminClient.realm("master").flows().getRequiredActions().stream().forEach(action -> {
        requiredActionsBeforeImport.put(action.getAlias(), action);
    });
    assertNotAuthenticated("test", "test-user@localhost", "password");
    assertNotAuthenticated("test", "user1", "password");
    assertNotAuthenticated("test", "user2", "password");
    assertNotAuthenticated("test", "user3", "password");
    assertNotAuthenticated("test", "user-requiredOTP", "password");
    assertNotAuthenticated("test", "user-requiredWebAuthn", "password");
    // Configure import
    testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
    testingClient.testing().exportImport().runImport();
    // Ensure data are imported back
    Assert.assertNames(adminClient.realms().findAll(), "master", "test", "test-realm");
    assertAuthenticated("test", "test-user@localhost", "password");
    assertAuthenticated("test", "user1", "password");
    assertAuthenticated("test", "user2", "password");
    assertAuthenticated("test", "user3", "password");
    assertAuthenticated("test", "user-requiredOTP", "password");
    assertAuthenticated("test", "user-requiredWebAuthn", "password");
    RealmResource testRealmRealm = adminClient.realm("test");
    assertTrue(testRealmRealm.users().search("user-requiredOTP").get(0).getRequiredActions().get(0).equals(UserModel.RequiredAction.CONFIGURE_TOTP.name()));
    assertTrue(testRealmRealm.users().search("user-requiredWebAuthn").get(0).getRequiredActions().get(0).equals(WebAuthnRegisterFactory.PROVIDER_ID));
    // KEYCLOAK-6050 Check SMTP password is exported/imported
    assertEquals("secret", testingClient.server("test").fetch(RunHelpers.internalRealm()).getSmtpServer().get("password"));
    // KEYCLOAK-8176 Check required actions are exported/imported properly
    List<RequiredActionProviderRepresentation> requiredActionsAfterImport = adminClient.realm("master").flows().getRequiredActions();
    assertThat(requiredActionsAfterImport.size(), is(equalTo(requiredActionsBeforeImport.size())));
    requiredActionsAfterImport.stream().forEach((action) -> {
        RequiredActionProviderRepresentation beforeImportAction = requiredActionsBeforeImport.get(action.getAlias());
        assertThat(action.getName(), is(equalTo(beforeImportAction.getName())));
        assertThat(action.getProviderId(), is(equalTo(beforeImportAction.getProviderId())));
        assertThat(action.getPriority(), is(equalTo(beforeImportAction.getPriority())));
    });
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) HashMap(java.util.HashMap) RealmResource(org.keycloak.admin.client.resource.RealmResource)

Example 28 with RequiredActionProviderRepresentation

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

the class AppInitiatedActionWebAuthnTest method configureTestRealm.

@Override
public void configureTestRealm(RealmRepresentation testRealm) {
    RequiredActionProviderRepresentation action = new RequiredActionProviderRepresentation();
    action.setAlias(WEB_AUTHN_REGISTER_PROVIDER);
    action.setProviderId(WEB_AUTHN_REGISTER_PROVIDER);
    action.setEnabled(true);
    action.setDefaultAction(true);
    action.setPriority(10);
    List<RequiredActionProviderRepresentation> actions = new ArrayList<>();
    actions.add(action);
    testRealm.setRequiredActions(actions);
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) ArrayList(java.util.ArrayList)

Example 29 with RequiredActionProviderRepresentation

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

the class AccountRestServiceTest method setRequiredActionEnabledStatus.

private void setRequiredActionEnabledStatus(String requiredActionProviderId, boolean enabled) {
    RequiredActionProviderRepresentation requiredActionRep = testRealm().flows().getRequiredAction(requiredActionProviderId);
    requiredActionRep.setEnabled(enabled);
    testRealm().flows().updateRequiredAction(requiredActionProviderId, requiredActionRep);
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation)

Example 30 with RequiredActionProviderRepresentation

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

the class PermissionsTest method flows.

@Test
public void flows() throws Exception {
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getFormProviders();
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getAuthenticatorProviders();
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getClientAuthenticatorProviders();
        }
    }, Resource.REALM, false, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getFormActionProviders();
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getFlows();
        }
    }, Resource.REALM, false, true);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            response.set(realm.flows().createFlow(new AuthenticationFlowRepresentation()));
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getFlow("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().deleteFlow("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            response.set(realm.flows().copy("nosuch", Collections.<String, String>emptyMap()));
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().addExecutionFlow("nosuch", Collections.<String, String>emptyMap());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().addExecution("nosuch", Collections.<String, String>emptyMap());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getExecutions("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().updateExecutions("nosuch", new AuthenticationExecutionInfoRepresentation());
        }
    }, Resource.REALM, true);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            AuthenticationExecutionRepresentation rep = new AuthenticationExecutionRepresentation();
            rep.setAuthenticator("auth-cookie");
            rep.setRequirement("CONDITIONAL");
            response.set(realm.flows().addExecution(rep));
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().raisePriority("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().lowerPriority("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().removeExecution("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            response.set(realm.flows().newExecutionConfig("nosuch", new AuthenticatorConfigRepresentation()));
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getAuthenticatorConfig("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getUnregisteredRequiredActions();
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().registerRequiredAction(new RequiredActionProviderSimpleRepresentation());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getRequiredActions();
        }
    }, Resource.REALM, false, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getRequiredAction("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().removeRequiredAction("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().updateRequiredAction("nosuch", new RequiredActionProviderRepresentation());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getAuthenticatorConfigDescription("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getPerClientConfigDescription();
        }
    }, Resource.REALM, false, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getAuthenticatorConfig("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().removeAuthenticatorConfig("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().updateAuthenticatorConfig("nosuch", new AuthenticatorConfigRepresentation());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            clients.get(AdminRoles.VIEW_REALM).realm(REALM_NAME).flows().getPerClientConfigDescription();
            clients.get(AdminRoles.VIEW_REALM).realm(REALM_NAME).flows().getClientAuthenticatorProviders();
            clients.get(AdminRoles.VIEW_REALM).realm(REALM_NAME).flows().getRequiredActions();
        }
    }, adminClient, true);
    // Re-create realm
    adminClient.realm(REALM_NAME).remove();
    recreatePermissionRealm();
}
Also used : Response(javax.ws.rs.core.Response) RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) RequiredActionProviderSimpleRepresentation(org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation) AuthenticatorConfigRepresentation(org.keycloak.representations.idm.AuthenticatorConfigRepresentation) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) Test(org.junit.Test)

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