-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support realm role attributes update #991
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ public RoleRepresentation getRealmRole(String realmName, String roleName) { | |
|
||
public List<RoleRepresentation> getRealmRoles(String realmName) { | ||
return realmRepository.getResource(realmName) | ||
.roles().list(); | ||
.roles().list(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any code that relies on the getRealmRoles method to retrieve a complete list of all roles (including composite ones) will now be affected. Do we know all consumers of this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getRealmRoles is used by only one method (RealmImportService :: doImport). |
||
} | ||
|
||
public List<RoleRepresentation> getRealmRolesByName(String realmName, Collection<String> roles) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
@@ -211,8 +212,21 @@ private void updateRoleIfNeeded( | |
) { | ||
String roleName = roleToImport.getName(); | ||
RoleRepresentation patchedRole = CloneUtil.patch(existingRole, roleToImport, propertiesWithDependencies); | ||
if (roleToImport.getAttributes() != null) { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like method does what it is supposed to. But we need tests to
How do we proceed for the removal of existing attributes. |
||
if (importConfigProperties.getManaged().getRole() == ImportConfigProperties.ImportManagedProperties.ImportManagedPropertiesValues.FULL | ||
&& roleToImport.getAttributes() != null) { | ||
logger.debug("Setting the attributes of the patched realm-level role as roleToImport attributes"); | ||
patchedRole.setAttributes(roleToImport.getAttributes()); | ||
} else { | ||
logger.debug("Setting the attributes of the patched realm-level role as a merge of roleToImport and existingRole"); | ||
Map<String, List<String>> attributes = new HashMap<>(); | ||
if (existingRole.getAttributes() != null) { | ||
attributes.putAll(existingRole.getAttributes()); | ||
} | ||
if (roleToImport.getAttributes() != null) { | ||
attributes.putAll(roleToImport.getAttributes()); | ||
} | ||
patchedRole.setAttributes(attributes); | ||
} | ||
|
||
if (!CloneUtil.deepEquals(existingRole, patchedRole)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this change the defaul behavior of the application? Do we have a backward compatibility issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even is we set full as the default value, how do change the value for existing deployments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I see it this change fixes a bug.
If I set the roles to be fully managed, then yes, I expect the data will be overridden.
I expect nothing will be deleted if I set the Roles with no-delete value.
Without this fix, there is data loss once the roles have no-delete managed configuration.