private UIPermissionNode getUIPermissionNode(Resource resource, boolean isSelected) throws RegistryException { String displayName = resource.getProperty(UserMgtConstants.DISPLAY_NAME); return new UIPermissionNode(resource.getPath(), displayName, isSelected); }
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); } } }
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 void buildUIPermissionNodeAllSelected(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry) throws RegistryException, UserStoreException { String[] children = parent.getChildren(); UIPermissionNode[] childNodes = new UIPermissionNode[children.length]; for (int i = 0; i < children.length; i++) { String child = children[i]; Resource resource = null; if (registry.resourceExists(child)) { resource = registry.get(child); } else if (tenantRegistry != null) { resource = tenantRegistry.get(child); } else { throw new RegistryException("Permission resource not found in the registry."); } childNodes[i] = getUIPermissionNode(resource, true); if (resource instanceof Collection) { buildUIPermissionNodeAllSelected((Collection) resource, childNodes[i], registry, tenantRegistry); } } parentNode.setNodeList(childNodes); }
/** * Load Analytics profile from given registry and registry path. * * @param analyticsServerProfile AnalyticsServerProfile instance * @param registry Registry space where file is located * @param location Registry path of the profile file */ private void loadAnalyticsProfileFromRegistry(AnalyticsServerProfile analyticsServerProfile, Registry registry, String location) { try { if (registry.resourceExists(location)) { Resource resource = registry.get(location); String resourceContent = new String((byte[]) resource.getContent()); parseAnalyticsProfile(resourceContent, analyticsServerProfile); } else { String errMsg = "The resource: " + location + " does not exist."; handleError(errMsg); } } catch (RegistryException e) { String errMsg = "Error occurred while reading the resource from registry: " + location + " to build the Analytics server profile: " + profileLocation; handleError(errMsg, e); } }
/** * * Populates the properties using the configuration file in the given registry location. * * @param configResourcePath * @param registry */ public void populate(String configResourcePath, Registry registry){ try{ if(registry.resourceExists(configResourcePath)) { Resource configurationsResource = registry.get(configResourcePath); StAXOMBuilder builder = new StAXOMBuilder(configurationsResource.getContentStream()); OMElement root = builder.getDocumentElement(); populate(root); } } catch (XMLStreamException e) { String errorMessage = "Can't load the tenant configuration for the tenant " + tenantID; log.error(errorMessage, e); } catch (RegistryException e) { String errorMessage = "Can't load the tenant configuration for the tenant " + tenantID; log.error(errorMessage, e); } }
@Override public void deletePolicy(String policyId) throws EntitlementException { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); try { if (registry.resourceExists(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId)) { registry.delete(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); } } catch (RegistryException e) { log.error("Error while deleting all versions of policy", e); } }
@Override public void persistConfig(String policyEditorType, String xmlConfig) throws PolicyEditorException { super.persistConfig(policyEditorType, xmlConfig); Registry registry = CarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_GOVERNANCE); try { Resource resource = registry.newResource(); resource.setContent(xmlConfig); String path = null; if (EntitlementConstants.PolicyEditor.BASIC.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_BASIC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.STANDARD.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_STANDARD_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.RBAC.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_RBAC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else if (EntitlementConstants.PolicyEditor.SET.equals(policyEditorType)) { path = EntitlementConstants.ENTITLEMENT_POLICY_SET_EDITOR_CONFIG_FILE_REGISTRY_PATH; } else { //default path = EntitlementConstants.ENTITLEMENT_POLICY_BASIC_EDITOR_CONFIG_FILE_REGISTRY_PATH; } registry.put(path, resource); } catch (RegistryException e) { throw new PolicyEditorException("Error while persisting policy editor config"); } }
/** * Check if resource has expired and delete. * * @param registry Registry instance to use. * @param resourcePath Path of resource to be deleted. * @throws RegistryException */ private static void checkAndDeleteRegistryResource (Registry registry, String resourcePath) throws RegistryException { Resource resource = registry.get(resourcePath); long currentEpochTime = System.currentTimeMillis(); long resourceExpireTime = Long.parseLong(resource.getProperty(EXPIRE_TIME_PROPERTY)); if (currentEpochTime > resourceExpireTime) { registry.delete(resource.getId()); } }
public static Resource getRegistryResource(String path) throws MobileDeviceMgtPluginException { try { if(MobileDeviceManagementUtil.getConfigurationRegistry().resourceExists(path)){ return MobileDeviceManagementUtil.getConfigurationRegistry().get(path); } return null; } catch (RegistryException e) { throw new MobileDeviceMgtPluginException("Error in retrieving registry resource : " + e.getMessage(), e); } }
private void deleteRecursively (Registry registry, Resource resource) throws RegistryException { if (resource instanceof Collection) { for(String childResource : ((Collection) resource).getChildren()){ deleteRecursively(registry, registry.get(childResource)); } } registry.delete(resource.getPath()); }
/** * Get config system registry * * @return config system registry * @throws org.wso2.carbon.registry.api.RegistryException */ private Registry getConfigSystemRegistry() throws RegistryException { return (Registry) ApplicationManagementServiceComponentHolder.getInstance().getRegistryService() .getConfigSystemRegistry(); }
private void buildUIPermissionNodeAllSelected(Collection parent, UIPermissionNode parentNode, Registry registry, Registry tenantRegistry) throws RegistryException, UserStoreException { String[] children = parent.getChildren(); UIPermissionNode[] childNodes = new UIPermissionNode[children.length]; for (int i = 0; i < children.length; i++) { String child = children[i]; Resource resource = null; if (registry.resourceExists(child)) { resource = registry.get(child); } else if (tenantRegistry != null) { resource = tenantRegistry.get(child); } else { throw new RegistryException("Permission resource not found in the registry."); } childNodes[i] = getUIPermissionNode(resource, true); if (resource instanceof Collection) { buildUIPermissionNodeAllSelected((Collection) resource, childNodes[i], registry, tenantRegistry); } } parentNode.setNodeList(childNodes); }
@Override public void deletePolicy(String policyId) throws EntitlementException { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); try { if (registry.resourceExists(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId)) { registry.delete(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); } } catch (RegistryException e) { log.error("Error while deleting all versions of policy", e); } }
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); } } }
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; } }
private UIPermissionNode getUIPermissionNode(Resource resource, boolean isSelected) throws RegistryException { String displayName = resource.getProperty(UserMgtConstants.DISPLAY_NAME); return new UIPermissionNode(resource.getPath(), displayName, isSelected); }
/** * Get config system registry * * @return config system registry * @throws org.wso2.carbon.registry.api.RegistryException */ private Registry getConfigSystemRegistry() throws RegistryException { return (Registry) ApplicationManagementServiceComponentHolder.getInstance().getRegistryService() .getConfigSystemRegistry(); }
@Override public void deletePolicy(String policyId) throws EntitlementException { Registry registry = EntitlementServiceComponent. getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId()); try { if (registry.resourceExists(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId)) { registry.delete(PDPConstants.ENTITLEMENT_POLICY_VERSION + policyId); } } catch (RegistryException e) { log.error("Error while deleting all versions of policy", e); } }
/** * Get config system registry * * @return config system registry * @throws org.wso2.carbon.registry.api.RegistryException */ private Registry getConfigSystemRegistry() throws RegistryException { return (Registry) ApplicationManagementServiceComponentHolder.getInstance().getRegistryService() .getConfigSystemRegistry(); }