Search in sources :

Example 6 with AuthenticationExecutionRepresentation

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

the class CustomFlowTest method configureFlows.

@Before
public void configureFlows() {
    userId = findUser("login-test").getId();
    // Do this just once per class
    if (testContext.isInitialized()) {
        return;
    }
    AuthenticationFlowRepresentation flow = FlowBuilder.create().alias("dummy").description("dummy pass through flow").providerId("basic-flow").topLevel(true).builtIn(false).build();
    testRealm().flows().createFlow(flow);
    RealmRepresentation realm = testRealm().toRepresentation();
    realm.setBrowserFlow(flow.getAlias());
    realm.setDirectGrantFlow(flow.getAlias());
    testRealm().update(realm);
    // refresh flow to find its id
    flow = findFlowByAlias(flow.getAlias());
    AuthenticationExecutionRepresentation execution = ExecutionBuilder.create().parentFlow(flow.getId()).requirement(AuthenticationExecutionModel.Requirement.REQUIRED.toString()).authenticator(PassThroughAuthenticator.PROVIDER_ID).priority(10).authenticatorFlow(false).build();
    testRealm().flows().addExecution(execution);
    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());
    execution = ExecutionBuilder.create().parentFlow(flow.getId()).requirement(AuthenticationExecutionModel.Requirement.REQUIRED.toString()).authenticator(PassThroughRegistration.PROVIDER_ID).priority(10).authenticatorFlow(false).build();
    testRealm().flows().addExecution(execution);
    AuthenticationFlowRepresentation clientFlow = FlowBuilder.create().alias("client-dummy").description("dummy pass through flow").providerId(AuthenticationFlow.CLIENT_FLOW).topLevel(true).builtIn(false).build();
    testRealm().flows().createFlow(clientFlow);
    realm = testRealm().toRepresentation();
    realm.setClientAuthenticationFlow(clientFlow.getAlias());
    testRealm().update(realm);
    // refresh flow to find its id
    clientFlow = findFlowByAlias(clientFlow.getAlias());
    execution = ExecutionBuilder.create().parentFlow(clientFlow.getId()).requirement(AuthenticationExecutionModel.Requirement.REQUIRED.toString()).authenticator(PassThroughClientAuthenticator.PROVIDER_ID).priority(10).authenticatorFlow(false).build();
    testRealm().flows().addExecution(execution);
    testContext.setInitialized(true);
}
Also used : RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) Before(org.junit.Before)

Example 7 with AuthenticationExecutionRepresentation

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

the class AbstractWebAuthnAccountTest method afterAbstractKeycloakTestRealmImport.

@Override
protected void afterAbstractKeycloakTestRealmImport() {
    super.afterAbstractKeycloakTestRealmImport();
    // configure WebAuthn
    // we can't do this during the realm import because we'd need to specify all built-in flows as well
    AuthenticationFlowRepresentation flow = new AuthenticationFlowRepresentation();
    flow.setId(WEBAUTHN_FLOW_ID);
    flow.setAlias("webauthn flow");
    flow.setProviderId("basic-flow");
    flow.setBuiltIn(false);
    flow.setTopLevel(true);
    testRealmResource().flows().createFlow(flow);
    AuthenticationExecutionRepresentation execution = new AuthenticationExecutionRepresentation();
    execution.setAuthenticator(WebAuthnAuthenticatorFactory.PROVIDER_ID);
    execution.setPriority(10);
    execution.setRequirement(REQUIRED.toString());
    execution.setParentFlow(WEBAUTHN_FLOW_ID);
    testRealmResource().flows().addExecution(execution);
    execution.setAuthenticator(WebAuthnPasswordlessAuthenticatorFactory.PROVIDER_ID);
    testRealmResource().flows().addExecution(execution);
    RequiredActionProviderSimpleRepresentation requiredAction = new RequiredActionProviderSimpleRepresentation();
    requiredAction.setProviderId(WebAuthnRegisterFactory.PROVIDER_ID);
    requiredAction.setName("blahblah");
    testRealmResource().flows().registerRequiredAction(requiredAction);
    requiredAction.setProviderId(WebAuthnPasswordlessRegisterFactory.PROVIDER_ID);
    testRealmResource().flows().registerRequiredAction(requiredAction);
}
Also used : AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) RequiredActionProviderSimpleRepresentation(org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation)

Example 8 with AuthenticationExecutionRepresentation

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

the class AccountRestServiceTest method configureBrowserFlowWithWebAuthnAuthenticator.

