private static void permissionPath(Registry tenantGovReg, String permissionPath) throws RegistryException { Collection appCollection = (Collection) tenantGovReg.get(permissionPath); String[] childern = appCollection.getChildren(); if (childern == null || childern.length == 0) { paths.add(permissionPath.replace(applicationNode, "").substring(2)); } while (childern != null && childern.length != 0) { for (int i = 0; i < childern.length; i++) { permissionPath(tenantGovReg, childern[i]); } break; } }
private static void addPermission(ApplicationPermission[] permissions, Registry tenantGovReg) throws RegistryException { for (ApplicationPermission permission : permissions) { String permissionValue = permission.getValue(); if ("/".equals(permissionValue.substring(0, 1))) { //if permissions are starts with slash remove that permissionValue = permissionValue.substring(1); } String[] splitedPermission = permissionValue.split("/"); String permissinPath = applicationNode + PATH_CONSTANT; for (int i = 0; i < splitedPermission.length; i++) { permissinPath = permissinPath + splitedPermission[i] + PATH_CONSTANT; Collection permissionNode = tenantGovReg.newCollection(); permissionNode.setProperty("name", splitedPermission[i]); tenantGovReg.put(permissinPath, permissionNode); } } }
if (!exist) { Collection appRootNode = tenantGovReg.newCollection(); appRootNode.setProperty("name", applicationName); tenantGovReg.put(applicationNode, appRootNode); String[] childern = appNodeCollec.getChildren(); if (childern == null || appNodeCollec.getChildCount() < 1) {
version = collection.getProperty("version"); } else { collection = registry.newCollection(); collection.setProperty("version", "1"); registry.put(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyDTO.getPolicyId(), collection); collection.setProperty("version", version); registry.put(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyDTO.getPolicyId(), collection);
@Override public PolicyDTO getPolicy(String policyId, String version) throws EntitlementException { // Zero means current version if (version == null || version.trim().length() == 0) { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); try { Collection collection = (Collection) registry. get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); if (collection != null) { version = collection.getProperty("version"); } } catch (RegistryException e) { log.error(e); throw new EntitlementException("Invalid policy version"); } } PAPPolicyStore policyStore = new PAPPolicyStore(); PAPPolicyStoreReader reader = new PAPPolicyStoreReader(policyStore); Resource resource = policyStore.getPolicy(version, PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId + RegistryConstants.PATH_SEPARATOR); if (resource == null) { throw new EntitlementException("Invalid policy version"); } return reader.readPolicyDTO(resource); }
if (!exist) { Collection appRootNode = tenantGovReg.newCollection(); appRootNode.setProperty("name", applicationName); tenantGovReg.put(applicationNode, appRootNode); String[] childern = appNodeCollec.getChildren(); if (childern == null || appNodeCollec.getChildCount() < 1) {
version = collection.getProperty("version"); } else { collection = registry.newCollection(); collection.setProperty("version", "1"); registry.put(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyDTO.getPolicyId(), collection); collection.setProperty("version", version); registry.put(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyDTO.getPolicyId(), collection);
@Override public PolicyDTO getPolicy(String policyId, String version) throws EntitlementException { // Zero means current version if (version == null || version.trim().length() == 0) { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); try { Collection collection = (Collection) registry. get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); if (collection != null) { version = collection.getProperty("version"); } } catch (RegistryException e) { log.error(e); throw new EntitlementException("Invalid policy version"); } } PAPPolicyStore policyStore = new PAPPolicyStore(); PAPPolicyStoreReader reader = new PAPPolicyStoreReader(policyStore); Resource resource = policyStore.getPolicy(version, PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId + RegistryConstants.PATH_SEPARATOR); if (resource == null) { throw new EntitlementException("Invalid policy version"); } return reader.readPolicyDTO(resource); }
private static void permissionPath(Registry tenantGovReg, String permissionPath, List<String> paths, String applicationNode) throws RegistryException { Collection appCollection = (Collection) tenantGovReg.get(permissionPath); String[] childern = appCollection.getChildren(); if (childern == null || childern.length == 0) { paths.add(permissionPath.replace(applicationNode, "").substring(2)); } while (childern != null && childern.length != 0) { for (int i = 0; i < childern.length; i++) { permissionPath(tenantGovReg, childern[i], paths, applicationNode); } break; } }
version = collection.getProperty("version"); } else { collection = registry.newCollection(); collection.setProperty("version", "1"); registry.put(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyDTO.getPolicyId(), collection); collection.setProperty("version", version); registry.put(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyDTO.getPolicyId(), collection);
private static void addPermission(String applicationNode, ApplicationPermission[] permissions, Registry tenantGovReg) throws RegistryException { for (ApplicationPermission permission : permissions) { String permissionValue = permission.getValue(); if ("/".equals(permissionValue.substring(0, 1))) { //if permissions are starts with slash remove that permissionValue = permissionValue.substring(1); } String[] splitedPermission = permissionValue.split("/"); String permissinPath = applicationNode + PATH_CONSTANT; for (int i = 0; i < splitedPermission.length; i++) { permissinPath = permissinPath + splitedPermission[i] + PATH_CONSTANT; Collection permissionNode = tenantGovReg.newCollection(); permissionNode.setProperty("name", splitedPermission[i]); tenantGovReg.put(permissinPath, permissionNode); } } }
@Override public PolicyDTO getPolicy(String policyId, String version) throws EntitlementException { // Zero means current version if (version == null || version.trim().length() == 0) { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); try { Collection collection = (Collection) registry. get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); if (collection != null) { version = collection.getProperty("version"); } } catch (RegistryException e) { log.error(e); throw new EntitlementException("Invalid policy version"); } } PAPPolicyStore policyStore = new PAPPolicyStore(); PAPPolicyStoreReader reader = new PAPPolicyStoreReader(policyStore); Resource resource = policyStore.getPolicy(version, PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId + RegistryConstants.PATH_SEPARATOR); if (resource == null) { throw new EntitlementException("Invalid policy version"); } return reader.readPolicyDTO(resource); }
@Override public String[] getVersions(String policyId) throws EntitlementException { List<String> versions = new ArrayList<String>(); Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); Collection collection = null; try { try { collection = (Collection) registry. get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); } catch (ResourceNotFoundException e) { // ignore } if (collection != null && collection.getChildren() != null) { String[] children = collection.getChildren(); for (String child : children) { versions.add(RegistryUtils.getResourceName(child)); } } } catch (RegistryException e) { log.error("Error while creating new version of policy", e); } return versions.toArray(new String[versions.size()]); } }
/** * Rename the registry path node name for a deleted Service provider role. * * @param oldName * @param newName * @throws IdentityApplicationManagementException */ public static void renameAppPermissionPathNode(String oldName, String newName) throws IdentityApplicationManagementException { List<ApplicationPermission> loadPermissions = loadPermissions(oldName); String newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + oldName; Registry tenantGovReg = CarbonContext.getThreadLocalCarbonContext().getRegistry( RegistryType.USER_GOVERNANCE); //creating new application node try { for (ApplicationPermission applicationPermission : loadPermissions) { tenantGovReg.delete(newApplicationNode + PATH_CONSTANT + applicationPermission.getValue()); } tenantGovReg.delete(newApplicationNode); Collection permissionNode = tenantGovReg.newCollection(); permissionNode.setProperty("name", newName); newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + newName; ApplicationMgtUtil.applicationNode = newApplicationNode; tenantGovReg.put(newApplicationNode, permissionNode); addPermission(loadPermissions.toArray(new ApplicationPermission[loadPermissions.size()]), tenantGovReg); } catch (RegistryException e) { throw new IdentityApplicationManagementException("Error while renaming permission node " + oldName + "to " + newName, e); } }
@Override public String[] getVersions(String policyId) throws EntitlementException { List<String> versions = new ArrayList<String>(); Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); Collection collection = null; try { try { collection = (Collection) registry. get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); } catch (ResourceNotFoundException e) { // ignore } if (collection != null && collection.getChildren() != null) { String[] children = collection.getChildren(); for (String child : children) { versions.add(RegistryUtils.getResourceName(child)); } } } catch (RegistryException e) { log.error("Error while creating new version of policy", e); } return versions.toArray(new String[versions.size()]); } }
permissionNode.setProperty("name", newName); newApplicationNode = ApplicationMgtUtil.getApplicationPermissionPath() + PATH_CONSTANT + newName; String applicationNode = newApplicationNode;
@Override public String[] getVersions(String policyId) throws EntitlementException { List<String> versions = new ArrayList<String>(); Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); Collection collection = null; try { try { collection = (Collection) registry. get(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); } catch (ResourceNotFoundException e) { // ignore } if (collection != null && collection.getChildren() != null) { String[] children = collection.getChildren(); for (String child : children) { versions.add(RegistryUtils.getResourceName(child)); } } } catch (RegistryException e) { log.error("Error while creating new version of policy", e); } return versions.toArray(new String[versions.size()]); } }
appRootNode.setProperty("name", "Applications"); tenantGovReg.put(permissionResourcePath, appRootNode); if (loggedInUserChanged) {
String[] childPaths = seqCollection.getChildren();
appRootNode.setProperty("name", "Applications"); tenantGovReg.put(permissionResourcePath, appRootNode); if (loggedInUserChanged) {