-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Update role based sync #298
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,21 +18,16 @@ | |
*/ | ||
package org.geonetwork.security.external.integration; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.function.Supplier; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.Stream; | ||
|
||
import org.fao.geonet.domain.Group; | ||
import org.fao.geonet.domain.Profile; | ||
import org.geonetwork.security.external.configuration.ExternalizedSecurityProperties; | ||
import org.geonetwork.security.external.configuration.ProfileMappingProperties; | ||
import org.geonetwork.security.external.model.CanonicalGroup; | ||
import org.geonetwork.security.external.model.CanonicalUser; | ||
import org.geonetwork.security.external.model.GroupLink; | ||
|
@@ -42,10 +37,15 @@ | |
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import static java.util.Objects.*; | ||
|
||
public class RolesBasedGroupSynchronizer extends AbstractGroupSynchronizer { | ||
|
||
public static final Logger log = LoggerFactory.getLogger(RolesBasedGroupSynchronizer.class.getPackage().getName()); | ||
|
||
static final Set<String> georchestraDefaultRoleNames = Set.of("SUPERUSER","ORGADMIN","MAPSTORE_ADMIN","REFERENT","EMAILPROXY", | ||
"ADMINISTRATOR", "IMPORT", "USER", "GN_EDITOR", "GN_REVIEWER", "GN_ADMIN"); | ||
|
||
@Autowired | ||
public ExternalizedSecurityProperties config; | ||
|
||
|
@@ -71,7 +71,7 @@ public RolesBasedGroupSynchronizer(CanonicalAccountsRepository canonicalAccounts | |
*/ | ||
public @Override List<CanonicalGroup> fetchCanonicalGroups() { | ||
List<CanonicalGroup> roles = canonicalAccounts.findAllRoles(); | ||
Stream<CanonicalGroup> matches = roles.stream().filter(this::matchesRoleNameFilter); | ||
Stream<CanonicalGroup> matches = roles.stream().filter(this::notMatchesGeorchestraDefaultRoleNameFilter).filter(this::matchesRoleNameFilter); | ||
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. s/notMatches/noMatches/ or doesNotMatch... ? 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. I was tired 😄 doesNotMatch is better, I fix this |
||
return matches.map(this::renameRoleUsingConfigPattern).collect(Collectors.toList()); | ||
} | ||
|
||
|
@@ -92,7 +92,7 @@ private CanonicalGroup renameRoleUsingConfigPattern(CanonicalGroup role) { | |
} | ||
|
||
protected @Override List<CanonicalGroup> resolveGroupsOf(CanonicalUser user) { | ||
Stream<String> roleNames = user.getRoles().stream().filter(config::matchesRoleNameFilter); | ||
Stream<String> roleNames = user.getRoles().stream().filter(this::notMatchesGeorchestraDefaultRoleNameFilter).filter(config::matchesRoleNameFilter); | ||
|
||
Stream<CanonicalGroup> roleGroups = roleNames.map(role -> this.externalGroupLinks.findByName(role)// | ||
.map(GroupLink::getCanonical)// | ||
|
@@ -103,15 +103,6 @@ private CanonicalGroup renameRoleUsingConfigPattern(CanonicalGroup role) { | |
return roleGroups.collect(Collectors.toList()); | ||
} | ||
|
||
protected @Override Privilege resolvePrivilegeFor(CanonicalUser user, Group groupFromRole) { | ||
final String roleName = groupFromRole.getName(); | ||
|
||
ProfileMappingProperties profileMappings = configProperties.getProfiles(); | ||
Profile profile = profileMappings.resolveHighestProfileFromRoleNames(Collections.singletonList(roleName)); | ||
|
||
return new Privilege(groupFromRole, profile); | ||
} | ||
|
||
private Supplier<? extends IllegalArgumentException> notFound(String role) { | ||
return () -> new IllegalArgumentException("Role " + role + " not found in internal or external repository"); | ||
} | ||
|
@@ -123,4 +114,14 @@ private boolean matchesRoleNameFilter(CanonicalGroup role) { | |
return config.matchesRoleNameFilter(name); | ||
} | ||
|
||
private boolean notMatchesGeorchestraDefaultRoleNameFilter(String roleName) { | ||
requireNonNull(roleName); | ||
return !georchestraDefaultRoleNames.contains(roleName); | ||
} | ||
|
||
private boolean notMatchesGeorchestraDefaultRoleNameFilter(CanonicalGroup role) { | ||
requireNonNull(role); | ||
return notMatchesGeorchestraDefaultRoleNameFilter(role.getName()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd have expected that such a set would have been defined somewhere into georchestra/georchestra (ldap-account-mgmt, georchestra-commons, or security-proxy-spring-integration), but it does not look like it's actually the case, so, fine
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.
there's https://github.com/georchestra/datadir/blob/master/console/protectedroles.properties ... but so far only used by the console. So that would be two lists to sync ? or move those to default.properties ?
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.
I think such a constant should be defined into one of the shared geOrchestra libraries across components, but this is another topic (georchestra/georchestra#4031) ; here, since we already are into a GN module specific to geOrchestra, I think it's fine to leave it as it is.