Java Code Examples for org.keycloak.representations.idm.UserRepresentation#setEmailVerified()

The following examples show how to use org.keycloak.representations.idm.UserRepresentation#setEmailVerified() . 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: ConsentsTest.java    From keycloak with Apache License 2.0 7 votes vote down vote up
@Before
public void createUser() {
    log.debug("creating user for realm " + providerRealmName());

    UserRepresentation user = new UserRepresentation();
    user.setUsername(getUserLogin());
    user.setEmail(getUserEmail());
    user.setFirstName(getUserFirstName());
    user.setLastName(getUserLastName());
    user.setEmailVerified(true);
    user.setEnabled(true);

    RealmResource realmResource = adminClient.realm(providerRealmName());
    String userId = createUserWithAdminClient(realmResource, user);

    resetUserPassword(realmResource.users().get(userId), getUserPassword(), false);
}
 
Example 2
Source File: KeyCloakServiceImpl.java    From sunbird-lms-service with MIT License 6 votes vote down vote up
/**
 * This method will update user email verified status
 *
 * @param userId String
 * @param status boolean
 * @throws ProjectCommonException
 */
private void updateEmailVerifyStatus(String userId, boolean status) {
  try {
    String fedUserId = getFederatedUserId(userId);
    UserResource resource =
        keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(fedUserId);
    UserRepresentation ur = resource.toRepresentation();
    ur.setEmailVerified(status);
    if (isNotNull(resource)) {
      resource.update(ur);
    }
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
    ProjectUtil.createAndThrowInvalidUserDataException();
  }
}
 
Example 3
Source File: AbstractSpringBootTest.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void addUser(String login, String email, String password, String... roles) {
    UserRepresentation userRepresentation = new UserRepresentation();

    userRepresentation.setUsername(login);
    userRepresentation.setEmail(email);
    userRepresentation.setEmailVerified(true);
    userRepresentation.setEnabled(true);

    RealmResource realmResource = adminClient.realm(REALM_NAME);
    String userId = createUserWithAdminClient(realmResource, userRepresentation);

    resetUserPassword(realmResource.users().get(userId), password, false);

    for (String role : roles)
        assignRealmRoles(realmResource, userId, role);
}
 
Example 4
Source File: KeyCloakServiceImpl.java    From sunbird-lms-service with MIT License 5 votes vote down vote up
@Override
public void setRequiredAction(String userId, String requiredAction) {
  String fedUserId = getFederatedUserId(userId);
  UserResource resource =
      keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(fedUserId);

  UserRepresentation userRepresentation = resource.toRepresentation();
  userRepresentation.setRequiredActions(asList(requiredAction));
  if (KeycloakRequiredActionLinkUtil.VERIFY_EMAIL.equalsIgnoreCase(requiredAction)) {
    userRepresentation.setEmailVerified(false);
  }
  resource.update(userRepresentation);
}
 
Example 5
Source File: PasswordHistoryPolicyTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public UserRepresentation createUserRepresentation(String username) {
    UserRepresentation userRepresentation = new UserRepresentation();
    userRepresentation.setUsername(username);
    userRepresentation.setEmail(String.format("%[email protected]", userRepresentation.getUsername()));
    userRepresentation.setEmailVerified(true);
    return userRepresentation;
}
 
Example 6
Source File: AbstractIdentityProviderMapperTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected void createUserInProviderRealm(Map<String, List<String>> attributes) {
    log.debug("Creating user in realm " + bc.providerRealmName());

    UserRepresentation user = UserBuilder.create()
            .username(bc.getUserLogin())
            .email(bc.getUserEmail())
            .build();
    user.setEmailVerified(true);
    user.setAttributes(attributes);

    this.userId = createUserAndResetPasswordWithAdminClient(adminClient.realm(bc.providerRealmName()), user, bc.getUserPassword());
}
 
