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

The following examples show how to use org.keycloak.representations.idm.RealmRepresentation#setRegistrationEmailAsUsername() . 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: AccountRestServiceTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateProfileWithRegistrationEmailAsUsername() throws IOException {
    RealmRepresentation realmRep = adminClient.realm("test").toRepresentation();
    realmRep.setRegistrationEmailAsUsername(true);
    adminClient.realm("test").update(realmRep);

    UserRepresentation user = SimpleHttp.doGet(getAccountUrl(null), httpClient).auth(tokenUtil.getToken()).asJson(UserRepresentation.class);
    String originalFirstname = user.getFirstName();

    try {
        user.setFirstName("Homer1");

        user = updateAndGet(user);

        assertEquals("Homer1", user.getFirstName());
    } finally {
        user.setFirstName(originalFirstname);
        int status = SimpleHttp.doPost(getAccountUrl(null), httpClient).auth(tokenUtil.getToken()).json(user).asStatus();
        assertEquals(204, status);
    }
}
 
Example 2
Source File: AbstractFirstBrokerLoginTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
/**
 * Refers to in old test suite: org.keycloak.testsuite.broker.AbstractFirstBrokerLoginTest#testRegistrationWithEmailAsUsername
 * Refers to in old test suite: org.keycloak.testsuite.broker.AbstractKeycloakIdentityProviderTest#testSuccessfulAuthenticationWithoutUpdateProfile_newUser_emailAsUsername()
 */
@Test
public void testRequiredRegistrationEmailAsUserName() {
    RealmResource realm = adminClient.realm(bc.consumerRealmName());
    RealmRepresentation realmRep = realm.toRepresentation();

    updateExecutions(AbstractBrokerTest::enableUpdateProfileOnFirstLogin);
    realmRep.setRegistrationEmailAsUsername(true);
    realm.update(realmRep);

    driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
    logInWithBroker(bc);

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

    log.debug("Updating info on updateAccount page");
    try {
        updateAccountInformationPage.updateAccountInformation("test", "[email protected]", "FirstName", "LastName");
        Assert.fail("It is not expected to see username field");
    } catch (NoSuchElementException ignore) {
    }

    updateAccountInformationPage.updateAccountInformation("[email protected]", "FirstName", "LastName");
    waitForAccountManagementTitle();
    accountUpdateProfilePage.assertCurrent();

    assertEquals(1, realm.users().search("[email protected]").size());
}
 
Example 3
Source File: UserAttributesTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Test
public void createUserEmailAsUserName() {
    RealmRepresentation representation = testRealmResource().toRepresentation();
    representation.setRegistrationEmailAsUsername(true);
    testRealmResource().update(representation);
    
    newTestRealmUser.setEmail("[email protected]");
    createUser(newTestRealmUser);
    assertAlertSuccess();
}
 
Example 4
Source File: RealmTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Test
public void updateRealm() {
    // first change
    RealmRepresentation rep = realm.toRepresentation();
    rep.setSsoSessionIdleTimeout(123);
    rep.setSsoSessionMaxLifespan(12);
    rep.setSsoSessionIdleTimeoutRememberMe(33);
    rep.setSsoSessionMaxLifespanRememberMe(34);
    rep.setAccessCodeLifespanLogin(1234);
    rep.setActionTokenGeneratedByAdminLifespan(2345);
    rep.setActionTokenGeneratedByUserLifespan(3456);
    rep.setRegistrationAllowed(true);
    rep.setRegistrationEmailAsUsername(true);
    rep.setEditUsernameAllowed(true);
    rep.setUserManagedAccessAllowed(true);

    realm.update(rep);
    assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, Matchers.nullValue(String.class), rep, ResourceType.REALM);

    rep = realm.toRepresentation();

    assertEquals(123, rep.getSsoSessionIdleTimeout().intValue());
    assertEquals(12, rep.getSsoSessionMaxLifespan().intValue());
    assertEquals(33, rep.getSsoSessionIdleTimeoutRememberMe().intValue());
    assertEquals(34, rep.getSsoSessionMaxLifespanRememberMe().intValue());
    assertEquals(1234, rep.getAccessCodeLifespanLogin().intValue());
    assertEquals(2345, rep.getActionTokenGeneratedByAdminLifespan().intValue());
    assertEquals(3456, rep.getActionTokenGeneratedByUserLifespan().intValue());
    assertEquals(Boolean.TRUE, rep.isRegistrationAllowed());
    assertEquals(Boolean.TRUE, rep.isRegistrationEmailAsUsername());
    assertEquals(Boolean.TRUE, rep.isEditUsernameAllowed());
    assertEquals(Boolean.TRUE, rep.isUserManagedAccessAllowed());

    // second change
    rep.setRegistrationAllowed(false);
    rep.setRegistrationEmailAsUsername(false);
    rep.setEditUsernameAllowed(false);
    rep.setUserManagedAccessAllowed(false);

    realm.update(rep);
    assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, Matchers.nullValue(String.class), rep, ResourceType.REALM);

    rep = realm.toRepresentation();
    assertEquals(Boolean.FALSE, rep.isRegistrationAllowed());
    assertEquals(Boolean.FALSE, rep.isRegistrationEmailAsUsername());
    assertEquals(Boolean.FALSE, rep.isEditUsernameAllowed());
    assertEquals(Boolean.FALSE, rep.isUserManagedAccessAllowed());
}
 
Example 5
Source File: UserTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private void switchRegistrationEmailAsUsername(boolean enable) {
    RealmRepresentation rep = realm.toRepresentation();
    rep.setRegistrationEmailAsUsername(enable);
    realm.update(rep);
    assertAdminEvents.assertEvent(realmId, OperationType.UPDATE, Matchers.nullValue(String.class), rep, ResourceType.REALM);
}
 
Example 6
Source File: RegisterTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
protected void configureRealmRegistrationEmailAsUsername(final boolean value) {
    RealmRepresentation realm = testRealm().toRepresentation();
    realm.setRegistrationEmailAsUsername(value);
    testRealm().update(realm);
}
 
Example 7
Source File: AccountFormServiceTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
private void setRegistrationEmailAsUsername(boolean allowed) {
    RealmRepresentation testRealm = testRealm().toRepresentation();
    testRealm.setRegistrationEmailAsUsername(allowed);
    testRealm().update(testRealm);
}