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; }
private String getChrootedServiceLocation(Registry registry, RegistryContext registryContext) { return RegistryUtils.getAbsolutePath(registryContext, registry.getRegistryContext().getServicePath()); // service path contains the base }
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); } }
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(). DataBaseConfiguration dataBaseConfiguration = registry.getRegistryContext().getDefaultDataBaseConfiguration(); String connectionId = (dataBaseConfiguration.getUserName() != null ? dataBaseConfiguration.getUserName().
RegistryConstants.URL_SEPARATOR + ".*)"); RegistryContext registryContext = registry.getRegistryContext(); registryContext.registerNoCachePath(mountPoint); registryContext.getHandlerManager().addHandler(null, urlMatcher, externalContentHandler, HandlerLifecycleManager.TENANT_SPECIFIC_SYSTEM_HANDLER_PHASE);
/** * Creates the regostry service if not available. * * @param realClass * @return * @throws RegistryException */ private RegistryService createRegistryService(Class realClass, int tenantID, String tenantDomain) throws RegistryException { if (registryService != null) { return registryService; } try { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantID); RegistryContext registryContext = RegistryContext.getBaseInstance(IdentityTenantUtil.getRealmService()); DataSource dataSource = MockInitialContextFactory .initializeDatasource(REG_DB_JNDI_NAME, realClass, new String[]{REG_DB_SQL_FILE}); registryContext.setDataAccessManager(new JDBCDataAccessManager(dataSource)); registryService = new EmbeddedRegistryService(registryContext); OSGiDataHolder.getInstance().setRegistryService(registryService); CarbonCoreDataHolder.getInstance().setRegistryService(registryService); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setRegistry(RegistryType.USER_GOVERNANCE, registryService.getRegistry()); return registryService; } catch (TestCreationException e) { log.error("Could not load registry data", e); throw new RegistryException("Could not load registry data", e); } }
if (registry.getRegistryContext() != null) { List remoteInstances = registry.getRegistryContext(). getRemoteInstances(); String[] instances = new String[remoteInstances.size()]; for(int i=0; i<instances.length; i++) {
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); }
public static void registerRegistryUsagePersistingListener(RegistryContext registryContext) throws RegistryException { //If metering is disabled, we do not need to register the handler if(!"true".equals(ServerConfiguration.getInstance().getFirstProperty("EnableMetering"))){ return; } HandlerManager handlerManager = registryContext.getHandlerManager(); RegistryUsageListener handler = new RegistryUsageListener(); URLMatcher anyUrlMatcher = new URLMatcher(); anyUrlMatcher.setPattern(".*"); String[] applyingFilters = new String[]{ Filter.PUT, Filter.IMPORT, Filter.GET, Filter.DUMP, Filter.RESTORE, Filter.DELETE}; handlerManager.addHandlerWithPriority(applyingFilters, anyUrlMatcher, handler, HandlerLifecycleManager.DEFAULT_REPORTING_HANDLER_PHASE); }
if (registry.getRegistryContext().getRemoteInstances().size() > 0) { for (Mount mount : registry.getRegistryContext().getMounts()) { for (RemoteConfiguration configuration : registry.getRegistryContext().getRemoteInstances()) { if (resourcePath.startsWith(mount.getPath())) { DataBaseConfiguration dataBaseConfiguration = registry.getRegistryContext().getDBConfig(configuration.getDbConfig()); removeCacheFromCacheRegistry(cache, dataBaseConfiguration, resourcePath, tenantId); getDefaultDataBaseConfiguration(); removeCacheFromCacheRegistry(cache, dataBaseConfiguration, resourcePath, tenantId);
/** * Creates the regostry service if not available. * * @param realClass * @return * @throws RegistryException */ private RegistryService createRegistryService(Class realClass, int tenantID, String tenantDomain) throws RegistryException { if (registryService != null) { return registryService; } try { PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantID); RegistryContext registryContext = RegistryContext.getBaseInstance(IdentityTenantUtil.getRealmService()); DataSource dataSource = MockInitialContextFactory .initializeDatasource(REG_DB_JNDI_NAME, realClass, new String[]{REG_DB_SQL_FILE}); registryContext.setDataAccessManager(new JDBCDataAccessManager(dataSource)); registryService = new EmbeddedRegistryService(registryContext); OSGiDataHolder.getInstance().setRegistryService(registryService); CarbonCoreDataHolder.getInstance().setRegistryService(registryService); PrivilegedCarbonContext.getThreadLocalCarbonContext() .setRegistry(RegistryType.USER_GOVERNANCE, registryService.getRegistry()); return registryService; } catch (TestCreationException e) { log.error("Could not load registry data", e); throw new RegistryException("Could not load registry data", e); } }
String layoutStoragePath = configurationPath + key; RealmService realmService = registry.getRegistryContext().getRealmService(); if (realmService.getTenantUserRealm(realmService.getTenantManager().getTenantId(s1)) .getAuthorizationManager().isUserAuthorized(s, configurationPath, ActionConstants.PUT)
/** * 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); }
protected void activate(ComponentContext context) { try { URLMatcher um = new URLMatcher(); um.setAddAssociationPattern(DEFAULT_SHUTTERBUG_HOME + RegistryConstants.PATH_SEPARATOR + VOTE_PATH); um.setRemoveAssociationPattern(DEFAULT_SHUTTERBUG_HOME + RegistryConstants.PATH_SEPARATOR + VOTE_PATH); ShutterbugCollectionHandler sbHandler = new ShutterbugCollectionHandler(); sbHandler.init(); Utils.getRegistryService().getSystemRegistry().getRegistryContext() .getHandlerManager().addHandler(null, um, sbHandler); } catch (Exception e) { log.error("Shutterbug Collection Handler registration failed.", e); } try { Utils.getRegistryService().getSystemRegistry().getRegistryContext() .getHandlerManager().addHandler(null, new MediaTypeMatcher(SHUTTERBUG_MEDIA_TYPE), new ShutterbugImageHandler()); } catch (Exception e) { log.error("Shutterbug Image Handler registration failed.", e); } log.info("Successfully started the Shutterbug Sample."); }
/** * 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; }
private String getChrootedServiceLocation(Registry registry, RegistryContext registryContext) { return RegistryUtils.getAbsolutePath(registryContext, registry.getRegistryContext().getServicePath()); // service path contains the base }
/** * 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); }
if (registry == null || registry.getRegistryContext() == null || registry.getRegistryContext().getHandlerManager() == null) { String msg = "Error Initializing Registry Profile Handler"; log.error(msg); "/") + ".*" + RegistryConstants.PROFILES_PATH + ".*/profiles"); ProfilesAddHandler handler = new ProfilesAddHandler(); registry.getRegistryContext().getHandlerManager().addHandler(null, filter, handler);
/** * 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; }