private static void zipDir(String dirToZip, ZipOutputStream zos) throws org.wso2.carbon.registry.api.RegistryException { try { File zipDir = new File(dirToZip); String[] dirList = zipDir.list(); byte[] readBuffer = new byte[1024]; int bytesIn = 0; for (int i = 0; i < dirList.length; i++) { File f = new File(zipDir,dirList[i]); if(f.isDirectory()) { zipDir(f.getPath(),zos); continue; } else { FileInputStream fis = new FileInputStream(f.getPath()); ZipEntry anEntry = new ZipEntry(f.getPath().contains("dependencies") ? "dependencies" + File.separator + f.getName():f.getName()); zos.putNextEntry(anEntry); while ((bytesIn = fis.read(readBuffer)) != -1) { zos.write(readBuffer, 0, bytesIn); } zos.flush(); fis.close(); } } } catch (Exception e) { throw new org.wso2.carbon.registry.api.RegistryException("Error occurred while zipping the file"); } }
private Properties getOIDCScopeProperties(String spTenantDomain) { Resource oidcScopesResource = null; try { int tenantId = IdentityTenantUtil.getTenantId(spTenantDomain); startTenantFlow(spTenantDomain, tenantId); RegistryService registryService = OAuth2ServiceComponentHolder.getRegistryService(); if (registryService == null) { throw new RegistryException("Registry Service not set in OAuth2 Component. Component may not have " + "initialized correctly."); } oidcScopesResource = registryService.getConfigSystemRegistry(tenantId).get(SCOPE_RESOURCE_PATH); } catch (RegistryException e) { log.error("Error while obtaining registry collection from registry path:" + SCOPE_RESOURCE_PATH, e); } finally { PrivilegedCarbonContext.endTenantFlow(); } Properties propertiesToReturn = new Properties(); if (oidcScopesResource != null) { for (Object scopeProperty : oidcScopesResource.getProperties().keySet()) { String propertyKey = (String) scopeProperty; propertiesToReturn.setProperty(propertyKey, oidcScopesResource.getProperty(propertyKey)); } } else { log.error("OIDC scope resource cannot be found at " + SCOPE_RESOURCE_PATH + " for tenantDomain: " + spTenantDomain); } return propertiesToReturn; }
public boolean importResource( String parentPath, String resourceName, String mediaType, String description, String fetchURL, String symlinkLocation, String[][] properties) throws Exception { UserRegistry registry = (UserRegistry) getRootRegistry(ResourceDataHolder.getInstance().getRegistryService()); if (RegistryUtils.isRegistryReadOnly(registry.getRegistryContext())) { return false; } // Fix for file importation security verification - FileSystemImportationSecurityHotFixTestCase if (StringUtils.isNotBlank(fetchURL) && fetchURL.toLowerCase().startsWith("file:")) { String msg = "The source URL must not be file in the server's local file system"; throw new RegistryException(msg); } // Adding Source URL as property to end of the properties array. String[][] newProperties = CommonUtil.setProperties(properties, "sourceURL", fetchURL); // Data is directed to below AddResourceUtil.addResource from ImportResourceUtil.importResource // Hence resource upload path will now go through put. AddResourceUtil.addResource(CommonUtil.calculatePath(parentPath, resourceName), mediaType, description, GetTextContentUtil.getByteContent(fetchURL), symlinkLocation, registry, newProperties); return true; }
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); }
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); }
resource = registry.get(child); } else { throw new RegistryException("Permission resource not found in the registry.");
resource = registry.get(child); } else { throw new RegistryException("Permission resource not found in the registry.");