AtlasAuthorizationUtils { public static Set<AtlasResourceTypes> getAtlasResourceType(String contextPath) { Set<AtlasResourceTypes> resourceTypes = new HashSet<>(); if (isDebugEnabled) { LOG.debug("==> getAtlasResourceType for {}", contextPath); } String api = getApi(contextPath); if (api.startsWith("types")) { resourceTypes.add(AtlasResourceTypes.TYPE); } else if (api.startsWith("admin") && (contextPath.contains("/session") || contextPath.contains("/version"))) { resourceTypes.add(AtlasResourceTypes.UNKNOWN); } else if ((api.startsWith("discovery") && contextPath.contains("/gremlin")) || api.startsWith("admin") || api.startsWith("graph")) { resourceTypes.add(AtlasResourceTypes.OPERATION); } else if (api.startsWith("entities") || api.startsWith("lineage") || api.startsWith("discovery") || api.startsWith("entity") || api.startsWith("search")) { resourceTypes.add(AtlasResourceTypes.ENTITY); } else if (api.startsWith("taxonomies")) { resourceTypes.add(AtlasResourceTypes.TAXONOMY); resourceTypes.add(AtlasResourceTypes.ENTITY); if (contextPath.contains("/terms")) { resourceTypes.add(AtlasResourceTypes.TERM); } } else if (api.startsWith("relationship")) { resourceTypes.add(AtlasResourceTypes.RELATIONSHIP); } else { LOG.error("Unable to find Atlas Resource corresponding to : {}\nSetting {}" , api, AtlasResourceTypes.UNKNOWN.name()); resourceTypes.add(AtlasResourceTypes.UNKNOWN); } if (isDebugEnabled) { LOG.debug("<== Returning AtlasResources {} for api {}", resourceTypes, api); } return resourceTypes; }  static String getApi(String contextPath); static AtlasActionTypes getAtlasAction(String method); static Set<AtlasResourceTypes> getAtlasResourceType(String contextPath); static boolean isAccessAllowed(AtlasResourceTypes resourcetype, AtlasActionTypes actionType, String userName, Set<String> groups, HttpServletRequest request); static String getRequestIpAddress(HttpServletRequest httpServletRequest);  }
@Test public void testGetAtlasResourceType() throws Exception { String contextPath = "/api/atlas/types"; Set<AtlasResourceTypes> resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.TYPE)); contextPath = "/api/atlas/admin/foo"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.OPERATION)); contextPath = "/api/atlas/graph/foo"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.OPERATION)); contextPath = "/api/atlas/discovery/search/gremlin"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.OPERATION)); contextPath = "/api/atlas/entities/111/traits"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.ENTITY)); contextPath = "/api/atlas/discovery/search"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.ENTITY)); contextPath = "/api/atlas/entities?type=Column"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.ENTITY)); contextPath = "/api/atlas/lineage"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.ENTITY)); contextPath = "/api/atlas/v1/taxonomies"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 2); assertTrue(resourceTypes.contains(AtlasResourceTypes.TAXONOMY)); assertTrue(resourceTypes.contains(AtlasResourceTypes.ENTITY)); contextPath = "/api/atlas/v1/taxonomies/taxonomy1/terms"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 3); assertTrue(resourceTypes.contains(AtlasResourceTypes.TAXONOMY)); assertTrue(resourceTypes.contains(AtlasResourceTypes.ENTITY)); assertTrue(resourceTypes.contains(AtlasResourceTypes.TERM)); contextPath = "/api/atlas/v1/entities/111"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.ENTITY)); contextPath = "/api/atlas/v1/entities/111/tags/foo"; resourceTypes = AtlasAuthorizationUtils.getAtlasResourceType(contextPath); assertEquals(resourceTypes.size(), 1); assertTrue(resourceTypes.contains(AtlasResourceTypes.ENTITY)); }