Search in sources :

Example 6 with AuthenticationExecutionInfoRepresentation

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

the class AbstractAuthenticationTest method newExecInfo.

AuthenticationExecutionInfoRepresentation newExecInfo(String displayName, String providerId, Boolean configurable, int level, int index, String requirement, Boolean authFlow, String[] choices) {
    AuthenticationExecutionInfoRepresentation execution = new AuthenticationExecutionInfoRepresentation();
    execution.setRequirement(requirement);
    execution.setDisplayName(displayName);
    execution.setConfigurable(configurable);
    execution.setProviderId(providerId);
    execution.setLevel(level);
    execution.setIndex(index);
    execution.setAuthenticationFlow(authFlow);
    if (choices != null) {
        execution.setRequirementChoices(Arrays.asList(choices));
    }
    return execution;
}
Also used : AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)

Example 7 with AuthenticationExecutionInfoRepresentation

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

the class ExecutionTest method testUpdateAuthenticatorConfig.

// KEYCLOAK-7975
@Test
public void testUpdateAuthenticatorConfig() {
    // copy built-in flow so we get a new editable flow
    HashMap<String, String> params = new HashMap<>();
    params.put("newName", "new-browser-flow");
    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();
    }
    // create Conditional OTP Form execution
    params.put("provider", "auth-conditional-otp-form");
    authMgmtResource.addExecution("new-browser-flow", params);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authAddExecutionPath("new-browser-flow"), params, ResourceType.AUTH_EXECUTION);
    List<AuthenticationExecutionInfoRepresentation> executionReps = authMgmtResource.getExecutions("new-browser-flow");
    AuthenticationExecutionInfoRepresentation exec = findExecutionByProvider("auth-conditional-otp-form", executionReps);
    // create authenticator config for the execution
    Map<String, String> config = new HashMap<>();
    config.put("defaultOtpOutcome", "skip");
    config.put("otpControlAttribute", "test");
    config.put("forceOtpForHeaderPattern", "");
    config.put("forceOtpRole", "");
    config.put("noOtpRequiredForHeaderPattern", "");
    config.put("skipOtpRole", "");
    AuthenticatorConfigRepresentation authConfigRep = new AuthenticatorConfigRepresentation();
    authConfigRep.setAlias("conditional-otp-form-config-alias");
    authConfigRep.setConfig(config);
    response = authMgmtResource.newExecutionConfig(exec.getId(), authConfigRep);
    try {
        authConfigRep.setId(ApiUtil.getCreatedId(response));
    } finally {
        response.close();
    }
    // try to update the config adn check
    config.put("otpControlAttribute", "test-updated");
    authConfigRep.setConfig(config);
    authMgmtResource.updateAuthenticatorConfig(authConfigRep.getId(), authConfigRep);
    AuthenticatorConfigRepresentation updated = authMgmtResource.getAuthenticatorConfig(authConfigRep.getId());
    Assert.assertThat(updated.getConfig().values(), hasItems("test-updated", "skip"));
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) AuthenticatorConfigRepresentation(org.keycloak.representations.idm.AuthenticatorConfigRepresentation) Test(org.junit.Test)

Example 8 with AuthenticationExecutionInfoRepresentation

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

the class InitialFlowsTest method compareExecutionsInfo.

private void compareExecutionsInfo(List<AuthenticationExecutionInfoRepresentation> expected, List<AuthenticationExecutionInfoRepresentation> actual) {
    Assert.assertEquals("Executions count", expected.size(), actual.size());
    Iterator<AuthenticationExecutionInfoRepresentation> it1 = expected.iterator();
    Iterator<AuthenticationExecutionInfoRepresentation> it2 = actual.iterator();
    while (it1.hasNext()) {
        AuthenticationExecutionInfoRepresentation exe1 = it1.next();
        AuthenticationExecutionInfoRepresentation exe2 = it2.next();
        compareExecutionWithConfig(exe1, exe2);
    }
}
Also used : AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)

Example 9 with AuthenticationExecutionInfoRepresentation

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

the class AuthenticatorConfigTest method testRemoveConfig.

