Java Code Examples for org.keycloak.representations.idm.UserRepresentation#setAttributes()
The following examples show how to use
org.keycloak.representations.idm.UserRepresentation#setAttributes() .
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: KeyCloakServiceImpl.java From sunbird-lms-service with MIT License | 6 votes |
@Override public void setEmailVerifiedUpdatedFlag(String userId, String flag) { String fedUserId = getFederatedUserId(userId); UserResource resource = keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(fedUserId); UserRepresentation user = resource.toRepresentation(); Map<String, List<String>> map = user.getAttributes(); List<String> list = new ArrayList<>(); list.add(flag); if (map == null) { map = new HashMap<>(); } map.put(JsonKey.EMAIL_VERIFIED_UPDATED, list); user.setAttributes(map); resource.update(user); }
Example 2
Source File: OIDCProtocolMappersTest.java From keycloak with Apache License 2.0 | 6 votes |
@Test public void testGroupAttributeUserOneGroupMultivalueNoAggregate() throws Exception { // get the user UserResource userResource = findUserByUsernameId(adminClient.realm("test"), "test-user@localhost"); UserRepresentation user = userResource.toRepresentation(); user.setAttributes(new HashMap<>()); user.getAttributes().put("group-value", Arrays.asList("user-value1", "user-value2")); userResource.update(user); // create a group1 with two values GroupRepresentation group1 = new GroupRepresentation(); group1.setName("group1"); group1.setAttributes(new HashMap<>()); group1.getAttributes().put("group-value", Arrays.asList("value1", "value2")); adminClient.realm("test").groups().add(group1); group1 = adminClient.realm("test").getGroupByPath("/group1"); userResource.joinGroup(group1.getId()); // create the attribute mapper ProtocolMappersResource protocolMappers = findClientResourceByClientId(adminClient.realm("test"), "test-app").getProtocolMappers(); protocolMappers.createMapper(createClaimMapper("group-value", "group-value", "group-value", "String", true, true, true, false)).close(); try { // test it OAuthClient.AccessTokenResponse response = browserLogin("password", "test-user@localhost", "password"); IDToken idToken = oauth.verifyIDToken(response.getIdToken()); assertNotNull(idToken.getOtherClaims()); assertNotNull(idToken.getOtherClaims().get("group-value")); assertTrue(idToken.getOtherClaims().get("group-value") instanceof List); assertEquals(2, ((List) idToken.getOtherClaims().get("group-value")).size()); assertTrue(((List) idToken.getOtherClaims().get("group-value")).contains("user-value1")); assertTrue(((List) idToken.getOtherClaims().get("group-value")).contains("user-value2")); } finally { // revert user.getAttributes().remove("group-value"); userResource.update(user); userResource.leaveGroup(group1.getId()); adminClient.realm("test").groups().group(group1.getId()).remove(); deleteMappers(protocolMappers); } }
Example 3
Source File: KeyCloakServiceImpl.java From sunbird-lms-service with MIT License | 5 votes |
@Override public boolean addUserLoginTime(String userId) { boolean response = true; try { String fedUserId = getFederatedUserId(userId); UserResource resource = keycloak.realm(KeyCloakConnectionProvider.SSO_REALM).users().get(fedUserId); UserRepresentation ur = resource.toRepresentation(); Map<String, List<String>> map = ur.getAttributes(); List<String> list = new ArrayList<>(); if (map == null) { map = new HashMap<>(); } List<String> currentLogTime = map.get(JsonKey.CURRENT_LOGIN_TIME); if (currentLogTime == null || currentLogTime.isEmpty()) { currentLogTime = new ArrayList<>(); currentLogTime.add(Long.toString(System.currentTimeMillis())); } else { list.add(currentLogTime.get(0)); currentLogTime.clear(); currentLogTime.add(0, Long.toString(System.currentTimeMillis())); } map.put(JsonKey.CURRENT_LOGIN_TIME, currentLogTime); map.put(JsonKey.LAST_LOGIN_TIME, list); ur.setAttributes(map); resource.update(ur); } catch (Exception e) { ProjectLogger.log(e.getMessage(), e); response = false; } return response; }
Example 4
Source File: ManyUsersTest.java From keycloak with Apache License 2.0 | 5 votes |
@Override public UserRepresentation createUser(UsersResource users, UserRepresentation user) { // Add some additional attributes to user if (CREATE_OBJECTS) { Map<String, List<String>> attrs = new HashMap<>(); attrs.put("attr1", Collections.singletonList("val1")); attrs.put("attr2", Collections.singletonList("val2")); user.setAttributes(attrs); } UserRepresentation userRep = super.createUser(users, user); // Add password if (CREATE_OBJECTS) { CredentialRepresentation password = new CredentialRepresentation(); password.setType(CredentialRepresentation.PASSWORD); password.setValue("password"); password.setTemporary(false); users.get(userRep.getId()).resetPassword(password); } // Add social link if (CREATE_SOCIAL_LINKS) { createSocialLink("facebook", users, userRep.getId()); } return userRep; }
Example 5
Source File: LDAPBinaryAttributesTest.java From keycloak with Apache License 2.0 | 5 votes |
@Test public void test03WritableMapper() { String mapperId = addPhotoMapper(testingClient); // Create user joe with jpegPHoto UserRepresentation joe = new UserRepresentation(); joe.setUsername("joephoto"); joe.setEmail("[email protected]"); joe.setAttributes(Collections.singletonMap(LDAPConstants.JPEG_PHOTO, Arrays.asList(JPEG_PHOTO_BASE64))); Response response = adminClient.realm("test").users().create(joe); response.close(); // Assert he is found including jpegPhoto joe = getUserAndAssertPhoto("joephoto", true); // Try to update him with some big non-LDAP mapped attribute. It will fail try { joe.getAttributes().put("someOtherPhoto", Arrays.asList(JPEG_PHOTO_BASE64)); adminClient.realm("test").users().get(joe.getId()).update(joe); Assert.fail("Not expected to successfully update user"); } catch (ClientErrorException cee) { // Expected } // Remove jpegPhoto attribute and assert it was successfully removed joe.getAttributes().remove("someOtherPhoto"); joe.getAttributes().remove(LDAPConstants.JPEG_PHOTO); adminClient.realm("test").users().get(joe.getId()).update(joe); getUserAndAssertPhoto("joephoto", false); }
Example 6
Source File: AbstractIdentityProviderMapperTest.java From keycloak with Apache License 2.0 | 5 votes |
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: HardcodedUserAttributeMapperTest.java From keycloak with Apache License 2.0 | 5 votes |
protected UserRepresentation loginAsUserTwiceWithMapper( IdentityProviderMapperSyncMode syncMode, boolean createAfterFirstLogin) { final IdentityProviderRepresentation idp = setupIdentityProvider(); if (!createAfterFirstLogin) { createMapperInIdp(idp, syncMode); } createUserInProviderRealm(); logInAsUserInIDPForFirstTime(); UserRepresentation user = findUser(bc.consumerRealmName(), bc.getUserLogin(), bc.getUserEmail()); if (!createAfterFirstLogin) { assertThatAttributeHasBeenAssigned(user); } else { assertThatAttributeHasNotBeenAssigned(user); } if (createAfterFirstLogin) { createMapperInIdp(idp, syncMode); } logoutFromRealm(getConsumerRoot(), bc.consumerRealmName()); if (user.getAttributes() != null) { user.setAttributes(new HashMap<>()); } adminClient.realm(bc.consumerRealmName()).users().get(user.getId()).update(user); logInAsUserInIDP(); return findUser(bc.consumerRealmName(), bc.getUserLogin(), bc.getUserEmail()); }
Example 8
Source File: OidcClaimToRoleMapperTest.java From keycloak with Apache License 2.0 | 5 votes |
@Override protected void updateUser() { UserRepresentation user = findUser(bc.providerRealmName(), bc.getUserLogin(), bc.getUserEmail()); ImmutableMap<String, List<String>> mismatchingAttributes = ImmutableMap.<String, List<String>>builder() .put(CLAIM, ImmutableList.<String>builder().add(claimOnSecondLogin).build()) .build(); user.setAttributes(mismatchingAttributes); adminClient.realm(bc.providerRealmName()).users().get(user.getId()).update(user); }
Example 9
Source File: AbstractUserAttributeMapperTest.java From keycloak with Apache License 2.0 | 5 votes |
private void testValueMapping(Map<String, List<String>> initialUserAttributes, Map<String, List<String>> modifiedUserAttributes, Map<String, List<String>> assertedModifiedAttributes) { String email = bc.getUserEmail(); createUserInProviderRealm(initialUserAttributes); logInAsUserInIDPForFirstTime(); UserRepresentation userRep = findUser(bc.consumerRealmName(), bc.getUserLogin(), email); assertUserAttributes(initialUserAttributes, userRep); logoutFromRealm(getConsumerRoot(), bc.consumerRealmName()); // update user in provider realm UserRepresentation userRepProvider = findUser(bc.providerRealmName(), bc.getUserLogin(), email); Map<String, List<String>> modifiedWithoutSpecialKeys = modifiedUserAttributes.entrySet().stream() .filter(a -> ! PROTECTED_NAMES.contains(a.getKey())) .filter(a -> a.getValue() != null) // Remove empty attributes .collect(Collectors.toMap(p -> p.getKey(), p -> p.getValue())); userRepProvider.setAttributes(modifiedWithoutSpecialKeys); if (modifiedUserAttributes.containsKey("email")) { userRepProvider.setEmail(modifiedUserAttributes.get("email").get(0)); email = modifiedUserAttributes.get("email").get(0); } if (modifiedUserAttributes.containsKey("firstName")) { userRepProvider.setFirstName(modifiedUserAttributes.get("firstName").get(0)); } if (modifiedUserAttributes.containsKey("lastName")) { userRepProvider.setLastName(modifiedUserAttributes.get("lastName").get(0)); } adminClient.realm(bc.providerRealmName()).users().get(userRepProvider.getId()).update(userRepProvider); logInAsUserInIDP(); userRep = findUser(bc.consumerRealmName(), bc.getUserLogin(), email); assertUserAttributes(assertedModifiedAttributes, userRep); }
Example 10
Source File: AbstractUsernameTemplateMapperTest.java From keycloak with Apache License 2.0 | 5 votes |
private void updateUser(String updatedUserName) { UserRepresentation user = findUser(bc.providerRealmName(), bc.getUserLogin(), bc.getUserEmail()); ImmutableMap<String, List<String>> matchingAttributes = ImmutableMap.<String, List<String>>builder() .put(KcOidcBrokerConfiguration.ATTRIBUTE_TO_MAP_NAME, ImmutableList.<String>builder().add(updatedUserName).build()) .build(); user.setAttributes(matchingAttributes); adminClient.realm(bc.providerRealmName()).users().get(user.getId()).update(user); }
Example 11
Source File: OidcAdvancedClaimToRoleMapperTest.java From keycloak with Apache License 2.0 | 5 votes |
@Override protected void updateUser() { UserRepresentation user = findUser(bc.providerRealmName(), bc.getUserLogin(), bc.getUserEmail()); ImmutableMap<String, List<String>> matchingAttributes = ImmutableMap.<String, List<String>>builder() .put(KcOidcBrokerConfiguration.ATTRIBUTE_TO_MAP_NAME, ImmutableList.<String>builder().add("value 1").build()) .put(KcOidcBrokerConfiguration.ATTRIBUTE_TO_MAP_NAME_2, ImmutableList.<String>builder().add(newValueForAttribute2).build()) .put("some.other.attribute", ImmutableList.<String>builder().add("some value").build()) .build(); user.setAttributes(matchingAttributes); adminClient.realm(bc.providerRealmName()).users().get(user.getId()).update(user); }
Example 12
Source File: OIDCProtocolMappersTest.java From keycloak with Apache License 2.0 | 5 votes |
@Test public void testGroupAttributeUserOneGroupNoMultivalueNoAggregate() throws Exception { // get the user UserResource userResource = findUserByUsernameId(adminClient.realm("test"), "test-user@localhost"); UserRepresentation user = userResource.toRepresentation(); user.setAttributes(new HashMap<>()); user.getAttributes().put("group-value", Arrays.asList("user-value1", "user-value2")); userResource.update(user); // create a group1 with two values GroupRepresentation group1 = new GroupRepresentation(); group1.setName("group1"); group1.setAttributes(new HashMap<>()); group1.getAttributes().put("group-value", Arrays.asList("value1", "value2")); adminClient.realm("test").groups().add(group1); group1 = adminClient.realm("test").getGroupByPath("/group1"); userResource.joinGroup(group1.getId()); // create the attribute mapper ProtocolMappersResource protocolMappers = findClientResourceByClientId(adminClient.realm("test"), "test-app").getProtocolMappers(); protocolMappers.createMapper(createClaimMapper("group-value", "group-value", "group-value", "String", true, true, false, false)).close(); try { // test it OAuthClient.AccessTokenResponse response = browserLogin("password", "test-user@localhost", "password"); IDToken idToken = oauth.verifyIDToken(response.getIdToken()); assertNotNull(idToken.getOtherClaims()); assertNotNull(idToken.getOtherClaims().get("group-value")); assertTrue(idToken.getOtherClaims().get("group-value") instanceof String); assertTrue("user-value1".equals(idToken.getOtherClaims().get("group-value")) || "user-value2".equals(idToken.getOtherClaims().get("group-value"))); } finally { // revert user.getAttributes().remove("group-value"); userResource.update(user); userResource.leaveGroup(group1.getId()); adminClient.realm("test").groups().group(group1.getId()).remove(); deleteMappers(protocolMappers); } }
Example 13
Source File: UserImportService.java From keycloak-config-cli with Apache License 2.0 | 5 votes |
private void updateUser(UserRepresentation existingUser) { UserRepresentation patchedUser = CloneUtil.deepPatch(existingUser, userToImport, IGNORED_PROPERTIES_FOR_UPDATE); if (userToImport.getAttributes() != null) { patchedUser.setAttributes(userToImport.getAttributes()); } if (!CloneUtil.deepEquals(existingUser, patchedUser, "access")) { logger.debug("Update user '{}' in realm '{}'", username, realm); userRepository.updateUser(realm, patchedUser); } else { logger.debug("No need to update user '{}' in realm '{}'", username, realm); } }
Example 14
Source File: KcSamlBrokerTest.java From keycloak with Apache License 2.0 | 4 votes |
@Test public void roleWithDots() { createRolesForRealm(bc.providerRealmName()); createRolesForRealm(bc.consumerRealmName()); createRoleMappersForConsumerRealm(); RoleRepresentation managerRole = adminClient.realm(bc.providerRealmName()).roles().get(ROLE_MANAGER).toRepresentation(); RoleRepresentation userRole = adminClient.realm(bc.providerRealmName()).roles().get(ROLE_USER).toRepresentation(); RoleRepresentation userRoleDotGuide = adminClient.realm(bc.providerRealmName()).roles().get(ROLE_USER_DOT_GUIDE).toRepresentation(); UserResource userResourceProv = adminClient.realm(bc.providerRealmName()).users().get(userId); userResourceProv.roles().realmLevel().add(Collections.singletonList(managerRole)); logInAsUserInIDPForFirstTime(); String consUserId = adminClient.realm(bc.consumerRealmName()).users().search(bc.getUserLogin()).iterator().next().getId(); UserResource userResourceCons = adminClient.realm(bc.consumerRealmName()).users().get(consUserId); Set<String> currentRoles = userResourceCons.roles().realmLevel().listAll().stream() .map(RoleRepresentation::getName) .collect(Collectors.toSet()); assertThat(currentRoles, hasItems(ROLE_MANAGER)); assertThat(currentRoles, not(hasItems(ROLE_USER, ROLE_FRIENDLY_MANAGER, ROLE_USER_DOT_GUIDE))); logoutFromRealm(getConsumerRoot(), bc.consumerRealmName()); UserRepresentation urp = userResourceProv.toRepresentation(); urp.setAttributes(new HashMap<>()); urp.getAttributes().put(AbstractUserAttributeMapperTest.ATTRIBUTE_TO_MAP_FRIENDLY_NAME, Collections.singletonList(ROLE_FRIENDLY_MANAGER)); userResourceProv.update(urp); userResourceProv.roles().realmLevel().add(Collections.singletonList(userRole)); userResourceProv.roles().realmLevel().add(Collections.singletonList(userRoleDotGuide)); logInAsUserInIDP(); currentRoles = userResourceCons.roles().realmLevel().listAll().stream() .map(RoleRepresentation::getName) .collect(Collectors.toSet()); assertThat(currentRoles, hasItems(ROLE_MANAGER, ROLE_USER, ROLE_USER_DOT_GUIDE, ROLE_FRIENDLY_MANAGER)); logoutFromRealm(getConsumerRoot(), bc.consumerRealmName()); urp = userResourceProv.toRepresentation(); urp.setAttributes(new HashMap<>()); userResourceProv.update(urp); logInAsUserInIDP(); currentRoles = userResourceCons.roles().realmLevel().listAll().stream() .map(RoleRepresentation::getName) .collect(Collectors.toSet()); assertThat(currentRoles, hasItems(ROLE_MANAGER, ROLE_USER, ROLE_USER_DOT_GUIDE)); assertThat(currentRoles, not(hasItems(ROLE_FRIENDLY_MANAGER))); logoutFromRealm(getProviderRoot(), bc.providerRealmName()); logoutFromRealm(getConsumerRoot(), bc.consumerRealmName()); }
Example 15
Source File: OIDCProtocolMappersTest.java From keycloak with Apache License 2.0 | 4 votes |
@Test public void testGroupAttributeUserOneGroupMultivalueAggregate() throws Exception { // get the user UserResource userResource = findUserByUsernameId(adminClient.realm("test"), "test-user@localhost"); UserRepresentation user = userResource.toRepresentation(); user.setAttributes(new HashMap<>()); user.getAttributes().put("group-value", Arrays.asList("user-value1", "user-value2")); userResource.update(user); // create a group1 with two values GroupRepresentation group1 = new GroupRepresentation(); group1.setName("group1"); group1.setAttributes(new HashMap<>()); group1.getAttributes().put("group-value", Arrays.asList("value1", "value2")); adminClient.realm("test").groups().add(group1); group1 = adminClient.realm("test").getGroupByPath("/group1"); userResource.joinGroup(group1.getId()); // create the attribute mapper ProtocolMappersResource protocolMappers = findClientResourceByClientId(adminClient.realm("test"), "test-app").getProtocolMappers(); protocolMappers.createMapper(createClaimMapper("group-value", "group-value", "group-value", "String", true, true, true, true)).close(); try { // test it OAuthClient.AccessTokenResponse response = browserLogin("password", "test-user@localhost", "password"); IDToken idToken = oauth.verifyIDToken(response.getIdToken()); assertNotNull(idToken.getOtherClaims()); assertNotNull(idToken.getOtherClaims().get("group-value")); assertTrue(idToken.getOtherClaims().get("group-value") instanceof List); assertEquals(4, ((List) idToken.getOtherClaims().get("group-value")).size()); assertTrue(((List) idToken.getOtherClaims().get("group-value")).contains("user-value1")); assertTrue(((List) idToken.getOtherClaims().get("group-value")).contains("user-value2")); assertTrue(((List) idToken.getOtherClaims().get("group-value")).contains("value1")); assertTrue(((List) idToken.getOtherClaims().get("group-value")).contains("value2")); } finally { // revert user.getAttributes().remove("group-value"); userResource.update(user); userResource.leaveGroup(group1.getId()); adminClient.realm("test").groups().group(group1.getId()).remove(); deleteMappers(protocolMappers); } }
Example 16
Source File: OIDCScopeTest.java From keycloak with Apache License 2.0 | 4 votes |
@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); }
Example 17
Source File: ExportUtils.java From keycloak with Apache License 2.0 | 4 votes |
/** * Full export of user data stored in federated storage (including role mappings and credentials) * * @param id * @return fully exported user representation */ public static UserRepresentation exportFederatedUser(KeycloakSession session, RealmModel realm, String id, ExportOptions options) { UserRepresentation userRep = new UserRepresentation(); userRep.setId(id); MultivaluedHashMap<String, String> attributes = session.userFederatedStorage().getAttributes(realm, id); if (attributes.size() > 0) { Map<String, List<String>> attrs = new HashMap<>(); attrs.putAll(attributes); userRep.setAttributes(attrs); } Set<String> requiredActions = session.userFederatedStorage().getRequiredActions(realm, id); if (requiredActions.size() > 0) { List<String> actions = new LinkedList<>(); actions.addAll(requiredActions); userRep.setRequiredActions(actions); } // Social links Set<FederatedIdentityModel> socialLinks = session.userFederatedStorage().getFederatedIdentities(id, realm); List<FederatedIdentityRepresentation> socialLinkReps = new ArrayList<>(); for (FederatedIdentityModel socialLink : socialLinks) { FederatedIdentityRepresentation socialLinkRep = exportSocialLink(socialLink); socialLinkReps.add(socialLinkRep); } if (socialLinkReps.size() > 0) { userRep.setFederatedIdentities(socialLinkReps); } // Role mappings if (options.isGroupsAndRolesIncluded()) { Set<RoleModel> roles = session.userFederatedStorage().getRoleMappings(realm, id); List<String> realmRoleNames = new ArrayList<>(); Map<String, List<String>> clientRoleNames = new HashMap<>(); for (RoleModel role : roles) { if (role.getContainer() instanceof RealmModel) { realmRoleNames.add(role.getName()); } else { ClientModel client = (ClientModel) role.getContainer(); String clientId = client.getClientId(); List<String> currentClientRoles = clientRoleNames.get(clientId); if (currentClientRoles == null) { currentClientRoles = new ArrayList<>(); clientRoleNames.put(clientId, currentClientRoles); } currentClientRoles.add(role.getName()); } } if (realmRoleNames.size() > 0) { userRep.setRealmRoles(realmRoleNames); } if (clientRoleNames.size() > 0) { userRep.setClientRoles(clientRoleNames); } } // Credentials List<CredentialModel> creds = session.userFederatedStorage().getStoredCredentials(realm, id); List<CredentialRepresentation> credReps = new ArrayList<>(); for (CredentialModel cred : creds) { CredentialRepresentation credRep = exportCredential(cred); credReps.add(credRep); } userRep.setCredentials(credReps); // Grants List<UserConsentModel> consents = session.users().getConsents(realm, id); LinkedList<UserConsentRepresentation> consentReps = new LinkedList<>(); for (UserConsentModel consent : consents) { UserConsentRepresentation consentRep = ModelToRepresentation.toRepresentation(consent); consentReps.add(consentRep); } if (consentReps.size() > 0) { userRep.setClientConsents(consentReps); } // Not Before int notBefore = session.userFederatedStorage().getNotBeforeOfUser(realm, userRep.getId()); userRep.setNotBefore(notBefore); if (options.isGroupsAndRolesIncluded()) { List<String> groups = new LinkedList<>(); for (GroupModel group : session.userFederatedStorage().getGroups(realm, id)) { groups.add(ModelToRepresentation.buildGroupPath(group)); } userRep.setGroups(groups); } return userRep; }