private void configureBrowserFlowWithWebAuthnAuthenticator(String newFlowAlias) {
    HashMap<String, String> params = new HashMap<>();
    params.put("newName", newFlowAlias);
    Response response = testRealm().flows().copy("browser", params);
    response.close();
    String flowId = AbstractAuthenticationTest.findFlowByAlias(newFlowAlias, testRealm().flows().getFlows()).getId();
    AuthenticationExecutionRepresentation execution = new AuthenticationExecutionRepresentation();
    execution.setParentFlow(flowId);
    execution.setAuthenticator(WebAuthnAuthenticatorFactory.PROVIDER_ID);
    execution.setRequirement(AuthenticationExecutionModel.Requirement.REQUIRED.toString());
    response = testRealm().flows().addExecution(execution);
    response.close();
    execution = new AuthenticationExecutionRepresentation();
    execution.setParentFlow(flowId);
    execution.setAuthenticator(WebAuthnPasswordlessAuthenticatorFactory.PROVIDER_ID);
    execution.setRequirement(AuthenticationExecutionModel.Requirement.ALTERNATIVE.toString());
    response = testRealm().flows().addExecution(execution);
    response.close();
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation)

Example 9 with AuthenticationExecutionRepresentation

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

the class PermissionsTest method flows.

@Test
public void flows() throws Exception {
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getFormProviders();
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getAuthenticatorProviders();
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getClientAuthenticatorProviders();
        }
    }, Resource.REALM, false, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getFormActionProviders();
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getFlows();
        }
    }, Resource.REALM, false, true);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            response.set(realm.flows().createFlow(new AuthenticationFlowRepresentation()));
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getFlow("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().deleteFlow("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            response.set(realm.flows().copy("nosuch", Collections.<String, String>emptyMap()));
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().addExecutionFlow("nosuch", Collections.<String, String>emptyMap());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().addExecution("nosuch", Collections.<String, String>emptyMap());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getExecutions("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().updateExecutions("nosuch", new AuthenticationExecutionInfoRepresentation());
        }
    }, Resource.REALM, true);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            AuthenticationExecutionRepresentation rep = new AuthenticationExecutionRepresentation();
            rep.setAuthenticator("auth-cookie");
            rep.setRequirement("CONDITIONAL");
            response.set(realm.flows().addExecution(rep));
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().raisePriority("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().lowerPriority("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().removeExecution("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new InvocationWithResponse() {

        public void invoke(RealmResource realm, AtomicReference<Response> response) {
            response.set(realm.flows().newExecutionConfig("nosuch", new AuthenticatorConfigRepresentation()));
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getAuthenticatorConfig("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getUnregisteredRequiredActions();
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().registerRequiredAction(new RequiredActionProviderSimpleRepresentation());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getRequiredActions();
        }
    }, Resource.REALM, false, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getRequiredAction("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().removeRequiredAction("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().updateRequiredAction("nosuch", new RequiredActionProviderRepresentation());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getAuthenticatorConfigDescription("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getPerClientConfigDescription();
        }
    }, Resource.REALM, false, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().getAuthenticatorConfig("nosuch");
        }
    }, Resource.REALM, false);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().removeAuthenticatorConfig("nosuch");
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            realm.flows().updateAuthenticatorConfig("nosuch", new AuthenticatorConfigRepresentation());
        }
    }, Resource.REALM, true);
    invoke(new Invocation() {

        public void invoke(RealmResource realm) {
            clients.get(AdminRoles.VIEW_REALM).realm(REALM_NAME).flows().getPerClientConfigDescription();
            clients.get(AdminRoles.VIEW_REALM).realm(REALM_NAME).flows().getClientAuthenticatorProviders();
            clients.get(AdminRoles.VIEW_REALM).realm(REALM_NAME).flows().getRequiredActions();
        }
    }, adminClient, true);
    // Re-create realm
    adminClient.realm(REALM_NAME).remove();
    recreatePermissionRealm();
}
Also used : Response(javax.ws.rs.core.Response) RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) AuthenticationExecutionRepresentation(org.keycloak.representations.idm.AuthenticationExecutionRepresentation) AuthenticationFlowRepresentation(org.keycloak.representations.idm.AuthenticationFlowRepresentation) AuthenticationExecutionInfoRepresentation(org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation) RequiredActionProviderSimpleRepresentation(org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation) AuthenticatorConfigRepresentation(org.keycloak.representations.idm.AuthenticatorConfigRepresentation) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest) Test(org.junit.Test)

Example 10 with AuthenticationExecutionRepresentation

use of org.keycloak.representations.idm.AuthenticationExecutionRepresentation 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)

Aggregations

AuthenticationExecutionRepresentation (org.keycloak.representations.idm.AuthenticationExecutionRepresentation)11 AuthenticationFlowRepresentation (org.keycloak.representations.idm.AuthenticationFlowRepresentation)8 Response (javax.ws.rs.core.Response)7 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 Test (org.junit.Test)3 AuthenticationExecutionInfoRepresentation (org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation)3 RequiredActionProviderSimpleRepresentation (org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation)2 BadRequestException (javax.ws.rs.BadRequestException)1 AuthenticationManagementResource (org.keycloak.admin.client.resource.AuthenticationManagementResource)1 RealmResource (org.keycloak.admin.client.resource.RealmResource)1 AuthenticatorConfigRepresentation (org.keycloak.representations.idm.AuthenticatorConfigRepresentation)1 RequiredActionProviderRepresentation (org.keycloak.representations.idm.RequiredActionProviderRepresentation)1 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)1