@Test
public void testRemoveConfig() {
    AuthenticatorConfigRepresentation cfg = newConfig("foo", IdpCreateUserIfUniqueAuthenticatorFactory.REQUIRE_PASSWORD_UPDATE_AFTER_REGISTRATION, "true");
    String cfgId = createConfig(executionId, cfg);
    AuthenticatorConfigRepresentation cfgRep = authMgmtResource.getAuthenticatorConfig(cfgId);
    // Assert execution has our config
    AuthenticationExecutionInfoRepresentation execution = findExecutionByProvider(IdpCreateUserIfUniqueAuthenticatorFactory.PROVIDER_ID, authMgmtResource.getExecutions("firstBrokerLogin2"));
    Assert.assertEquals(cfgRep.getId(), execution.getAuthenticationConfig());
    // Test remove not-existent
    try {
        authMgmtResource.removeAuthenticatorConfig("not-existent");
        Assert.fail("Config didn't found");
    } catch (NotFoundException nfe) {
    // Expected
    }
    // Test remove our config
    authMgmtResource.removeAuthenticatorConfig(cfgId);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.DELETE, AdminEventPaths.authExecutionConfigPath(cfgId), ResourceType.AUTHENTICATOR_CONFIG);
    // Assert config not found
    try {
        authMgmtResource.getAuthenticatorConfig(cfgRep.getId());
        Assert.fail("Not expected to find config");
    } catch (NotFoundException nfe) {
    // Expected
    }
    // Assert execution doesn't have our config
    execution = findExecutionByProvider(IdpCreateUserIfUniqueAuthenticatorFactory.PROVIDER_ID, authMgmtResource.getExecutions("firstBrokerLogin2"));
    Assert.assertNull(execution.getAuthenticationConfig());
}
Also used : AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) NotFoundException(javax.ws.rs.NotFoundException) AuthenticatorConfigRepresentation(org.keycloak.representations.idm.AuthenticatorConfigRepresentation) Test(org.junit.Test)

Example 10 with AuthenticationExecutionInfoRepresentation

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

the class AuthenticatorConfigTest method beforeConfigTest.

@Before
public void beforeConfigTest() {
    AuthenticationFlowRepresentation flowRep = newFlow("firstBrokerLogin2", "firstBrokerLogin2", "basic-flow", true, false);
    createFlow(flowRep);
    HashMap<String, String> params = new HashMap<>();
    params.put("provider", IdpCreateUserIfUniqueAuthenticatorFactory.PROVIDER_ID);
    authMgmtResource.addExecution("firstBrokerLogin2", params);
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authAddExecutionPath("firstBrokerLogin2"), params, ResourceType.AUTH_EXECUTION);
    List<AuthenticationExecutionInfoRepresentation> executionReps = authMgmtResource.getExecutions("firstBrokerLogin2");
    AuthenticationExecutionInfoRepresentation exec = findExecutionByProvider(IdpCreateUserIfUniqueAuthenticatorFactory.PROVIDER_ID, executionReps);
    Assert.assertNotNull(exec);
    executionId = exec.getId();
}
Also used : HashMap(java.util.HashMap) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) Before(org.junit.Before)

Aggregations

AuthenticationExecutionInfoRepresentation (org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)33 Test (org.junit.Test)16 AuthenticationFlowRepresentation (org.keycloak.representations.idm.AuthenticationFlowRepresentation)10 HashMap (java.util.HashMap)9 Response (javax.ws.rs.core.Response)8 NotFoundException (javax.ws.rs.NotFoundException)5 Before (org.junit.Before)4 AuthenticatorConfigRepresentation (org.keycloak.representations.idm.AuthenticatorConfigRepresentation)4 LinkedList (java.util.LinkedList)3 BadRequestException (javax.ws.rs.BadRequestException)3 ComponentRepresentation (org.keycloak.representations.idm.ComponentRepresentation)3 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)3 URI (java.net.URI)2 List (java.util.List)2 RealmResource (org.keycloak.admin.client.resource.RealmResource)2 AuthenticationExecutionModel (org.keycloak.models.AuthenticationExecutionModel)2 AuthenticationFlowModel (org.keycloak.models.AuthenticationFlowModel)2 AuthenticationExecutionRepresentation (org.keycloak.representations.idm.AuthenticationExecutionRepresentation)2 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)2 IOException (java.io.IOException)1