Search in sources :

Example 1 with AuthenticationManagementResource

use of org.keycloak.admin.client.resource.AuthenticationManagementResource in project keycloak by keycloak.

the class KcOidcFirstBrokerLoginDetectExistingUserTest method beforeBrokerTest.

@Override
@Before
public void beforeBrokerTest() {
    super.beforeBrokerTest();
    log.debug("creating detect existing user flow for realm " + bc.providerRealmName());
    final RealmResource consumerRealm = adminClient.realm(bc.consumerRealmName());
    AuthenticationManagementResource authMgmtResource = consumerRealm.flows();
    // Creates detectExistingUserFlow
    String detectExistingFlowAlias = "detectExistingUserFlow";
    final AuthenticationFlowRepresentation authenticationFlowRepresentation = newFlow(detectExistingFlowAlias, detectExistingFlowAlias, "basic-flow", true, false);
    authMgmtResource.createFlow(authenticationFlowRepresentation);
    AuthenticationFlowRepresentation authenticationFlowRepresentation1 = getFlow(authMgmtResource, detectExistingFlowAlias);
    assertNotNull("The authentication flow must exist", authenticationFlowRepresentation1);
    // retrieves the id of the newly created flow
    String flowId = authenticationFlowRepresentation1.getId();
    // Adds executions to the flow
    addExecution(authMgmtResource, flowId, IdpDetectExistingBrokerUserAuthenticatorFactory.PROVIDER_ID, 10);
    addExecution(authMgmtResource, flowId, IdpAutoLinkAuthenticatorFactory.PROVIDER_ID, 20);
    // Updates the FirstBrokerLoginFlowAlias for the identity provider
    IdentityProviderResource identityConsumerResource = consumerRealm.identityProviders().get(bc.getIDPAlias());
    IdentityProviderRepresentation identityProviderRepresentation = consumerRealm.identityProviders().findAll().get(0);
    identityProviderRepresentation.setFirstBrokerLoginFlowAlias(detectExistingFlowAlias);
    identityProviderRepresentation.getConfig().put(IdentityProviderModel.SYNC_MODE, IdentityProviderSyncMode.FORCE.toString());
    identityConsumerResource.update(identityProviderRepresentation);
    assertEquals("Two executions must have been created", 2, getFlow(authMgmtResource, detectExistingFlowAlias).getAuthenticationExecutions().size());
}
Also used : IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) AuthenticationManagementResource(org.keycloak.admin.client.resource.AuthenticationManagementResource) RealmResource(org.keycloak.admin.client.resource.RealmResource) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Before(org.junit.Before)

Example 2 with AuthenticationManagementResource

use of org.keycloak.admin.client.resource.AuthenticationManagementResource in project keycloak by keycloak.

the class Creator method create.

public static Creator.Flow create(RealmResource realmResource, AuthenticationFlowRepresentation rep) {
    final AuthenticationManagementResource authMgmgRes = realmResource.flows();
    try (Response response = authMgmgRes.createFlow(rep)) {
        String createdId = getCreatedId(response);
        LOG.debugf("Created flow ID %s", createdId);
        return new Flow(createdId, rep.getAlias(), authMgmgRes, () -> authMgmgRes.deleteFlow(createdId));
    }
}
Also used : Response(javax.ws.rs.core.Response) AuthenticationManagementResource(org.keycloak.admin.client.resource.AuthenticationManagementResource)

Example 3 with AuthenticationManagementResource

use of org.keycloak.admin.client.resource.AuthenticationManagementResource in project keycloak by keycloak.

the class CustomFlowTest method testRequiredAfterAlternative.

/**
 * KEYCLOAK-3506
 */
