public static void updateUserFromRep( UserModel user, UserRepresentation rep, Set<String> attrsToRemove, RealmModel realm, KeycloakSession session) { if (realm.isEditUsernameAllowed()) { user.setUsername(rep.getUsername()); } user.setEmail(rep.getEmail()); user.setFirstName(rep.getFirstName()); user.setLastName(rep.getLastName()); if (rep.isEnabled() != null) user.setEnabled(rep.isEnabled()); if (rep.isTotp() != null) user.setOtpEnabled(rep.isTotp()); if (rep.isEmailVerified() != null) user.setEmailVerified(rep.isEmailVerified()); List<String> reqActions = rep.getRequiredActions(); if (reqActions != null) { Set<String> allActions = new HashSet<>(); for (ProviderFactory factory : session.getKeycloakSessionFactory().getProviderFactories(RequiredActionProvider.class)) { allActions.add(factory.getId()); } for (String action : allActions) { if (reqActions.contains(action)) { user.addRequiredAction(action); } else { user.removeRequiredAction(action); } } } if (rep.getAttributesAsListValues() != null) { for (Map.Entry<String, List<String>> attr : rep.getAttributesAsListValues().entrySet()) { user.setAttribute(attr.getKey(), attr.getValue()); } for (String attr : attrsToRemove) { user.removeAttribute(attr); } } }
public void setValues(UserRepresentation user) { setUsername(user.getUsername()); setEmail(user.getEmail()); setFirstName(user.getFirstName()); setLastName(user.getLastName()); }