Skip to content

Commit

Permalink
Fix empty username auth
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilbonte21 committed Dec 4, 2023
1 parent 744bb61 commit f983800
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ private static Map<String, Object> getMap(String key, Object value) {
}

public static void verifyAccess(String guid, String action) throws AtlasBaseException {
String userName = getCurrentUserName();

if (StringUtils.isEmpty(userName) || RequestContext.get().isImportInProgress()) {
return;
}

try {
if (!isAccessAllowed(guid, action)) {
throw new AtlasBaseException(AtlasErrorCode.UNAUTHORIZED_ACCESS, RequestContext.getCurrentUser(), guid);
Expand All @@ -116,6 +122,12 @@ public static void verifyAccess(String guid, String action) throws AtlasBaseExce
}

public static void verifyAccess(AtlasEntity entity, AtlasPrivilege action, String message) throws AtlasBaseException {
String userName = getCurrentUserName();

if (StringUtils.isEmpty(userName) || RequestContext.get().isImportInProgress()) {
return;
}

try {
if (AtlasPrivilege.ENTITY_CREATE == action) {
if (!isCreateAccessAllowed(entity, AtlasPrivilege.ENTITY_CREATE.getType())){
Expand Down Expand Up @@ -152,16 +164,6 @@ private static boolean isAccessAllowed(String guid, String action) throws AtlasB
return false;
}

public static void verifyAccess(String entityTypeName, String entityQualifiedName, String action) throws AtlasBaseException {
try {
if (!isAccessAllowed(entityTypeName, entityQualifiedName, action)) {
throw new AtlasBaseException(AtlasErrorCode.UNAUTHORIZED_ACCESS, RequestContext.getCurrentUser(), "Unauthorised");
}
} catch (AtlasBaseException e) {
throw e;
}
}

private static boolean isAccessAllowed(String entityTypeName, String entityQualifiedName, String action) throws AtlasBaseException {
List<Map<String, Object>> filterClauseList = new ArrayList<>();
Map<String, Object> policiesDSL = getElasticsearchDSL(null, null, Arrays.asList(action));
Expand Down

0 comments on commit f983800

Please sign in to comment.