Skip to content
Snippets Groups Projects
Verified Commit 76ce6903 authored by Dominik Frantisek Bucik's avatar Dominik Frantisek Bucik
Browse files

feat: :guitar: filtering of groups in access control filter

AccessControl filter (PerunAuthorizationFilter) now support specifying
a resource attribute, which if set and non-null on Resource object,
groups from this resource will not be considered for controlling access.
parent 7f1cf4c5
No related branches found
No related tags found
1 merge request!396feat+refactor: filtering of assigned resource groups in entitlements, filtering of groups in access control filter, refactor PerunRPC Adapter
...@@ -86,11 +86,12 @@ public interface PerunAdapterMethods { ...@@ -86,11 +86,12 @@ public interface PerunAdapterMethods {
* Perform check if user can access service based on his/her membership * Perform check if user can access service based on his/her membership
* in groups assigned to facility resources * in groups assigned to facility resources
* *
* @param facility Facility object * @param facility Facility object
* @param userId ID of user * @param userId ID of user
* @param accessControlDisabledAttr
* @return TRUE if user can access, FALSE otherwise * @return TRUE if user can access, FALSE otherwise
*/ */
boolean canUserAccessBasedOnMembership(Facility facility, Long userId); boolean canUserAccessBasedOnMembership(Facility facility, Long userId, String accessControlDisabledAttr);
/** /**
* Fetch facility attribute values * Fetch facility attribute values
......
...@@ -62,12 +62,12 @@ public class PerunAdapterImpl extends PerunAdapter { ...@@ -62,12 +62,12 @@ public class PerunAdapterImpl extends PerunAdapter {
} }
@Override @Override
public boolean canUserAccessBasedOnMembership(Facility facility, Long userId) { public boolean canUserAccessBasedOnMembership(Facility facility, Long userId, String accessControlDisabledAttr) {
try { try {
return this.getAdapterPrimary().canUserAccessBasedOnMembership(facility, userId); return this.getAdapterPrimary().canUserAccessBasedOnMembership(facility, userId, accessControlDisabledAttr);
} catch (UnsupportedOperationException e) { } catch (UnsupportedOperationException e) {
if (this.isCallFallback()) { if (this.isCallFallback()) {
return this.getAdapterFallback().canUserAccessBasedOnMembership(facility, userId); return this.getAdapterFallback().canUserAccessBasedOnMembership(facility, userId, accessControlDisabledAttr);
} else { } else {
throw e; throw e;
} }
......
...@@ -142,14 +142,14 @@ public class PerunAdapterLdap extends PerunAdapterWithMappingServices implements ...@@ -142,14 +142,14 @@ public class PerunAdapterLdap extends PerunAdapterWithMappingServices implements
} }
@Override @Override
public boolean canUserAccessBasedOnMembership(Facility facility, Long userId) { public boolean canUserAccessBasedOnMembership(Facility facility, Long userId, String accessControlDisabledAttr) {
Set<Long> groupsWithAccessIds = getGroupIdsAssignedToFacility(facility.getId(), null); Set<Long> groupsWithAccessIds = getGroupIdsAssignedToFacility(facility.getId(), accessControlDisabledAttr);
if (groupsWithAccessIds == null || groupsWithAccessIds.isEmpty()) { if (groupsWithAccessIds == null || groupsWithAccessIds.isEmpty()) {
return false; return false;
} }
Set<Long> userGroupIds = getGroupIdsWhereUserIsMember(userId, null); Set<Long> userGroupIds = getGroupIdsWhereUserIsMember(userId, null);
if (userGroupIds == null || userGroupIds.isEmpty()) { if (userGroupIds.isEmpty()) {
return false; return false;
} }
......
...@@ -132,12 +132,12 @@ public class PerunAdapterRpc extends PerunAdapterWithMappingServices implements ...@@ -132,12 +132,12 @@ public class PerunAdapterRpc extends PerunAdapterWithMappingServices implements
} }
@Override @Override
public boolean canUserAccessBasedOnMembership(Facility facility, Long userId) { public boolean canUserAccessBasedOnMembership(Facility facility, Long userId, String ignoreAttr) {
if (!this.connectorRpc.isEnabled()) { if (!this.connectorRpc.isEnabled()) {
return true; return true;
} }
List<Group> activeGroups = getGroupsWhereUserIsActiveByFacility(facility.getId(), userId); Set<Group> activeGroups = getGroupsWhereUserIsActive(facility.getId(), userId, ignoreAttr);
return !activeGroups.isEmpty(); return !activeGroups.isEmpty();
} }
...@@ -1002,6 +1002,19 @@ public class PerunAdapterRpc extends PerunAdapterWithMappingServices implements ...@@ -1002,6 +1002,19 @@ public class PerunAdapterRpc extends PerunAdapterWithMappingServices implements
return groups; return groups;
} }
private Set<Group> getGroupsWhereUserIsActiveByFacility(Long facilityId, Long userId) {
if (!this.connectorRpc.isEnabled()) {
return new HashSet<>();
}
Map<String, Object> map = new LinkedHashMap<>();
map.put("facility", facilityId);
map.put("user", userId);
JsonNode jsonNode = connectorRpc.post(USERS_MANAGER, "getGroupsWhereUserIsActive", map);
return new HashSet<>(RpcMapper.mapGroups(jsonNode));
}
private Set<Resource> getResourcesAssignedToFacility(Long facilityId, Long userId, String ignoreAttribute) { private Set<Resource> getResourcesAssignedToFacility(Long facilityId, Long userId, String ignoreAttribute) {
if (!this.connectorRpc.isEnabled()) { if (!this.connectorRpc.isEnabled()) {
return new HashSet<>(); return new HashSet<>();
...@@ -1010,7 +1023,7 @@ public class PerunAdapterRpc extends PerunAdapterWithMappingServices implements ...@@ -1010,7 +1023,7 @@ public class PerunAdapterRpc extends PerunAdapterWithMappingServices implements
Set<Resource> result = new HashSet<>(); Set<Resource> result = new HashSet<>();
for (Resource resource : resources) { for (Resource resource : resources) {
PerunAttributeValue attrValue = getResourceAttributeValue(resource.getId(), ignoreAttribute); PerunAttributeValue attrValue = getResourceAttributeValue(resource.getId(), ignoreAttribute);
if (attrValue == null || attrValue.isNullValue()) { if (attrValue == null || attrValue.isNullValue() || !attrValue.valueAsBoolean()) {
result.add(resource); result.add(resource);
} else { } else {
log.debug( log.debug(
...@@ -1251,19 +1264,6 @@ public class PerunAdapterRpc extends PerunAdapterWithMappingServices implements ...@@ -1251,19 +1264,6 @@ public class PerunAdapterRpc extends PerunAdapterWithMappingServices implements
return true; return true;
} }
private List<Group> getGroupsWhereUserIsActiveByFacility(Long facilityId, Long userId) {
if (!this.connectorRpc.isEnabled()) {
return new ArrayList<>();
}
Map<String, Object> map = new LinkedHashMap<>();
map.put("facility", facilityId);
map.put("user", userId);
JsonNode jsonNode = connectorRpc.post(USERS_MANAGER, "getGroupsWhereUserIsActive", map);
return RpcMapper.mapGroups(jsonNode);
}
private Map<Long, Vo> convertVoListToMap(List<Vo> vos) { private Map<Long, Vo> convertVoListToMap(List<Vo> vos) {
if (!this.connectorRpc.isEnabled()) { if (!this.connectorRpc.isEnabled()) {
return new HashMap<>(); return new HashMap<>();
......
...@@ -31,6 +31,11 @@ import static cz.muni.ics.openid.connect.request.ConnectRequestParameters.STATE; ...@@ -31,6 +31,11 @@ import static cz.muni.ics.openid.connect.request.ConnectRequestParameters.STATE;
* *
* Configuration: * Configuration:
* - based on the configuration of bean "facilityAttrsConfig" * - based on the configuration of bean "facilityAttrsConfig"
* Configuration of filter (replace [name] part with the name defined for the filter):
* <ul>
* <li><b>filter.[name].accessControlDisabledAttr</b> - resource attribute which triggers if resource assigned
* groups should not be used for controlling access. When not specified, all groups will be used.</li>
* </ul>
* @see FacilityAttrsConfig * @see FacilityAttrsConfig
* @see cz.muni.ics.oidc.server.filters.AuthProcFilter (basic configuration options) * @see cz.muni.ics.oidc.server.filters.AuthProcFilter (basic configuration options)
* *
...@@ -39,15 +44,19 @@ import static cz.muni.ics.openid.connect.request.ConnectRequestParameters.STATE; ...@@ -39,15 +44,19 @@ import static cz.muni.ics.openid.connect.request.ConnectRequestParameters.STATE;
@Slf4j @Slf4j
public class PerunAuthorizationFilter extends AuthProcFilter { public class PerunAuthorizationFilter extends AuthProcFilter {
protected static final String ACCESS_CONTROL_DISABLED_ATTR = "accessControlDisabledAttr";
private final PerunAdapter perunAdapter; private final PerunAdapter perunAdapter;
private final FacilityAttrsConfig facilityAttrsConfig; private final FacilityAttrsConfig facilityAttrsConfig;
private final PerunOidcConfig config; private final PerunOidcConfig config;
private final String accessControlDisabledAttr;
public PerunAuthorizationFilter(AuthProcFilterInitContext ctx) throws ConfigurationException { public PerunAuthorizationFilter(AuthProcFilterInitContext ctx) throws ConfigurationException {
super(ctx); super(ctx);
this.perunAdapter = ctx.getPerunAdapterBean(); this.perunAdapter = ctx.getPerunAdapterBean();
this.config = ctx.getPerunOidcConfigBean(); this.config = ctx.getPerunOidcConfigBean();
this.facilityAttrsConfig = ctx.getBeanUtil().getBean(FacilityAttrsConfig.class); this.facilityAttrsConfig = ctx.getBeanUtil().getBean(FacilityAttrsConfig.class);
this.accessControlDisabledAttr = ctx.getProperty(ACCESS_CONTROL_DISABLED_ATTR, null);
} }
@Override @Override
...@@ -65,7 +74,7 @@ public class PerunAuthorizationFilter extends AuthProcFilter { ...@@ -65,7 +74,7 @@ public class PerunAuthorizationFilter extends AuthProcFilter {
} }
return this.decideAccess(facility, user, req, res, params.getClientIdentifier(), return this.decideAccess(facility, user, req, res, params.getClientIdentifier(),
perunAdapter, facilityAttrsConfig); perunAdapter, facilityAttrsConfig, accessControlDisabledAttr);
} }
@Override @Override
...@@ -73,9 +82,14 @@ public class PerunAuthorizationFilter extends AuthProcFilter { ...@@ -73,9 +82,14 @@ public class PerunAuthorizationFilter extends AuthProcFilter {
return false; return false;
} }
private boolean decideAccess(Facility facility, PerunUser user, HttpServletRequest req, private boolean decideAccess(Facility facility,
HttpServletResponse response, String clientIdentifier, PerunAdapter perunAdapter, PerunUser user,
FacilityAttrsConfig facilityAttrsConfig) HttpServletRequest req,
HttpServletResponse response,
String clientIdentifier,
PerunAdapter perunAdapter,
FacilityAttrsConfig facilityAttrsConfig,
String accessControlDisabledAttr)
{ {
Map<String, PerunAttributeValue> facilityAttributes = perunAdapter.getFacilityAttributeValues( Map<String, PerunAttributeValue> facilityAttributes = perunAdapter.getFacilityAttributeValues(
facility, facilityAttrsConfig.getMembershipAttrNames()); facility, facilityAttrsConfig.getMembershipAttrNames());
...@@ -85,7 +99,7 @@ public class PerunAuthorizationFilter extends AuthProcFilter { ...@@ -85,7 +99,7 @@ public class PerunAuthorizationFilter extends AuthProcFilter {
return true; return true;
} }
if (perunAdapter.canUserAccessBasedOnMembership(facility, user.getId())) { if (perunAdapter.canUserAccessBasedOnMembership(facility, user.getId(), accessControlDisabledAttr)) {
log.info("{} - user allowed to access the service", getFilterName()); log.info("{} - user allowed to access the service", getFilterName());
return true; return true;
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment