Java Code Examples for org.keycloak.representations.idm.RealmRepresentation#setDirectGrantFlow()

The following examples show how to use org.keycloak.representations.idm.RealmRepresentation#setDirectGrantFlow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void disableDirectGrantFlow(RealmRepresentation existingRealm) {
    String otherFlowAlias = searchTemporaryCreatedTopLevelFlowForReplacement();

    directGrantFlow = existingRealm.getDirectGrantFlow();

    existingRealm.setDirectGrantFlow(otherFlowAlias);
    realmRepository.update(existingRealm);
}
 
Example 2
Source File: UsedAuthenticationFlowWorkaroundFactory.java    From keycloak-config-cli with Apache License 2.0 5 votes vote down vote up
private void resetDirectGrantFlowIfNeeded(RealmRepresentation existingRealm) {
    if (Strings.isNotBlank(directGrantFlow)) {
        logger.debug("Reset direct-grant-flow in realm '{}' to '{}'", realmImport.getRealm(), directGrantFlow);

        existingRealm.setDirectGrantFlow(directGrantFlow);
    }
}
 
Example 3
Source File: DeployedScriptAuthenticatorTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public void configureFlows() {
    deployer.deploy(SCRIPT_DEPLOYMENT_NAME);

    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("script-authenticator-a.js")
            .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);
}
 
Example 4
Source File: AbstractX509AuthenticationTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
void setDirectGrantFlow(AuthenticationFlowRepresentation flow) {
    RealmRepresentation realm = testRealm().toRepresentation();
    realm.setDirectGrantFlow(flow.getAlias());
    testRealm().update(realm);
}
 
Example 5
Source File: ScriptAuthenticatorTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example 6
Source File: CustomFlowTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@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);
}