public void setRequiredActionEnabled(
      String realm, String userId, String requiredAction, boolean enabled) {
    UsersResource usersResource = adminClient.realm(realm).users();

    UserResource userResource = usersResource.get(userId);
    UserRepresentation userRepresentation = userResource.toRepresentation();

    List<String> requiredActions = userRepresentation.getRequiredActions();
    if (enabled && !requiredActions.contains(requiredAction)) {
      requiredActions.add(requiredAction);
    } else if (!enabled && requiredActions.contains(requiredAction)) {
      requiredActions.remove(requiredAction);
    }

    userResource.update(userRepresentation);
  }
Example #2
0
  @Test
  public void logInAsUserInIDP() {
    driver.navigate().to(getAccountUrl(consumerRealmName()));

    log.debug("Clicking social " + getIDPAlias());
    accountLoginPage.clickSocial(getIDPAlias());

    waitForPage("log in to");

    Assert.assertTrue(
        "Driver should be on the provider realm page right now",
        driver.getCurrentUrl().contains("/auth/realms/" + providerRealmName() + "/"));

    log.debug("Logging in");
    accountLoginPage.login(getUserLogin(), getUserPassword());

    waitForPage("update account information");

    Assert.assertTrue(updateAccountInformationPage.isCurrent());
    Assert.assertTrue(
        "We must be on correct realm right now",
        driver.getCurrentUrl().contains("/auth/realms/" + consumerRealmName() + "/"));

    log.debug("Updating info on updateAccount page");
    updateAccountInformationPage.updateAccountInformation("Firstname", "Lastname");

    UsersResource consumerUsers = adminClient.realm(consumerRealmName()).users();

    int userCount = consumerUsers.count();
    Assert.assertTrue("There must be at least one user", userCount > 0);

    List<UserRepresentation> users = consumerUsers.search("", 0, userCount);

    boolean isUserFound = false;
    for (UserRepresentation user : users) {
      if (user.getUsername().equals(getUserLogin()) && user.getEmail().equals(getUserEmail())) {
        isUserFound = true;
        break;
      }
    }

    Assert.assertTrue(
        "There must be user " + getUserLogin() + " in realm " + consumerRealmName(), isUserFound);

    testSingleLogout();
  }