public RegistryContext getRegistryContext() { return RegistryContext.getBaseInstance(); }
/** * 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); }
/** * 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); }
public static void initializeAllListeners() throws Exception { RegistryUsageListener.registerRegistryUsagePersistingListener( RegistryContext.getBaseInstance()); }
public void init() throws RegistryException { if("true".equals(ServerConfiguration.getInstance().getFirstProperty("EnableMetering"))){ UserRegistry superTenantGovernanceRegistry = registryService.getGovernanceSystemRegistry(); scheduler.scheduleAtFixedRate( new ThrottlingInfoCacheUpdaterTask(throttlingInfoCache, superTenantGovernanceRegistry), 2, 15, TimeUnit.MINUTES); PerRegistryRequestListener.registerPerRegistryRequestListener(RegistryContext.getBaseInstance()); if (bundleContext != null) { bundleContext.registerService(UserStoreManagerListener.class.getName(), new PerUserAddListener(), null); } } throttlingRuleInvokerTracker = new ServiceTracker(bundleContext, ThrottlingRuleInvoker.class.getName(), null); throttlingRuleInvokerTracker.open(); }
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); }
public DefaultLifeCycle(OMElement config) throws RegistryException { initialize(); String currentAspectName = config.getAttributeValue(new QName(LifecycleConstants.NAME)); aspectName = currentAspectName; currentAspectName = currentAspectName.replaceAll("\\s", ""); stateProperty = LifecycleConstants.REGISTRY_LIFECYCLE + currentAspectName + ".state"; lifecycleProperty = lifecycleProperty + "." + currentAspectName ; Iterator configChildElements = config.getChildElements(); while (configChildElements.hasNext()) { OMElement configChildEl = (OMElement) configChildElements.next(); if (configChildEl.getAttribute(new QName(LifecycleConstants.TYPE)) != null) { String type = configChildEl.getAttributeValue(new QName(LifecycleConstants.TYPE)); if (type.equalsIgnoreCase("resource")) { isConfigurationFromResource = true; configurationResourcePath = RegistryUtils.getAbsolutePath( RegistryContext.getBaseInstance(), configChildEl.getText()); clearAll(); break; } else if (type.equalsIgnoreCase("literal")) { isConfigurationFromResource = false; configurationElement = configChildEl.getFirstElement(); clearAll(); break; } } } }
String resourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), AppManagerUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + AppMConstants.EXTERNAL_APP_STORES_LOCATION); authManager.denyRole(AppMConstants.EVERYONE_ROLE, resourcePath, ActionConstants.GET);
GenericArtifactManager artifactManager = AppManagerUtil.getArtifactManager(systemRegistry, appType); GenericArtifact appArtifact = artifactManager.getGenericArtifact(appId); String resourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + appArtifact.getPath());
String path = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + apiPath); boolean checkAuthorized = false;
GenericArtifactManager artifactManager = AppManagerUtil.getArtifactManager(systemRegistry, appType); GenericArtifact appArtifact = artifactManager.getGenericArtifact(appId); String resourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + appArtifact.getPath());
AppManagementException { String sourceResourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + sourceArtifactPath); RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + targetArtifactPath);
/** * This function is to set resource permissions based on its visibility * * @param artifactPath WebApp resource path * @throws org.wso2.carbon.appmgt.api.AppManagementException Throwing exception */ private void clearResourcePermissions(String artifactPath, APIIdentifier apiId) throws AppManagementException { try { String resourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + artifactPath); String tenantDomain = MultitenantUtils.getTenantDomain( AppManagerUtil.replaceEmailDomainBack(apiId.getProviderName())); if (!tenantDomain.equals(org.wso2.carbon.utils.multitenancy. MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { AuthorizationManager authManager = ServiceReferenceHolder.getInstance(). getRealmService().getTenantUserRealm(((UserRegistry) registry).getTenantId()). getAuthorizationManager(); authManager.clearResourceAuthorizations(resourcePath); } else { RegistryAuthorizationManager authorizationManager = new RegistryAuthorizationManager(ServiceReferenceHolder.getUserRealm()); authorizationManager.clearResourceAuthorizations(resourcePath); } } catch (UserStoreException e) { handleException("Error while adding role permissions to WebApp", e); } } /**
try { String resourcePath = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + artifactPath);
RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + AppMConstants.APPMGT_APPLICATION_DATA_LOCATION), RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + AppMConstants.APPMGT_MOBILE_REGISTRY_LOCATION),
/** * 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); } }
/** * 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 latestAPIsQueryPath = RegistryConstants.QUERIES_COLLECTION_PATH + "/latest-apis"; String resourcesByTag = RegistryConstants.QUERIES_COLLECTION_PATH + "/resource-by-tag"; String path = RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH + "/repository/components/org.wso2.carbon.governance"); if (username == null) {