private boolean isConfigRegistryReadOnly() { RegistryContext context = tenantConfigRegistry.getRegistryContext(); try { if (context != null) { return context.isReadOnly(); } } catch (Exception e) { log.error("An error occurred while obtaining registry instance", e); } return false; }
private boolean isExecutingMountedHandlerChain(RequestContext requestContext) { return (requestContext.getRegistry().getRegistryContext() == null) || requestContext.getRegistry().getRegistryContext().isClone(); }
private String getChrootedServiceLocation(Registry registry, RegistryContext registryContext) { return RegistryUtils.getAbsolutePath(registryContext, registry.getRegistryContext().getServicePath()); // service path contains the base }
private String getChrootedServiceLocation(Registry registry, RegistryContext registryContext) { return RegistryUtils.getAbsolutePath(registryContext, registry.getRegistryContext().getServicePath()); // service path contains the base }
private static String getChrootedServiceLocation(Registry registry, RegistryContext registryContext) { return RegistryUtils.getAbsolutePath(registryContext, registry.getRegistryContext().getServicePath()); // service path contains the base }
/** * Method to get the actual depth of the request * @param requestContext Request Context */ private int getRequestDepth(RequestContext requestContext){ int requestDepth = -1; if (requestContext.getRegistry().getRegistryContext() != null && requestContext.getRegistry().getRegistryContext().getDataAccessManager() != null && requestContext.getRegistry().getRegistryContext().getDataAccessManager().getDatabaseTransaction() != null) { requestDepth = requestContext.getRegistry().getRegistryContext().getDataAccessManager().getDatabaseTransaction() .getNestedDepth(); } return requestDepth; }
/** * Configures the swagger resource path form its content and returns the swagger document path. * * @param rootLocation root location of the swagger files. * @param content swagger content. * @return Common resource path. */ private String getSwaggerDocumentPath(String rootLocation, JsonObject content) throws RegistryException { String swaggerDocPath = requestContext.getResourcePath().getPath(); String swaggerDocName = swaggerDocPath.substring(swaggerDocPath.lastIndexOf(RegistryConstants.PATH_SEPARATOR) + 1); JsonElement infoElement = content.get(SwaggerConstants.INFO); JsonObject infoObject = (infoElement != null) ? infoElement.getAsJsonObject() : null; if (infoObject == null || infoElement.isJsonNull()) { throw new RegistryException("Invalid swagger document."); } String serviceName = infoObject.get(SwaggerConstants.TITLE).getAsString().replaceAll("\\s", ""); String serviceProvider = CarbonContext.getThreadLocalCarbonContext().getUsername(); swaggerResourcesPath = rootLocation + serviceProvider + RegistryConstants.PATH_SEPARATOR + serviceName + RegistryConstants.PATH_SEPARATOR + documentVersion; String pathExpression = getSwaggerRegistryPath(swaggerDocName, serviceProvider); return RegistryUtils.getAbsolutePath(registry.getRegistryContext(),pathExpression); }
/** * Function to check whether this nos node is manager node by checking registry read/write ability * * @return true if this is manager node, false otherwise */ private boolean isManagerNode() { try { //get config registry of super tenant Registry configRegistry = BPELServiceComponent.getRegistryService().getConfigSystemRegistry( MultitenantConstants.SUPER_TENANT_ID); RegistryContext registryContext = configRegistry.getRegistryContext(); if (registryContext != null) { return !registryContext.isReadOnly(); } } catch (RegistryException e) { log.error("Error occurred while retrieving config registry", e); } return false; }
/** * At bpel package undeployment, remove the entires created in registry corresponding to the given BPEL package * @param packageName * @throws RegistryException */ public void handleBPELPackageUndeploy(String packageName) throws RegistryException { try { String packageLocation = BPELPackageRepositoryUtils.getResourcePathForBPELPackage(packageName); if (!configRegistry.getRegistryContext().isReadOnly() && configRegistry.resourceExists(packageLocation)) { configRegistry.delete(packageLocation); } else { throw new IllegalAccessException(); } } catch (RegistryException re) { String errMessage = "Unable to access registry for handling BPEL package " + "undeployment for Package: " + packageName; log.error(errMessage, re); throw re; } catch (IllegalAccessException e) { log.error("Trying to update a Read-only registry", e); } }
private String getServicePath(Registry registry, Resource resource, OMElement serviceInfoElement, String serviceName, String serviceNamespace, String serviceVersion) { String servicePath; if (Utils.getRxtService() == null) { servicePath = RegistryUtils.getAbsolutePath(registry.getRegistryContext(), registry.getRegistryContext().getServicePath() + (serviceNamespace == null ? "" : CommonUtil .derivePathFragmentFromNamespace( serviceNamespace)) + serviceVersion + "/" + serviceName); } else { String pathExpression = Utils.getRxtService().getStoragePath(resource.getMediaType()); servicePath = RegistryUtils.getAbsolutePath(registry.getRegistryContext(), CommonUtil.getPathFromPathExpression(pathExpression, serviceInfoElement, null)); servicePath = CommonUtil.getRegistryPath(registry.getRegistryContext(), servicePath); } return servicePath; }
private String getServicePath(Registry registry, Resource resource, OMElement serviceInfoElement, String serviceName, String serviceNamespace, String serviceVersion) { String servicePath; if (Utils.getRxtService() == null) { servicePath = RegistryUtils.getAbsolutePath(registry.getRegistryContext(), registry.getRegistryContext().getServicePath() + (serviceNamespace == null ? "" : CommonUtil .derivePathFragmentFromNamespace( serviceNamespace)) + serviceVersion + "/" + serviceName); } else { String pathExpression = Utils.getRxtService().getStoragePath(resource.getMediaType()); servicePath = RegistryUtils.getAbsolutePath(registry.getRegistryContext(), CommonUtil.getPathFromPathExpression(pathExpression, serviceInfoElement, null)); servicePath = CommonUtil.getRegistryPath(registry.getRegistryContext(), servicePath); } return servicePath; }
public static Registry getUnchrootedSystemRegistry(RequestContext requestContext) throws RegistryException { Registry registry = requestContext.getRegistry(); RealmService realmService = registry.getRegistryContext().getRealmService(); String systemUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME; return new UserRegistry(systemUser, CurrentSession.getTenantId(), registry, realmService, null); }
private String getRegistryPath(RequestContext requestContext) { String servicePath = requestContext.getResourcePath().getPath(); List<Mount> mounts = requestContext.getRegistry().getRegistryContext().getMounts(); for (Mount mount: mounts) { String mountPath = mount.getPath(); if (servicePath.startsWith(mount.getTargetPath())){ return servicePath.replace(mount.getTargetPath(), mountPath); } } return servicePath; }
/** * Method will add Local PathMap to the CurrentSession, if it is not exists * Set ARCHIEVE_UPLOAD param to true, it param is accessed to calculate registry path in mounted env. * @param requestContext the request context to get mount points * @return whether pathMap is set or not */ private boolean setSessionLocalPathMap(RequestContext requestContext) { boolean pathMapSet = false; if (CurrentSession.getLocalPathMap() == null) { RegistryContext registryContext = requestContext.getRegistry().getRegistryContext(); if (registryContext != null && registryContext.getMounts() != null && !registryContext.getMounts().isEmpty()) { Map<String, String> localPathMap = new HashMap<String, String>(); CurrentSession.setLocalPathMap(localPathMap); CurrentSession.getLocalPathMap().put(CommonConstants.ARCHIEVE_UPLOAD, "true"); pathMapSet = true; } } else { CurrentSession.getLocalPathMap().put(CommonConstants.ARCHIEVE_UPLOAD, "true"); } return pathMapSet; }
private static void saveEndpoint(RequestContext context, Registry registry, String url, String associatedPath, Map<String, String> properties, Registry systemRegistry) throws RegistryException { String urlToPath = deriveEndpointFromUrl(url); String pathExpression = getEndpointLocation(context, url, systemRegistry, endpointLocation); String endpointAbsoluteBasePath = RegistryUtils.getAbsolutePath(registry.getRegistryContext(), org.wso2.carbon.registry.core.RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + endpointLocation); if (!systemRegistry.resourceExists(endpointAbsoluteBasePath)) { systemRegistry.put(endpointAbsoluteBasePath, systemRegistry.newCollection()); } if(endpointLocation.endsWith(RegistryConstants.PATH_SEPARATOR)){ if(urlToPath.startsWith(RegistryConstants.PATH_SEPARATOR)){ urlToPath = urlToPath.replaceFirst(RegistryConstants.PATH_SEPARATOR,""); } }else{ if(!urlToPath.startsWith(RegistryConstants.PATH_SEPARATOR)){ urlToPath = RegistryConstants.PATH_SEPARATOR + urlToPath; } } String relativePath = endpointLocation + urlToPath; String endpointAbsolutePath = pathExpression; saveEndpointValues(context, registry, url, associatedPath, properties, systemRegistry, relativePath, endpointAbsolutePath); }
private boolean isIndexablePutOperation(RequestContext requestContext) { return (requestContext.getRegistry().getRegistryContext() == null) || requestContext.getResource() == null || requestContext.getResource().getMediaType() == null || requestContext.getResource() instanceof Collection; }
private String getSwaggerRegistryPath(String swaggerDocName, String serviceProvider) { String pathExpression = Utils.getRxtService().getStoragePath(CommonConstants.SWAGGER_MEDIA_TYPE); pathExpression = CommonUtil.getPathFromPathExpression(pathExpression, requestContext.getResource().getProperties(), null); pathExpression = CommonUtil.replaceExpressionOfPath(pathExpression, "provider", serviceProvider); swaggerResourcesPath = pathExpression; pathExpression = CommonUtil.replaceExpressionOfPath(pathExpression, "name", swaggerDocName); String swaggerPath = pathExpression; /** * Fix for the REGISTRY-3052 : validation is to check the whether this invoked by ZIPWSDLMediaTypeHandler * Setting the registry and absolute paths to current session to avoid incorrect resource path entry in REG_LOG table */ if (CurrentSession.getLocalPathMap() != null && !Boolean.valueOf(CurrentSession.getLocalPathMap().get(CommonConstants.ARCHIEVE_UPLOAD))) { swaggerPath = CommonUtil.getRegistryPath(requestContext.getRegistry().getRegistryContext(), pathExpression); if (log.isDebugEnabled()) { log.debug("Saving current session local paths, key: " + swaggerPath + " | value: " + pathExpression); } CurrentSession.getLocalPathMap().put(swaggerPath, pathExpression); } return swaggerPath; }
/** * This method used to generate endpoint path * @param requestContext Request Context * @param endpointElement Endpoint XML element * @param endpointPath Current endpoint path * @return Updated endpoint path; */ private static String getEndpointPath(RequestContext requestContext, OMElement endpointElement, String endpointPath) { String pathExpression = Utils.getRxtService().getStoragePath(CommonConstants.ENDPOINT_MEDIA_TYPE); pathExpression = CommonUtil.getPathFromPathExpression(pathExpression, endpointElement, requestContext.getResource().getProperties()); endpointPath = CommonUtil.replaceExpressionOfPath(pathExpression, "name", endpointPath); String endpointRegistryPath = endpointPath; /** * Fix for the REGISTRY-3052 : validation is to check the whether this invoked by ZIPWSDLMediaTypeHandler * Setting the registry and absolute paths to current session to avoid incorrect resource path entry in REG_LOG table */ if (CurrentSession.getLocalPathMap() != null && !Boolean.valueOf(CurrentSession.getLocalPathMap().get(CommonConstants.ARCHIEVE_UPLOAD))) { endpointRegistryPath = CommonUtil.getRegistryPath(requestContext.getRegistry().getRegistryContext(), endpointPath); if (log.isDebugEnabled()) { log.debug("Saving current session local paths, key: " + endpointRegistryPath + " | value: " + endpointPath); } CurrentSession.getLocalPathMap().put(endpointRegistryPath, endpointPath); } return endpointRegistryPath; }
private static void saveEndpoint(RequestContext context, Registry registry, String url, String associatedPath, Map<String, String> properties, Registry systemRegistry, String environment) throws RegistryException { String pathExpression = getEndpointLocation(context, url, systemRegistry, environment); String urlToPath = deriveEndpointFromUrl(url); String endpointAbsoluteBasePath = RegistryUtils.getAbsolutePath(registry.getRegistryContext(), org.wso2.carbon.registry.core.RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + environment); if (!systemRegistry.resourceExists(endpointAbsoluteBasePath)) { systemRegistry.put(endpointAbsoluteBasePath, systemRegistry.newCollection()); } String relativePath = environment + urlToPath; String endpointAbsolutePath = pathExpression; saveEndpointValues(context, registry, url, associatedPath, properties, systemRegistry, relativePath, endpointAbsolutePath); }
private String getEndpointPath(RequestContext requestContext, String resourceContent, String endpointUrl) throws RegistryException { String pathExpression = Utils.getRxtService().getStoragePath(CommonConstants.ENDPOINT_MEDIA_TYPE); pathExpression = CommonUtil.replaceExpressionOfPath(pathExpression, "name",getEndpointName(EndpointUtils.deriveNameFromContent(resourceContent),EndpointUtils.deriveEndpointNameWithNamespaceFromUrl(endpointUrl))); pathExpression = CommonUtil.getPathFromPathExpression(pathExpression, EndpointUtils.deriveOMElementContent(resourceContent),requestContext.getResource().getProperties()); String endpointPath = CommonUtil.getRegistryPath(requestContext.getRegistry().getRegistryContext(), pathExpression); return endpointPath; }