From 60dd0d81d6d3b9bbaefacfcad4f8e37b0b81b9c4 Mon Sep 17 00:00:00 2001 From: MatthieuBarbet Date: Sat, 8 Feb 2025 17:33:05 +0100 Subject: [PATCH] Fix: retrieve org if no org filter --- .../arlas/iam/impl/HibernateAuthService.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/arlas-iam-core/src/main/java/io/arlas/iam/impl/HibernateAuthService.java b/arlas-iam-core/src/main/java/io/arlas/iam/impl/HibernateAuthService.java index dabbc75..f69d70a 100644 --- a/arlas-iam-core/src/main/java/io/arlas/iam/impl/HibernateAuthService.java +++ b/arlas-iam-core/src/main/java/io/arlas/iam/impl/HibernateAuthService.java @@ -208,12 +208,18 @@ private Map> listRoles(Set roles, String orgFilter) { // (the empty key is for cross org roles such as "role/iam/admin") roles.forEach(r -> { String orgName = r.getOrganisation().map(Organisation::getName).orElse(NO_ORG); - // if no orgFilter, we only keep the roles associated to "no org" - if ((orgFilter == null && orgName.equals(NO_ORG)) - || orgName.equals(orgFilter)) { + // if no orgFilter, we keep all the roles + if(orgFilter == null){ List roleList = Optional.ofNullable(orgRoles.get(orgName)).orElseGet(ArrayList::new); roleList.add(r.getName()); orgRoles.put(orgName, roleList); + }else{ + // if orgFilter, we add only the roles of the org or no org + if(orgName.equals(orgFilter) || orgName.equals(NO_ORG)){ + List roleList = Optional.ofNullable(orgRoles.get(orgName)).orElseGet(ArrayList::new); + roleList.add(r.getName()); + orgRoles.put(orgName, roleList); + } } }); // manually add "group/public" which is given to everybody @@ -863,10 +869,14 @@ private Set listPermissions(Set roles, String orgFilter) { Set permissions = new HashSet<>(); roles.forEach(r -> { String orgName = r.getOrganisation().map(Organisation::getName).orElse(NO_ORG); - // if no orgFilter, we only keep the permissions associated to "no org" - if ((orgFilter == null && orgName.equals(NO_ORG)) - || orgName.equals(orgFilter)) { + // if no orgFilter, we add all the permissions + if(orgFilter == null){ permissions.addAll(r.getPermissions()); + }else{ + // if orgFilter, we add only the permissions of the org or no org + if(orgName.equals(orgFilter) || orgName.equals(NO_ORG)){ + permissions.addAll(r.getPermissions()); + } } });