@Test
public void testRequiredAfterAlternative() {
    AuthenticationManagementResource authMgmtResource = testRealm().flows();
    Map<String, String> params = new HashMap();
    String flowAlias = "Browser Flow With Extra";
    params.put("newName", flowAlias);
    Response response = authMgmtResource.copy("browser", params);
    String flowId = null;
    try {
        Assert.assertThat("Copy flow", response, statusCodeIs(Response.Status.CREATED));
        AuthenticationFlowRepresentation newFlow = findFlowByAlias(flowAlias);
        flowId = newFlow.getId();
    } finally {
        response.close();
    }
    AuthenticationExecutionRepresentation execution = ExecutionBuilder.create().parentFlow(flowId).requirement(AuthenticationExecutionModel.Requirement.REQUIRED.toString()).authenticator(ClickThroughAuthenticator.PROVIDER_ID).priority(10).authenticatorFlow(false).build();
    RealmRepresentation rep = testRealm().toRepresentation();
    try (Response r = testRealm().flows().addExecution(execution)) {
        rep.setBrowserFlow(flowAlias);
        testRealm().update(rep);
        rep = testRealm().toRepresentation();
        Assert.assertEquals(flowAlias, rep.getBrowserFlow());
    }
    loginPage.open();
    /* In the new flows, any required execution will render any optional flows unused.
        // test to make sure we aren't skipping anything
        loginPage.login("test-user@localhost", "bad-password");
        Assert.assertTrue(loginPage.isCurrent());
        loginPage.login("test-user@localhost", "password");*/
    Assert.assertTrue(termsPage.isCurrent());
    // Revert dummy flow
    rep.setBrowserFlow("dummy");
    testRealm().update(rep);
}
Also used : Response(javax.ws.rs.core.Response) AuthenticationManagementResource(org.keycloak.admin.client.resource.AuthenticationManagementResource) HashMap(java.util.HashMap) AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) Test(org.junit.Test)

Example 4 with AuthenticationManagementResource

use of org.keycloak.admin.client.resource.AuthenticationManagementResource in project keycloak by keycloak.

the class CustomFlowTest method validateX509FlowUpdate.

@Test
public void validateX509FlowUpdate() throws Exception {
    String flowAlias = "Browser Flow With Extra 2";
    AuthenticationFlowRepresentation flow = new AuthenticationFlowRepresentation();
    flow.setAlias(flowAlias);
    flow.setDescription("");
    flow.setProviderId("basic-flow");
    flow.setTopLevel(true);
    flow.setBuiltIn(false);
    try (Creator.Flow amr = Creator.create(testRealm(), flow)) {
        AuthenticationManagementResource authMgmtResource = amr.resource();
        // add execution - X509 username
        final AuthenticationExecutionInfoRepresentation execution = amr.addExecution(ValidateX509CertificateUsernameFactory.PROVIDER_ID);
        String executionId = execution.getId();
        Map<String, String> config = new HashMap<>();
        config.put(AbstractX509ClientCertificateAuthenticator.ENABLE_CRL, Boolean.TRUE.toString());
        AuthenticatorConfigRepresentation authConfig = new AuthenticatorConfigRepresentation();
        authConfig.setAlias("Config alias");
        authConfig.setConfig(config);
        String acId;
        try (Response resp = authMgmtResource.newExecutionConfig(executionId, authConfig)) {
            assertThat(resp, statusCodeIs(Status.CREATED));
            acId = ApiUtil.getCreatedId(resp);
        }
        authConfig = authMgmtResource.getAuthenticatorConfig(acId);
        authConfig.getConfig().put(AbstractX509ClientCertificateAuthenticator.ENABLE_CRL, Boolean.FALSE.toString());
        authConfig.getConfig().put(AbstractX509ClientCertificateAuthenticator.CRL_RELATIVE_PATH, "");
        authMgmtResource.updateAuthenticatorConfig(acId, authConfig);
        // Saving the same options for the second time would fail for CRL_RELATIVE_PATH on Oracle due to "" == NULL weirdness
        authMgmtResource.updateAuthenticatorConfig(acId, authConfig);
    }
}
Also used : Response(javax.ws.rs.core.Response) AuthenticationManagementResource(org.keycloak.admin.client.resource.AuthenticationManagementResource) HashMap(java.util.HashMap) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) Creator(org.keycloak.testsuite.updaters.Creator) AuthenticatorConfigRepresentation(org.keycloak.representations.idm.AuthenticatorConfigRepresentation) Test(org.junit.Test)

Aggregations

AuthenticationManagementResource (org.keycloak.admin.client.resource.AuthenticationManagementResource)4 Response (javax.ws.rs.core.Response)3 AuthenticationFlowRepresentation (org.keycloak.representations.idm.AuthenticationFlowRepresentation)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Before (org.junit.Before)1 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)1 RealmResource (org.keycloak.admin.client.resource.RealmResource)1 AuthenticationExecutionInfoRepresentation (org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)1 AuthenticationExecutionRepresentation (org.keycloak.representations.idm.AuthenticationExecutionRepresentation)1 AuthenticatorConfigRepresentation (org.keycloak.representations.idm.AuthenticatorConfigRepresentation)1 IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 Creator (org.keycloak.testsuite.updaters.Creator)1