Search in sources :

Example 36 with AuthenticationFlowRepresentation

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

the class FlowTest method editFlowTest.

@Test
public // test editing of authentication flows
void editFlowTest() {
    List<AuthenticationFlowRepresentation> flows;
    // copy an existing one first
    HashMap<String, String> params = new HashMap<>();
    params.put("newName", "Copy of browser");
    Response response = authMgmtResource.copy("browser", params);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authCopyFlowPath("browser"), params, ResourceType.AUTH_FLOW);
    try {
        Assert.assertEquals("Copy flow", 201, response.getStatus());
    } finally {
        response.close();
    }
    // load the newly copied flow
    flows = authMgmtResource.getFlows();
    AuthenticationFlowRepresentation testFlow = findFlowByAlias("Copy of browser", flows);
    // Set a new unique name. Should succeed
    testFlow.setAlias("Copy of browser2");
    authMgmtResource.updateFlow(testFlow.getId(), testFlow);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authEditFlowPath(testFlow.getId()), ResourceType.AUTH_FLOW);
    flows = authMgmtResource.getFlows();
    Assert.assertEquals("Copy of browser2", findFlowByAlias("Copy of browser2", flows).getAlias());
    // Create new flow and edit the old one to have the new ones name
    AuthenticationFlowRepresentation newFlow = newFlow("New Flow", "Test description", "basic-flow", true, false);
    createFlow(newFlow);
    // check that new flow is returned in a children list
    flows = authMgmtResource.getFlows();
    AuthenticationFlowRepresentation found = findFlowByAlias("New Flow", flows);
    Assert.assertNotNull("created flow visible in parent", found);
    compareFlows(newFlow, found);
    // try to update old flow with alias that already exists
    testFlow.setAlias("New Flow");
    try {
        authMgmtResource.updateFlow(found.getId(), testFlow);
    } catch (ClientErrorException exception) {
    // expoected
    }
    flows = authMgmtResource.getFlows();
    // name should be the same for the old Flow
    Assert.assertEquals("Copy of browser2", findFlowByAlias("Copy of browser2", flows).getAlias());
    // Only update the description
    found.setDescription("New description");
    authMgmtResource.updateFlow(found.getId(), found);
    flows = authMgmtResource.getFlows();
    Assert.assertEquals("New description", findFlowByAlias("New Flow", flows).getDescription());
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authEditFlowPath(found.getId()), ResourceType.AUTH_FLOW);
    // Update name and description
    found.setAlias("New Flow2");
    found.setDescription("New description2");
    authMgmtResource.updateFlow(found.getId(), found);
    flows = authMgmtResource.getFlows();
    Assert.assertEquals("New Flow2", findFlowByAlias("New Flow2", flows).getAlias());
    Assert.assertEquals("New description2", findFlowByAlias("New Flow2", flows).getDescription());
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authEditFlowPath(found.getId()), ResourceType.AUTH_FLOW);
    Assert.assertNull(findFlowByAlias("New Flow", flows));
    authMgmtResource.deleteFlow(testFlow.getId());
    authMgmtResource.deleteFlow(found.getId());
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) ClientErrorException(javax.ws.rs.ClientErrorException) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 37 with AuthenticationFlowRepresentation

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

the class FlowTest method editExecutionFlowTest.

@Test
public void editExecutionFlowTest() {
    HashMap<String, String> params = new HashMap<>();
    List<AuthenticationExecutionInfoRepresentation> executionReps;
    // create new parent flow
    AuthenticationFlowRepresentation newFlow = newFlow("Parent-Flow", "This is a parent flow", "basic-flow", true, false);
    createFlow(newFlow);
    // create a child sub flow
    params.put("alias", "Child-Flow");
    params.put("description", "This is a child flow");
    params.put("provider", "registration-page-form");
    params.put("type", "basic-flow");
    authMgmtResource.addExecutionFlow("Parent-Flow", params);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authAddExecutionFlowPath("Parent-Flow"), params, ResourceType.AUTH_EXECUTION_FLOW);
    executionReps = authMgmtResource.getExecutions("Parent-Flow");
    // create another with the same name of the previous one. Should fail to create
    params = new HashMap<>();
    params.put("alias", "Child-Flow");
    params.put("description", "This is another child flow");
    params.put("provider", "registration-page-form");
    params.put("type", "basic-flow");
    try {
        authMgmtResource.addExecutionFlow("Parent-Flow", params);
        Assert.fail("addExecutionFlow the alias already exist");
    } catch (Exception expected) {
    // Expected
    }
    AuthenticationExecutionInfoRepresentation found = executionReps.get(0);
    found.setDisplayName("Parent-Flow");
    try {
        authMgmtResource.updateExecutions("Parent-Flow", found);
    } catch (ClientErrorException exception) {
    // expected
    }
    // edit both name and description
    found.setDisplayName("Child-Flow2");
    found.setDescription("This is another child flow2");
    authMgmtResource.updateExecutions("Parent-Flow", found);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authUpdateExecutionPath("Parent-Flow"), ResourceType.AUTH_EXECUTION);
    executionReps = authMgmtResource.getExecutions("Parent-Flow");
    Assert.assertEquals("Child-Flow2", executionReps.get(0).getDisplayName());
    Assert.assertEquals("This is another child flow2", executionReps.get(0).getDescription());
    // edit only description
    found.setDescription("This is another child flow3");
    authMgmtResource.updateExecutions("Parent-Flow", found);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authUpdateExecutionPath("Parent-Flow"), ResourceType.AUTH_EXECUTION);
    executionReps = authMgmtResource.getExecutions("Parent-Flow");
    Assert.assertEquals("Child-Flow2", executionReps.get(0).getDisplayName());
    Assert.assertEquals("This is another child flow3", executionReps.get(0).getDescription());
}
Also used : HashMap(java.util.HashMap) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) ClientErrorException(javax.ws.rs.ClientErrorException) Matchers.containsString(org.hamcrest.Matchers.containsString) ClientErrorException(javax.ws.rs.ClientErrorException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.Test)

