Search in sources :

Example 1 with RequiredActionProviderRepresentation

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

the class ShiftRequiredActionTest method testShiftRequiredAction.

@Test
public void testShiftRequiredAction() {
    // get action
    List<RequiredActionProviderRepresentation> actions = authMgmtResource.getRequiredActions();
    RequiredActionProviderRepresentation last = actions.get(actions.size() - 1);
    RequiredActionProviderRepresentation oneButLast = actions.get(actions.size() - 2);
    // Not possible to raisePriority of not-existent required action
    try {
        authMgmtResource.raisePriority("not-existent");
        Assert.fail("Not expected to raise priority of not existent required action");
    } catch (NotFoundException nfe) {
    // Expected
    }
    // shift last required action up
    authMgmtResource.raiseRequiredActionPriority(last.getAlias());
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authRaiseRequiredActionPath(last.getAlias()), ResourceType.REQUIRED_ACTION);
    List<RequiredActionProviderRepresentation> actions2 = authMgmtResource.getRequiredActions();
    RequiredActionProviderRepresentation last2 = actions2.get(actions.size() - 1);
    RequiredActionProviderRepresentation oneButLast2 = actions2.get(actions.size() - 2);
    Assert.assertEquals("Required action shifted up - N", last.getAlias(), oneButLast2.getAlias());
    Assert.assertEquals("Required action up - N-1", oneButLast.getAlias(), last2.getAlias());
    // Not possible to lowerPriority of not-existent required action
    try {
        authMgmtResource.lowerRequiredActionPriority("not-existent");
        Assert.fail("Not expected to raise priority of not existent required action");
    } catch (NotFoundException nfe) {
    // Expected
    }
    // shift one before last down
    authMgmtResource.lowerRequiredActionPriority(oneButLast2.getAlias());
    assertAdminEvents.assertEvent(REALM_NAME, OperationType.UPDATE, AdminEventPaths.authLowerRequiredActionPath(oneButLast2.getAlias()), ResourceType.REQUIRED_ACTION);
    actions2 = authMgmtResource.getRequiredActions();
    last2 = actions2.get(actions.size() - 1);
    oneButLast2 = actions2.get(actions.size() - 2);
    Assert.assertEquals("Required action shifted down - N", last.getAlias(), last2.getAlias());
    Assert.assertEquals("Required action shifted down - N-1", oneButLast.getAlias(), oneButLast2.getAlias());
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.Test)

Example 2 with RequiredActionProviderRepresentation

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

the class AbstractMigrationTest method testRequiredActionsPriority.

private void testRequiredActionsPriority(RealmResource... realms) {
    log.info("testing required action's priority");
    for (RealmResource realm : realms) {
        log.info("Taking required actions from realm: " + realm.toRepresentation().getRealm());
        List<RequiredActionProviderRepresentation> actions = realm.flows().getRequiredActions();
        // Checking the priority
        int priority = 10;
        for (RequiredActionProviderRepresentation action : actions) {
            if (action.getAlias().equals("update_user_locale")) {
                assertEquals(1000, action.getPriority());
            } else {
                assertEquals(priority, action.getPriority());
            }
            priority += 10;
        }
    }
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource)

Example 3 with RequiredActionProviderRepresentation

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

the class AbstractMigrationTest method testUserLocaleActionAdded.

protected void testUserLocaleActionAdded(RealmResource realm) {
    RequiredActionProviderRepresentation rep = realm.flows().getRequiredAction("update_user_locale");
    assertNotNull(rep);
    assertEquals("update_user_locale", rep.getAlias());
    assertEquals("update_user_locale", rep.getProviderId());
    assertEquals("Update User Locale", rep.getName());
    assertEquals(1000, rep.getPriority());
    assertTrue(rep.isEnabled());
    assertFalse(rep.isDefaultAction());
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation)

Example 4 with RequiredActionProviderRepresentation

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

the class DeleteAccountActionTest method setUpAction.

@Before
public void setUpAction() {
    UserRepresentation user = ActionUtil.findUserWithAdminClient(adminClient, "test-user@localhost");
    UserBuilder.edit(user).requiredAction(DeleteAccount.PROVIDER_ID);
    testRealm().users().get(user.getId()).update(user);
    addDeleteAccountRoleToUserClientRoles();
    RequiredActionProviderRepresentation rep = testRealm().flows().getRequiredAction(DeleteAccount.PROVIDER_ID);
    rep.setEnabled(true);
    adminClient.realm("test").flows().updateRequiredAction(DeleteAccount.PROVIDER_ID, rep);
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Before(org.junit.Before)

Example 5 with RequiredActionProviderRepresentation

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

the class TermsAndConditionsTest method addTermsAndConditionRequiredAction.

@Before
public void addTermsAndConditionRequiredAction() {
    UserRepresentation user = ActionUtil.findUserWithAdminClient(adminClient, "test-user@localhost");
    UserBuilder.edit(user).requiredAction(TermsAndConditions.PROVIDER_ID);
    adminClient.realm("test").users().get(user.getId()).update(user);
    RequiredActionProviderRepresentation rep = adminClient.realm("test").flows().getRequiredAction("terms_and_conditions");
    rep.setEnabled(true);
    adminClient.realm("test").flows().updateRequiredAction("terms_and_conditions", rep);
}
Also used : RequiredActionProviderRepresentation(org.keycloak.representations.idm.RequiredActionProviderRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Before(org.junit.Before)

Aggregations

RequiredActionProviderRepresentation (org.keycloak.representations.idm.RequiredActionProviderRepresentation)33 Test (org.junit.Test)13 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)6 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)5 ArrayList (java.util.ArrayList)4 RealmResource (org.keycloak.admin.client.resource.RealmResource)4 RequiredActionProviderSimpleRepresentation (org.keycloak.representations.idm.RequiredActionProviderSimpleRepresentation)4 AbstractAuthenticationTest (org.keycloak.testsuite.admin.authentication.AbstractAuthenticationTest)4 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Before (org.junit.Before)3 AuthServerContainerExclude (org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude)3 SocialLoginTest (org.keycloak.testsuite.broker.SocialLoginTest)3 HashMap (java.util.HashMap)2 NotFoundException (javax.ws.rs.NotFoundException)2 SigningInPage (org.keycloak.testsuite.ui.account2.page.SigningInPage)2 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Response (javax.ws.rs.core.Response)1