private String getCustomQuery() { if (StaticConfiguration.isVersioningProperties()) { return "SELECT R.REG_PATH_ID, R.REG_NAME FROM REG_RESOURCE R , REG_PROPERTY PP, REG_RESOURCE_PROPERTY RP" + "R.REG_VERSION=RP.REG_VERSION AND" + "RP.REG_PROPERTY_ID=PP.REG_ID AND PP.REG_NAME=? AND PP.REG_VALUE LIKE ?"; } else { return "SELECT R.REG_PATH_ID, R.REG_NAME FROM REG_RESOURCE R , REG_PROPERTY PP, REG_RESOURCE_PROPERTY RP" + "((R.REG_PATH_ID=RP.REG_PATH_ID AND R.REG_NAME = RP.REG_RESOURCE_NAME ) OR" + "(R.REG_PATH_ID=RP.REG_PATH_ID AND R.REG_NAME IS NULL AND RP.REG_RESOURCE_NAME IS NULL)) AND" + "RP.REG_PROPERTY_ID=PP.REG_ID AND PP.REG_NAME=? AND PP.REG_VALUE LIKE ?"; } }
public RegistryContext getRegistryContext() { return RegistryContext.getBaseInstance(); }
/** * This method will return mounted path of the path if the path * is mounted. Else path will be returned. * * @param registryContext Registry Context instance which holds path mappings * @param path default path of the registry * @return mounted path or path */ public static String getMountedPath(RegistryContext registryContext, String path) { if (registryContext != null && path != null) { List<Mount> mounts = registryContext.getMounts(); if (mounts != null) { for (Mount mount : mounts) { if (path.equals(mount.getPath())) { return mount.getTargetPath(); } } } } return path; }
RegistryCacheKey cacheKey = null; if (registry.getRegistryContext().getRemoteInstances().size() > 0) { for (Mount mount : registry.getRegistryContext().getMounts()) { for (RemoteConfiguration configuration : registry.getRegistryContext().getRemoteInstances()) { if (updatedPath.startsWith(mount.getPath())) { DataBaseConfiguration dataBaseConfiguration = registry.getRegistryContext(). getDBConfig(configuration.getDbConfig()); String connectionId = (dataBaseConfiguration.getUserName() != null ? dataBaseConfiguration.getUserName(). split("@")[0] : dataBaseConfiguration.getUserName()) + "@" + dataBaseConfiguration.getDbUrl(); cacheKey = RegistryUtils.buildRegistryCacheKey(connectionId, tenantId, updatedPath); DataBaseConfiguration dataBaseConfiguration = registry.getRegistryContext().getDefaultDataBaseConfiguration(); String connectionId = (dataBaseConfiguration.getUserName() != null ? dataBaseConfiguration.getUserName(). split("@")[0] : dataBaseConfiguration.getUserName()) + "@" + dataBaseConfiguration.getDbUrl(); cacheKey = RegistryUtils.buildRegistryCacheKey(connectionId, tenantId, updatedPath);
public static void registerPerRegistryRequestListener(RegistryContext registryContext) { HandlerManager handlerManager = registryContext.getHandlerManager(); PerRegistryRequestListener storeBandwidthHandler = new PerRegistryRequestListener(); URLMatcher anyUrlMatcher = new URLMatcher(); anyUrlMatcher.setPattern(".*"); String[] applyingFilters = new String[] { Filter.PUT, Filter.IMPORT, Filter.GET, Filter.DUMP, Filter.RESTORE, }; handlerManager.addHandlerWithPriority( applyingFilters, anyUrlMatcher, storeBandwidthHandler); } }
private RegistryCacheKey constructCacheKey(DataBaseConfiguration dbConfig, String resourcePath, int tenantId) { String connectionId = (dbConfig.getUserName() != null ? dbConfig.getUserName().split("@")[0] : dbConfig.getUserName()) + "@" + dbConfig.getDbUrl(); return RegistryUtils.buildRegistryCacheKey(connectionId, tenantId, resourcePath); }
private String getChrootedServiceLocation(Registry registry, RegistryContext registryContext) { return RegistryUtils.getAbsolutePath(registryContext, registry.getRegistryContext().getServicePath()); // service path contains the base }
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; }
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 boolean isExecutingMountedHandlerChain(RequestContext requestContext) { return (requestContext.getRegistry().getRegistryContext() == null) || requestContext.getRegistry().getRegistryContext().isClone(); }
/** * This method used to generate mount path.(Fix need to go to kernel, Since Kernel 4.4.0 already released * will maintain fix here.) * @param requestContext * @param servicePath * @return */ public static String getRegistryPath(RegistryContext requestContext, String servicePath){ List<Mount> mounts = requestContext.getMounts(); for (Mount mount: mounts) { String mountPath = mount.getPath(); if (servicePath.startsWith(mountPath) && !servicePath.startsWith(mount.getTargetPath())){ return servicePath.replace(mountPath, mount.getTargetPath()); } } return servicePath; }
/** * Obtains the governance user registry from the given root registry instance. This is useful * when creating a governance user registry out of a remote client registry instance. * * @param registry the remote client registry instance. * @param username the name of the user to connect as. * @return the system registry. * @throws RegistryException throws if an error occurs */ @SuppressWarnings("unused") public static Registry getGovernanceUserRegistry(Registry registry, String username) throws RegistryException { if (RegistryContext.getBaseInstance() == null) { RegistryContext.getBaseInstance(null, false); } return new UserRegistry(username, MultitenantConstants.SUPER_TENANT_ID, registry, null, RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH); }
private String getCustomQuery() { if (StaticConfiguration.isVersioningProperties()) { return "SELECT R.REG_PATH_ID, R.REG_NAME FROM REG_RESOURCE R , REG_PROPERTY PP, REG_RESOURCE_PROPERTY RP" + "R.REG_VERSION=RP.REG_VERSION AND" + "RP.REG_PROPERTY_ID=PP.REG_ID AND PP.REG_NAME=? AND PP.REG_VALUE LIKE ?"; } else { return "SELECT R.REG_PATH_ID, R.REG_NAME FROM REG_RESOURCE R , REG_PROPERTY PP, REG_RESOURCE_PROPERTY RP" + "((R.REG_PATH_ID=RP.REG_PATH_ID AND R.REG_NAME = RP.REG_RESOURCE_NAME ) OR" + "(R.REG_PATH_ID=RP.REG_PATH_ID AND R.REG_NAME IS NULL AND RP.REG_RESOURCE_NAME IS NULL)) AND" + "RP.REG_PROPERTY_ID=PP.REG_ID AND PP.REG_NAME=? AND PP.REG_VALUE LIKE ?"; } }
private String getChrootedServiceLocation(Registry registry, RegistryContext registryContext) { return RegistryUtils.getAbsolutePath(registryContext, registry.getRegistryContext().getServicePath()); // service path contains the base }
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; }
/** * Obtains the governance user registry from the given root registry instance. This is useful * when creating a tenant aware governance user registry out of a remote client registry instance. * * @param registry registry the remote client registry instance. * @param username username the name of the user to connect as. * @param tenantId tenant id * @return the system registry * @throws RegistryException throws if an error occurs */ public static Registry getGovernanceUserRegistry(Registry registry, String username, int tenantId) throws RegistryException { if (RegistryContext.getBaseInstance() == null) { RegistryContext.getBaseInstance(null, false); } return new UserRegistry(username, tenantId, registry, null, RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH); }
private String getCustomQuery() { if (StaticConfiguration.isVersioningProperties()) { return "SELECT R.REG_PATH_ID, R.REG_NAME FROM REG_RESOURCE R , REG_PROPERTY PP, REG_RESOURCE_PROPERTY RP" + "R.REG_VERSION=RP.REG_VERSION AND" + "RP.REG_PROPERTY_ID=PP.REG_ID AND PP.REG_NAME=? AND PP.REG_VALUE LIKE ?"; } else { return "SELECT R.REG_PATH_ID, R.REG_NAME FROM REG_RESOURCE R , REG_PROPERTY PP, REG_RESOURCE_PROPERTY RP" + "((R.REG_PATH_ID=RP.REG_PATH_ID AND R.REG_NAME = RP.REG_RESOURCE_NAME ) OR" + "(R.REG_PATH_ID=RP.REG_PATH_ID AND R.REG_NAME IS NULL AND RP.REG_RESOURCE_NAME IS NULL)) AND" + "RP.REG_PROPERTY_ID=PP.REG_ID AND PP.REG_NAME=? AND PP.REG_VALUE LIKE ?"; } }
private static String getChrootedServiceLocation(Registry registry, RegistryContext registryContext) { return RegistryUtils.getAbsolutePath(registryContext, registry.getRegistryContext().getServicePath()); // service path contains the base }
public static void initializeAllListeners() throws Exception { RegistryUsageListener.registerRegistryUsagePersistingListener( RegistryContext.getBaseInstance()); }
private String[] getAuthorizedRoles(String artifactPath) throws UserStoreException { String resourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + artifactPath); RegistryAuthorizationManager authorizationManager = new RegistryAuthorizationManager (ServiceReferenceHolder.getUserRealm()); return authorizationManager.getAllowedRolesForResource(resourcePath,ActionConstants.GET); }