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());
}
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());
}
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);
}
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);
}
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());
}
}
}
Aggregations