Example 38 with AuthenticationFlowRepresentation

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

the class CustomRegistrationFlowTest method configureFlow.

@Before
public void configureFlow() {
    AuthenticationFlowRepresentation flow = FlowBuilder.create().alias("dummy registration").description("dummy pass through registration").providerId("basic-flow").topLevel(true).builtIn(false).build();
    testRealm().flows().createFlow(flow);
    setRegistrationFlow(flow);
    // refresh flow to find its id
    flow = findFlowByAlias(flow.getAlias());
    AuthenticationExecutionRepresentation execution = ExecutionBuilder.create().parentFlow(flow.getId()).requirement(AuthenticationExecutionModel.Requirement.REQUIRED.toString()).authenticator(PassThroughRegistration.PROVIDER_ID).priority(10).authenticatorFlow(false).build();
    testRealm().flows().addExecution(execution);
}
Also used : AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) Before(org.junit.Before)

Example 39 with AuthenticationFlowRepresentation

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

the class ScriptAuthenticatorTest method configureFlows.

@Before
public void configureFlows() throws Exception {
    if (testContext.isInitialized()) {
        return;
    }
    String scriptFlow = "scriptBrowser";
    AuthenticationFlowRepresentation scriptBrowserFlow = FlowBuilder.create().alias(scriptFlow).description("dummy pass through registration").providerId("basic-flow").topLevel(true).builtIn(false).build();
    Response createFlowResponse = testRealm().flows().createFlow(scriptBrowserFlow);
    Assert.assertEquals(201, createFlowResponse.getStatus());
    RealmRepresentation realm = testRealm().toRepresentation();
    realm.setBrowserFlow(scriptFlow);
    realm.setDirectGrantFlow(scriptFlow);
    testRealm().update(realm);
    this.flow = findFlowByAlias(scriptFlow);
    AuthenticationExecutionRepresentation usernamePasswordFormExecution = ExecutionBuilder.create().id("username password form").parentFlow(this.flow.getId()).requirement(AuthenticationExecutionModel.Requirement.REQUIRED.name()).authenticator(UsernamePasswordFormFactory.PROVIDER_ID).build();
    AuthenticationExecutionRepresentation authScriptExecution = ExecutionBuilder.create().id(EXECUTION_ID).parentFlow(this.flow.getId()).requirement(AuthenticationExecutionModel.Requirement.REQUIRED.name()).authenticator(ScriptBasedAuthenticatorFactory.PROVIDER_ID).build();
    Response addExecutionResponse = testRealm().flows().addExecution(usernamePasswordFormExecution);
    Assert.assertEquals(201, addExecutionResponse.getStatus());
    addExecutionResponse.close();
    addExecutionResponse = testRealm().flows().addExecution(authScriptExecution);
    Assert.assertEquals(201, addExecutionResponse.getStatus());
    addExecutionResponse.close();
    testContext.setInitialized(true);
}
Also used : Response(javax.ws.rs.core.Response) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) Before(org.junit.Before)

Example 40 with AuthenticationFlowRepresentation

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

the class ResetCredentialsAlternativeFlowsTest method revertFlows.

private void revertFlows() {
    List<AuthenticationFlowRepresentation> flows = testRealm().flows().getFlows();
    // Set default flows
    RealmRepresentation realm = testRealm().toRepresentation();
    realm.setBrowserFlow(DefaultAuthenticationFlows.BROWSER_FLOW);
    realm.setResetCredentialsFlow(DefaultAuthenticationFlows.RESET_CREDENTIALS_FLOW);
    testRealm().update(realm);
    // Delete flows previously created within various tests
    final List<String> aliasesOfExistingFlows = Arrays.asList("browser - alternative", "resetcred - alternative", "resetcred - KEYCLOAK-11753 - test");
    for (String existingFlowAlias : aliasesOfExistingFlows) {
        AuthenticationFlowRepresentation flowRepresentation = AbstractAuthenticationTest.findFlowByAlias(existingFlowAlias, flows);
        if (flowRepresentation != null) {
            testRealm().flows().deleteFlow(flowRepresentation.getId());
        }
    }
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation)

Aggregations

AuthenticationFlowRepresentation (org.keycloak.representations.idm.AuthenticationFlowRepresentation)42 Test (org.junit.Test)17 HashMap (java.util.HashMap)15 Response (javax.ws.rs.core.Response)14 AuthenticationExecutionInfoRepresentation (org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)10 AuthenticationExecutionRepresentation (org.keycloak.representations.idm.AuthenticationExecutionRepresentation)8 Before (org.junit.Before)7 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)7 BadRequestException (javax.ws.rs.BadRequestException)5 NotFoundException (javax.ws.rs.NotFoundException)5 RealmResource (org.keycloak.admin.client.resource.RealmResource)5 ClientErrorException (javax.ws.rs.ClientErrorException)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 AuthenticationExecutionExportRepresentation (org.keycloak.representations.idm.AuthenticationExecutionExportRepresentation)4 AuthenticatorConfigRepresentation (org.keycloak.representations.idm.AuthenticatorConfigRepresentation)4 IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)4 LinkedList (java.util.LinkedList)3 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)3 AuthenticationManagementResource (org.keycloak.admin.client.resource.AuthenticationManagementResource)3 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)2