Example 7
Source File: KcOIDCBrokerWithSignatureTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Before
public void createUser() {
    log.debug("creating user for realm " + bc.providerRealmName());

    UserRepresentation user = new UserRepresentation();
    user.setUsername(bc.getUserLogin());
    user.setEmail(bc.getUserEmail());
    user.setEmailVerified(true);
    user.setEnabled(true);

    RealmResource realmResource = adminClient.realm(bc.providerRealmName());
    String userId = createUserWithAdminClient(realmResource, user);

    resetUserPassword(realmResource.users().get(userId), bc.getUserPassword(), false);
}
 
Example 8
Source File: KcOidcBrokerLogoutTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Before
public void createUser() {
    log.debug("creating user for realm " + bc.providerRealmName());

    final UserRepresentation user = new UserRepresentation();
    user.setUsername(bc.getUserLogin());
    user.setEmail(bc.getUserEmail());
    user.setEmailVerified(true);
    user.setEnabled(true);

    final RealmResource realmResource = adminClient.realm(bc.providerRealmName());
    final String userId = createUserWithAdminClient(realmResource, user);

    resetUserPassword(realmResource.users().get(userId), bc.getUserPassword(), false);
}
 
Example 9
Source File: AccountBrokerTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Before
public void createUser() {
    log.debug("creating user for realm " + bc.providerRealmName());

    UserRepresentation user = new UserRepresentation();
    user.setUsername(bc.getUserLogin());
    user.setEmail(bc.getUserEmail());
    user.setEmailVerified(true);
    user.setEnabled(true);

    RealmResource realmResource = adminClient.realm(bc.providerRealmName());
    userId = createUserWithAdminClient(realmResource, user);

    resetUserPassword(realmResource.users().get(userId), bc.getUserPassword(), false);
}
 
Example 10
Source File: OIDCScopeTest.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public void configureTestRealm(RealmRepresentation testRealm) {
    UserRepresentation user = UserBuilder.create()
            .id(userId)
            .username("john")
            .enabled(true)
            .email("[email protected]")
            .firstName("John")
            .lastName("Doe")
            .password("password")
            .role("account", "manage-account")
            .role("account", "view-profile")
            .addRoles("role-1", "role-2")
            .build();

    user.setEmailVerified(true);
    MultivaluedHashMap<String, String> attrs = new MultivaluedHashMap<>();
    attrs.add("street", "Elm 5");
    attrs.add("phoneNumber", "111-222-333");
    attrs.add("phoneNumberVerified", "true");
    user.setAttributes(attrs);

    testRealm.getUsers().add(user);


    // Add sample realm roles
    RoleRepresentation role1 = new RoleRepresentation();
    role1.setName("role-1");
    testRealm.getRoles().getRealm().add(role1);
    RoleRepresentation role2 = new RoleRepresentation();
    role2.setName("role-2");
    testRealm.getRoles().getRealm().add(role2);

    RoleRepresentation roleParent = RoleBuilder.create()
            .name("role-parent")
            .realmComposite("role-1")
            .build();
    testRealm.getRoles().getRealm().add(roleParent);

    // Add sample group
    GroupRepresentation group = new GroupRepresentation();
    group.setName("group-role-1");
    group.setRealmRoles(Collections.singletonList("role-1"));
    testRealm.getGroups().add(group);

    // Add more sample users
    user = UserBuilder.create()
            .username("role-1-user")
            .enabled(true)
            .password("password")
            .addRoles("role-1")
            .build();
    testRealm.getUsers().add(user);

    user = UserBuilder.create()
            .username("role-2-user")
            .enabled(true)
            .password("password")
            .addRoles("role-2")
            .build();
    testRealm.getUsers().add(user);

    user = UserBuilder.create()
            .username("role-parent-user")
            .enabled(true)
            .password("password")
            .addRoles("role-parent")
            .build();
    testRealm.getUsers().add(user);

    user = UserBuilder.create()
            .username("group-role-1-user")
            .enabled(true)
            .password("password")
            .addGroups("group-role-1")
            .build();
    testRealm.getUsers().add(user);
}