Skip to content

Commit

Permalink
Merge pull request #861 from lme-atolcd/fix-user-declarative-profile-…
Browse files Browse the repository at this point in the history
…import

Allow importing attribute groups in User Declarative Profile
  • Loading branch information
st3v0rr authored Jul 13, 2023
2 parents 49ecfe7 + a0283f1 commit 34fe17f
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI

env:
# https://github.com/actions/virtual-environments/issues/1499
MAVEN_CLI_OPTS: '-ntp --batch-mode --errors --fail-at-end --show-version -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dstyle.color=always'
MAVEN_CLI_OPTS: '-ntp --batch-mode --errors --fail-at-end --show-version -Dmaven.wagon.httpconnectionManager.ttlSeconds=60 -Dmaven.wagon.http.retryHandler.count=3 -Dstyle.color=always'
TESTCONTAINERS_RYUK_DISABLED: 'true'
CT_CHART_DIRS: 'contrib/charts/'
CT_BUILD_ID: '${{ github.run_id }}'
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- Refactored support for user profile updates
- Attribute groups are now allowed in the `userProfile` property in json import. The format to import User Declarative Profile attributes (and attribute groups) has slightly changed. To migrate to the new format:
- transform the `userProfile` property to a JSON object with two properties: `attributes` and `groups`
- copy the JSON array of the old `userProfile` property to the new `userProfile.attributes` property
- create a new JSON array for the `userProfile.groups` property (containing the attribute groups definitions)
- in the end, the `userProfile` property should match the content of the "JSON editor" tab in the "Realm settings > User profile" page from the Keycloak admin console
- Add support for managing client-policies

