Skip to content
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

Mapper instance should not be cached in the policy, as per comment #39

Merged
merged 1 commit into from Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -65,7 +65,7 @@ public boolean impliesByRole(Permission permissionToBeChecked, Subject subject)
// Note that these are obtained for the current (application) context ID, and this policy could potentially
// be used for multiple context IDs. Therefore these objects should not be cached as instance data of this policy.
PolicyConfiguration policyConfiguration = getPolicyConfigurationFactory().getPolicyConfiguration();
PrincipalMapper roleMapper = getRoleMapper();
PrincipalMapper roleMapper = PolicyContext.get(PRINCIPAL_MAPPER);

if (!roleMapper.isAnyAuthenticatedUserRoleMapped() && !subject.getPrincipals().isEmpty()) {
// The "any authenticated user" role is not mapped, so available to anyone and the current
Expand Down Expand Up @@ -93,7 +93,7 @@ public PermissionCollection getPermissionCollection(Subject subject) {
Permissions permissions = new Permissions();

PolicyConfiguration policyConfiguration = getPolicyConfigurationFactory().getPolicyConfiguration();
PrincipalMapper roleMapper = getRoleMapper();
PrincipalMapper roleMapper = PolicyContext.get(PRINCIPAL_MAPPER);

PermissionCollection excludedPermissions = policyConfiguration.getExcludedPermissions();

Expand Down Expand Up @@ -125,14 +125,6 @@ private PolicyConfigurationFactory getPolicyConfigurationFactory() {
return policyConfigurationFactory;
}

private PrincipalMapper getRoleMapper() {
if (principalMapper == null) {
principalMapper = PolicyContext.get(PRINCIPAL_MAPPER);
}

return principalMapper;
}

private boolean isExcluded(PermissionCollection excludedPermissions, Permission permission) {
if (excludedPermissions.implies(permission)) {
return true;
Expand Down