Search in sources :

Example 6 with RequiredActionProviderSimpleRepresentation

use of org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation 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)

Example 7 with RequiredActionProviderSimpleRepresentation

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

the class BrowserFlowTest method testLoginWithWithNoWebAuthnCredential.

/**
 * This test checks that if a REQUIRED authentication execution which has isUserSetupAllowed -> true
 * has its requiredActionProvider enabled, than it will login and show the otpSetup page.
 * NOTE: webauthn currently isn't configured by default in the realm. When this changes, this test will need to be adapted
 */
@Test
@AuthServerContainerExclude(REMOTE)
public void testLoginWithWithNoWebAuthnCredential() {
    String newFlowAlias = "browser - copy 1";
    configureBrowserFlowWithRequiredWebAuthn(newFlowAlias);
    RequiredActionProviderSimpleRepresentation requiredActionRepresentation = new RequiredActionProviderSimpleRepresentation();
    requiredActionRepresentation.setName("WebAuthn Required Action");
    requiredActionRepresentation.setProviderId(WebAuthnRegisterFactory.PROVIDER_ID);
    testRealm().flows().registerRequiredAction(requiredActionRepresentation);
    try {
        provideUsernamePassword("test-user@localhost");
        // Assert that in this case you arrive to an webauthn setup
        Assert.assertTrue(driver.getCurrentUrl().contains("required-action?execution=" + WebAuthnRegisterFactory.PROVIDER_ID));
    } finally {
        revertFlows("browser - copy 1");
        testRealm().flows().removeRequiredAction(WebAuthnRegisterFactory.PROVIDER_ID);
        UserRepresentation user = testRealm().users().search("test-user@localhost").get(0);
        user.setRequiredActions(Collections.emptyList());
        testRealm().users().get(user.getId()).update(user);
    }
}
Also used : RequiredActionProviderSimpleRepresentation(org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation) Matchers.containsString(org.hamcrest.Matchers.containsString) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) 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

RequiredActionProviderSimpleRepresentation (org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation)7 Test (org.junit.Test)6 RequiredActionProviderRepresentation (org.keycloak.representations.idm.RequiredActionProviderRepresentation)4 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)3 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)3 SocialLoginTest (org.keycloak.testsuite.broker.SocialLoginTest)3 AuthenticationExecutionRepresentation (org.keycloak.representations.idm.AuthenticationExecutionRepresentation)2 AuthenticationFlowRepresentation (org.keycloak.representations.idm.AuthenticationFlowRepresentation)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 NotFoundException (javax.ws.rs.NotFoundException)1 Response (javax.ws.rs.core.Response)1 RealmResource (org.keycloak.admin.client.resource.RealmResource)1 AuthenticationExecutionInfoRepresentation (org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)1 AuthenticatorConfigRepresentation (org.keycloak.representations.idm.AuthenticatorConfigRepresentation)1 CredentialRepresentation (org.keycloak.representations.idm.CredentialRepresentation)1 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)1 AccountCredentialResource (org.keycloak.services.resources.account.AccountCredentialResource)1 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)1