## [5.6.1] - 2023-03-05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Component
public class RealmImport extends RealmRepresentation {
private List<AuthenticationFlowImport> authenticationFlowImports;

private List<LinkedHashMap<String, Object>> userProfile;
private Map<String, List<Map<String, Object>>> userProfile;

private String checksum;

Expand All @@ -54,11 +54,11 @@ public void setAuthenticationFlowImports(List<AuthenticationFlowImport> authenti

@SuppressWarnings("unused")
@JsonSetter("userProfile")
public void setUserProfile(List<LinkedHashMap<String, Object>> userProfile) {
public void setUserProfile(Map<String, List<Map<String, Object>>> userProfile) {
this.userProfile = userProfile;
}

public List<LinkedHashMap<String, Object>> getUserProfile() {
public Map<String, List<Map<String, Object>>> getUserProfile() {
return userProfile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedHashMap;

@Service
public class UserProfileImportService {
private static final Logger logger = LoggerFactory.getLogger(UserProfileImportService.class);
Expand All @@ -42,7 +40,6 @@ public UserProfileImportService(UserProfileRepository userProfileRepository) {
}

public void doImport(RealmImport realmImport) {

var userProfileEnabledString = realmImport.getAttributesOrEmpty().get(UserProfileRepository.REALM_ATTRIBUTES_USER_PROFILE_ENABLED_STRING);
if (userProfileEnabledString == null) {
//if not defined at all, ignore everything else
Expand All @@ -59,14 +56,10 @@ public void doImport(RealmImport realmImport) {
}

private String buildUserProfileConfigurationString(RealmImport realmImport) {

var userProfile = new LinkedHashMap<String, Object>();
var userProfileAttributes = realmImport.getUserProfile();
if (userProfileAttributes == null || userProfileAttributes.isEmpty()) {
var userProfile = realmImport.getUserProfile();
if (userProfile == null || userProfile.isEmpty()) {
return null;
}

userProfile.put("attributes", userProfileAttributes);
return JsonUtil.toJson(userProfile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ void shouldUpdateRealm() throws IOException {

assertThat(configurationNode.at("/attributes/0/name").asText(), is("username"));
assertThat(configurationNode.at("/attributes/0/validations/length/min").asInt(), is(5));
assertThat(configurationNode.at("/attributes/1/name").asText(), is("email"));
assertThat(configurationNode.at("/attributes/1/group").asText(), is("user_informations"));
assertThat(configurationNode.at("/groups/0/name").asText(), is("user_informations"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,76 @@
{
"enabled": true,
"realm": "realmWithProfile",
"userProfile": [
{
"name": "username",
"displayName": "${username}",
"validations": {
"length": {
"min": 1,
"max": 20
},
"username-prohibited-characters": {}
}
},
{
"name": "email",
"displayName": "${email}",
"validations": {
"email": {},
"length": {
"max": 255
"userProfile": {
"attributes": [
{
"name": "username",
"displayName": "${username}",
"validations": {
"length": {
"min": 1,
"max": 20
},
"username-prohibited-characters": {}
}
}
},
{
"name": "firstName",
"displayName": "${firstName}",
"required": {
"roles": [
"user"
]
},
"permissions": {
"view": [
"admin",
"user"
],
"edit": [
"admin"
]
{
"name": "email",
"displayName": "${email}",
"validations": {
"email": {},
"length": {
"max": 255
}
}
},
"validations": {
"length": {
"max": 169
{
"name": "firstName",
"displayName": "${firstName}",
"required": {
"roles": [
"user"
]
},
"person-name-prohibited-characters": {}
}
},
{
"name": "lastName",
"displayName": "${lastName}",
"required": {
"roles": [
"user"
]
},
"permissions": {
"view": [
"user"
],
"edit": [
"admin"
]
"permissions": {
"view": [
"admin",
"user"
],
"edit": [
"admin"
]
},
"validations": {
"length": {
"max": 169
},
"person-name-prohibited-characters": {}
}
},
"validations": {
"length": {
"max": 238
{
"name": "lastName",
"displayName": "${lastName}",
"required": {
"roles": [
"user"
]
},
"person-name-prohibited-characters": {}
"permissions": {
"view": [
"user"
],
"edit": [
"admin"
]
},
"validations": {
"length": {
"max": 238
},
"person-name-prohibited-characters": {}
}
}
}
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,76 @@
"attributes": {
"userProfileEnabled": true
},
"userProfile": [
{
"name": "username",
"displayName": "${username}",
"validations": {
"length": {
"min": 1,
"max": 20
},
"username-prohibited-characters": {}
}
},
{
"name": "email",
"displayName": "${email}",
"validations": {
"email": {},
"length": {
"max": 255
"userProfile": {
"attributes": [
{
"name": "username",
"displayName": "${username}",
"validations": {
"length": {
"min": 1,
"max": 20
},
"username-prohibited-characters": {}
}
}
},
{
"name": "firstName",
"displayName": "${firstName}",
"required": {
"roles": [
"user"
]
},
"permissions": {
"view": [
"admin",
"user"
],
"edit": [
"admin"
]
{
"name": "email",
"displayName": "${email}",
"validations": {
"email": {},
"length": {
"max": 255
}
}
},
"validations": {
"length": {
"max": 169
{
"name": "firstName",
"displayName": "${firstName}",
"required": {
"roles": [
"user"
]
},
"person-name-prohibited-characters": {}
}
},
{
"name": "lastName",
"displayName": "${lastName}",
"required": {
"roles": [
"user"
]
},
"permissions": {
"view": [
"user"
],
"edit": [
"admin"
]
"permissions": {
"view": [
"admin",
"user"
],
"edit": [
"admin"
]
},
"validations": {
"length": {
"max": 169
},
"person-name-prohibited-characters": {}
}
},
"validations": {
"length": {
"max": 238
{
"name": "lastName",
"displayName": "${lastName}",
"required": {
"roles": [
"user"
]
},
"person-name-prohibited-characters": {}
"permissions": {
"view": [
"user"
],
"edit": [
"admin"
]
},
"validations": {
"length": {
"max": 238
},
"person-name-prohibited-characters": {}
}
}
}
]
]
}
}
Loading

0 comments on commit 34fe17f

Please sign in to comment.