Search in sources :

Example 11 with AuthenticationExecutionInfoRepresentation

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

the class LDAPSamlIdPInitiatedVaryingLetterCaseTest method setupIdentityProvider.

@Before
public void setupIdentityProvider() {
    // Configure autolink flow
    AuthenticationFlowRepresentation newFlow = new AuthenticationFlowRepresentation();
    newFlow.setAlias(FLOW_AUTO_LINK);
    newFlow.setDescription("Auto-link flow");
    newFlow.setProviderId("basic-flow");
    newFlow.setBuiltIn(false);
    newFlow.setTopLevel(true);
    Creator.Flow amr = Creator.create(testRealm(), newFlow);
    AuthenticationExecutionInfoRepresentation exCreateUser = amr.addExecution(IdpCreateUserIfUniqueAuthenticatorFactory.PROVIDER_ID);
    exCreateUser.setRequirement(Requirement.ALTERNATIVE.name());
    testRealm().flows().updateExecutions(FLOW_AUTO_LINK, exCreateUser);
    AuthenticationExecutionInfoRepresentation exAutoLink = amr.addExecution(IdpAutoLinkAuthenticatorFactory.PROVIDER_ID);
    exAutoLink.setRequirement(Requirement.ALTERNATIVE.name());
    testRealm().flows().updateExecutions(FLOW_AUTO_LINK, exAutoLink);
    getCleanup().addCleanup(amr);
    // Configure identity provider
    IdentityProviderRepresentation idp = KcSamlBrokerConfiguration.INSTANCE.setUpIdentityProvider();
    idp.getConfig().put(SAMLIdentityProviderConfig.NAME_ID_POLICY_FORMAT, JBossSAMLURIConstants.NAMEID_FORMAT_UNSPECIFIED.get());
    idp.setFirstBrokerLoginFlowAlias(FLOW_AUTO_LINK);
    final Creator<IdentityProviderResource> idpCreator = Creator.create(testRealm(), idp);
    IdentityProviderMapperRepresentation samlNameIdMapper = new IdentityProviderMapperRepresentation();
    samlNameIdMapper.setName("username-nameid-mapper");
    idpAlias = idp.getAlias();
    samlNameIdMapper.setIdentityProviderAlias(idpAlias);
    samlNameIdMapper.setIdentityProviderMapper(UsernameTemplateMapper.PROVIDER_ID);
    samlNameIdMapper.setConfig(ImmutableMap.<String, String>builder().put(IdentityProviderMapperModel.SYNC_MODE, "IMPORT").put(UsernameTemplateMapper.TEMPLATE, "${NAMEID | lowercase}").put(UsernameTemplateMapper.TARGET, Target.BROKER_ID.name()).build());
    idpCreator.resource().addMapper(samlNameIdMapper);
    getCleanup().addCleanup(idpCreator);
}
Also used : IdentityProviderMapperRepresentation(org.keycloak.representations.idm.IdentityProviderMapperRepresentation) IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Creator(org.keycloak.testsuite.updaters.Creator) Before(org.junit.Before)

Example 12 with AuthenticationExecutionInfoRepresentation

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

the class AccountRestServiceTest method setExecutionRequirement.

// Sets new requirement and returns current requirement
private AuthenticationExecutionModel.Requirement setExecutionRequirement(String flowAlias, String executionDisplayName, AuthenticationExecutionModel.Requirement newRequirement) {
    List<AuthenticationExecutionInfoRepresentation> executionInfos = testRealm().flows().getExecutions(flowAlias);
    for (AuthenticationExecutionInfoRepresentation exInfo : executionInfos) {
        if (executionDisplayName.equals(exInfo.getDisplayName())) {
            AuthenticationExecutionModel.Requirement currentRequirement = AuthenticationExecutionModel.Requirement.valueOf(exInfo.getRequirement());
            exInfo.setRequirement(newRequirement.toString());
            testRealm().flows().updateExecutions(flowAlias, exInfo);
            return currentRequirement;
        }
    }
    throw new IllegalStateException("Not found execution '" + executionDisplayName + "' in flow '" + flowAlias + "'.");
}
Also used : AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)

Example 13 with AuthenticationExecutionInfoRepresentation

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

the class OpenShiftTokenReviewEndpointTest method enablePassthroughAuthenticator.

