Commit 3725dcf1 by saqeeb.shaikh Committed by Madhan Neethiraj

ATLAS-1350: update authorization to handle v2 REST endpoints

parent ec1b160a
...@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; ...@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
public class AtlasAuthorizationUtils { public class AtlasAuthorizationUtils {
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthorizationUtils.class); private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthorizationUtils.class);
...@@ -46,18 +47,13 @@ public class AtlasAuthorizationUtils { ...@@ -46,18 +47,13 @@ public class AtlasAuthorizationUtils {
} }
} }
String[] split = contextPath.split("/", 3); String[] split = contextPath.split("/", 3);
String api = split[0]; String api = split[0];
if (split.length > 1) { if(Pattern.matches("v\\d", api)) {
if (Objects.equals(api, "v1")) { api = split[1];
return String.format("v1/%s", split[1]);
} else if (Objects.equals(api, "v2")) {
return String.format("v2/%s", split[1]);
} else {
return api;
}
} else {
return api;
} }
LOG.info("Now returning API : "+api);
return api;
} }
public static AtlasActionTypes getAtlasAction(String method) { public static AtlasActionTypes getAtlasAction(String method) {
...@@ -100,6 +96,9 @@ public class AtlasAuthorizationUtils { ...@@ -100,6 +96,9 @@ public class AtlasAuthorizationUtils {
* entities,lineage and discovery apis are mapped with AtlasResourceTypes.ENTITY eg :- /api/atlas/lineage/hive/table/* * entities,lineage and discovery apis are mapped with AtlasResourceTypes.ENTITY eg :- /api/atlas/lineage/hive/table/*
* /api/atlas/entities/{guid}* /api/atlas/discovery/* * /api/atlas/entities/{guid}* /api/atlas/discovery/*
* *
* taxonomy API are also mapped to AtlasResourceTypes.TAXONOMY & AtlasResourceTypes.ENTITY and its terms APIs have
* added AtlasResourceTypes.TERM associations.
*
* unprotected types are mapped with AtlasResourceTypes.UNKNOWN, access to these are allowed. * unprotected types are mapped with AtlasResourceTypes.UNKNOWN, access to these are allowed.
*/ */
public static Set<AtlasResourceTypes> getAtlasResourceType(String contextPath) { public static Set<AtlasResourceTypes> getAtlasResourceType(String contextPath) {
...@@ -108,33 +107,31 @@ public class AtlasAuthorizationUtils { ...@@ -108,33 +107,31 @@ public class AtlasAuthorizationUtils {
LOG.debug("==> getAtlasResourceType for " + contextPath); LOG.debug("==> getAtlasResourceType for " + contextPath);
} }
String api = getApi(contextPath); String api = getApi(contextPath);
if (api.startsWith("types") || api.startsWith("v2/types")) { if (api.startsWith("types")) {
resourceTypes.add(AtlasResourceTypes.TYPE); resourceTypes.add(AtlasResourceTypes.TYPE);
} else if (api.startsWith("admin") && (contextPath.contains("/session") || contextPath.contains("/version"))) { } else if (api.startsWith("admin") && (contextPath.contains("/session") || contextPath.contains("/version"))) {
resourceTypes.add(AtlasResourceTypes.UNKNOWN); resourceTypes.add(AtlasResourceTypes.UNKNOWN);
} else if ((api.startsWith("discovery") && contextPath.contains("/gremlin")) || api.startsWith("admin") } else if ((api.startsWith("discovery") && contextPath.contains("/gremlin")) || api.startsWith("admin")
|| api.startsWith("graph")) { || api.startsWith("graph")) {
resourceTypes.add(AtlasResourceTypes.OPERATION); resourceTypes.add(AtlasResourceTypes.OPERATION);
} else if (api.startsWith("entities") || api.startsWith("lineage") || } else if (api.startsWith("entities") || api.startsWith("lineage") ||
api.startsWith("discovery") || api.startsWith("v2/entity")) { api.startsWith("discovery") || api.startsWith("entity")) {
resourceTypes.add(AtlasResourceTypes.ENTITY); resourceTypes.add(AtlasResourceTypes.ENTITY);
} else if (api.startsWith("v1/taxonomies")) { } else if (api.startsWith("taxonomies")) {
resourceTypes.add(AtlasResourceTypes.TAXONOMY); resourceTypes.add(AtlasResourceTypes.TAXONOMY);
// taxonomies are modeled as entities // taxonomies are modeled as entities
resourceTypes.add(AtlasResourceTypes.ENTITY); resourceTypes.add(AtlasResourceTypes.ENTITY);
if (contextPath.contains("/terms")) { if (contextPath.contains("/terms")) {
resourceTypes.add(AtlasResourceTypes.TERM); resourceTypes.add(AtlasResourceTypes.TERM);
} }
} else if (api.startsWith("v1/entities") || api.startsWith("v2/entities")) {
resourceTypes.add(AtlasResourceTypes.ENTITY);
} else { } else {
LOG.error("Unable to find Atlas Resource corresponding to : " + api + "\nSetting " LOG.error("Unable to find Atlas Resource corresponding to : " + api + "\nSetting "
+ AtlasResourceTypes.UNKNOWN.name()); + AtlasResourceTypes.UNKNOWN.name());
resourceTypes.add(AtlasResourceTypes.UNKNOWN); resourceTypes.add(AtlasResourceTypes.UNKNOWN);
} }
if (isDebugEnabled) { if (isDebugEnabled) {
LOG.debug("<== Returning AtlasResources " + resourceTypes + " for api " + api); LOG.debug("<== Returning AtlasResource/s " + resourceTypes + " for api " + api);
} }
return resourceTypes; return resourceTypes;
} }
......
...@@ -39,10 +39,10 @@ public class AtlasAuthorizationUtilsTest { ...@@ -39,10 +39,10 @@ public class AtlasAuthorizationUtilsTest {
assertEquals(AtlasAuthorizationUtils.getApi(contextPath), "entities"); assertEquals(AtlasAuthorizationUtils.getApi(contextPath), "entities");
contextPath = "/api/atlas/v1/entities"; contextPath = "/api/atlas/v1/entities";
assertEquals(AtlasAuthorizationUtils.getApi(contextPath), "v1/entities"); assertEquals(AtlasAuthorizationUtils.getApi(contextPath), "entities");
contextPath = "/api/atlas/v1/entities/111/tags"; contextPath = "/api/atlas/v1/entities/111/tags";
assertEquals(AtlasAuthorizationUtils.getApi(contextPath), "v1/entities"); assertEquals(AtlasAuthorizationUtils.getApi(contextPath), "entities");
// not sure of this use case but the code appears to support url's that don't // not sure of this use case but the code appears to support url's that don't
// begin with base url. // begin with base url.
......
...@@ -9,6 +9,9 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,6 +9,9 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1350 update authorization to handle v2 REST endpoints (saqeeb.s via mneethiraj)
ATLAS-1311 Integration tests for V2 Entity APIs (apoorvnaik via mneethiraj)
ATLAS-1377 fix for Escaping comma in for LDAP properties (nixonrodrigues via mneethiraj)
ATLAS-1367 fix to use correct version of curator-client library (mneethiraj) ATLAS-1367 fix to use correct version of curator-client library (mneethiraj)
ATLAS-1371 create/edit tag dialog to allow choosing of data-type for attributes (Kalyanikashikar via mneethiraj) ATLAS-1371 create/edit tag dialog to allow choosing of data-type for attributes (Kalyanikashikar via mneethiraj)
ATLAS-1395 Lineage improvement for tooltip (kevalbhatt via mneethiraj) ATLAS-1395 Lineage improvement for tooltip (kevalbhatt via mneethiraj)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment