/** * Reads authorization (@requires/@restrict) details of the given service/entity * name from CSN.json. * * @throws IllegalArgumentException - If conversion fails due to incompatible * type; check CSN.json and * AuthorizationDetails- class. * @param serviceOrEntityName * @return AuthorizationDetails if found. Else returns null. */ public static AuthorizationDetails getAuthorizationDetails(String serviceOrEntityName) { JsonNode csn = getCsn(); if (csn != null) { JsonNode entityNode = csn.get("definitions").get(serviceOrEntityName); if (entityNode != null) { return getAuthorizationDetails(entityNode); } } return null; }
/** * Reads the rule on-demand from CSN.json and builds it in local data store. * Based on availability of the rule returns value. * * @param serviceOrEntityName the OData service name / entity name. * @return true if rule found for given service/entity name. */ public static boolean isRuleExist(String serviceOrEntityName) { init(); if(servicesAndEntitiesWithoutAuthRule.contains(serviceOrEntityName)) { return false; }else if (authorizationDefinition.containsKey(serviceOrEntityName)) { return true; } else { AuthorizationDetails authDetails = CSNUtil.getAuthorizationDetails(serviceOrEntityName); if (authDetails != null && (null != authDetails.getRequires() || null != authDetails.getRestrict())) { authorizationDefinition.put(serviceOrEntityName, authDetails); return true; } servicesAndEntitiesWithoutAuthRule.add(serviceOrEntityName); } return false; }