Skip to content

Commit

Permalink
Fix currentUser name
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbonte21 committed Dec 4, 2023
1 parent 25f7c05 commit 744bb61
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.janusgraph.graphdb.util.CollectionsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class AtlasAuthorization {

Expand Down Expand Up @@ -450,7 +452,8 @@ private static List<RangerPolicy> getRelevantPolicies(String persona, String pur
policyQualifiedNamePrefix = purpose;
}

String user = RequestContext.getCurrentUser();
//String user = RequestContext.getCurrentUser();
String user = getCurrentUserName();
LOG.info("Getting relevant policies for user: {}", user);

RangerUserStore userStore = usersGroupsRolesStore.getUserStore();
Expand Down Expand Up @@ -819,7 +822,7 @@ public Map<String, Object> getIndexsearchPreFilterDSL(String persona, String pur
RangerUserStore userStore = usersGroupsRolesStore.getUserStore();
RangerRoles allRoles = usersGroupsRolesStore.getAllRoles();

String user = RequestContext.getCurrentUser();
String user = getCurrentUserName();
Map<String, Set<String>> userGroupMapping = userStore.getUserGroupMapping();
List<String> groups = new ArrayList<>();
Set<String> groupsSet = userGroupMapping.get(user);
Expand Down Expand Up @@ -1407,4 +1410,10 @@ private List<String> getPolicyDSLArray(List<String> policyFilterCriteriaArray) {
// return shouldClauseList;
// }

public static String getCurrentUserName() {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();

return auth != null ? auth.getName() : "";
}

}

0 comments on commit 744bb61

Please sign in to comment.