@Before
public void enablePassthroughAuthenticator() {
    if (!flowConfigured) {
        HashMap<String, String> data = new HashMap<>();
        data.put("newName", "testsuite-client-dummy");
        Response response = testRealm().flows().copy("clients", data);
        assertEquals(201, response.getStatus());
        response.close();
        data = new HashMap<>();
        data.put("provider", "testsuite-client-dummy");
        data.put("requirement", "ALTERNATIVE");
        testRealm().flows().addExecution("testsuite-client-dummy", data);
        RealmRepresentation realmRep = testRealm().toRepresentation();
        realmRep.setClientAuthenticationFlow("testsuite-client-dummy");
        testRealm().update(realmRep);
        List<AuthenticationExecutionInfoRepresentation> executions = testRealm().flows().getExecutions("testsuite-client-dummy");
        for (AuthenticationExecutionInfoRepresentation e : executions) {
            if (e.getProviderId().equals("testsuite-client-dummy")) {
                e.setRequirement("ALTERNATIVE");
                testRealm().flows().updateExecutions("testsuite-client-dummy", e);
            }
        }
        flowConfigured = true;
    }
}
Also used : Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HashMap(java.util.HashMap) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) Before(org.junit.Before)

Example 14 with AuthenticationExecutionInfoRepresentation

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

the class AbstractMigrationTest method testOTPExecutionMigratedToConditionalFlow.

private void testOTPExecutionMigratedToConditionalFlow(String topFlowAlias, String expectedOTPSubflowAlias, String expectedOTPExecutionDisplayName) {
    List<AuthenticationExecutionInfoRepresentation> authExecutions = migrationRealm.flows().getExecutions(topFlowAlias);
    int counter = -1;
    AuthenticationExecutionInfoRepresentation subflowExecution = null;
    for (AuthenticationExecutionInfoRepresentation ex : authExecutions) {
        counter++;
        if (expectedOTPSubflowAlias.equals(ex.getDisplayName())) {
            subflowExecution = ex;
            break;
        }
    }
    if (subflowExecution == null) {
        throw new AssertionError("Not found subflow with displayName '" + expectedOTPSubflowAlias + "' in the flow " + topFlowAlias);
    }
    Assert.assertEquals(AuthenticationExecutionModel.Requirement.CONDITIONAL.toString(), subflowExecution.getRequirement());
    AuthenticationExecutionInfoRepresentation childEx1 = authExecutions.get(counter + 1);
    Assert.assertEquals("Condition - user configured", childEx1.getDisplayName());
    Assert.assertEquals(AuthenticationExecutionModel.Requirement.REQUIRED.toString(), childEx1.getRequirement());
    Assert.assertEquals(0, childEx1.getIndex());
    Assert.assertEquals(subflowExecution.getLevel() + 1, childEx1.getLevel());
    AuthenticationExecutionInfoRepresentation childEx2 = authExecutions.get(counter + 2);
    Assert.assertEquals(expectedOTPExecutionDisplayName, childEx2.getDisplayName());
    Assert.assertEquals(AuthenticationExecutionModel.Requirement.REQUIRED.toString(), childEx2.getRequirement());
    Assert.assertEquals(1, childEx2.getIndex());
    Assert.assertEquals(subflowExecution.getLevel() + 1, childEx2.getLevel());
}
Also used : AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)

Example 15 with AuthenticationExecutionInfoRepresentation

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

the class AbstractX509AuthenticationTest method addAssertExecution.

private AuthenticationExecutionInfoRepresentation addAssertExecution(AuthenticationFlowRepresentation flow, String providerId, String requirement) {
    AuthenticationExecutionRepresentation rep = new AuthenticationExecutionRepresentation();
    rep.setPriority(10);
    rep.setAuthenticator(providerId);
    rep.setRequirement(requirement);
    rep.setParentFlow(flow.getId());
    Response response = authMgmtResource.addExecution(rep);
    // assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AssertAdminEvents.isExpectedPrefixFollowedByUuid(AdminEventPaths.authMgmtBasePath() + "/executions"), rep);
    try {
        Assert.assertEquals("added execution", 201, response.getStatus());
    } finally {
        response.close();
    }
    List<AuthenticationExecutionInfoRepresentation> executionReps = authMgmtResource.getExecutions(flow.getAlias());
    return findExecution(providerId, executionReps);
}
Also used : Response(javax.ws.rs.core.Response) AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)

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