registry.beginTransaction(); String hostResourcePath = CartridgeConstants.DomainMappingInfo.HOSTINFO; if (registry.resourceExists(hostResourcePath)) { Resource hostResource = registry.get(hostResourcePath); Collection hostInfoCollection; if(hostResource instanceof Collection){ Resource domainMapping = registry.get(path); String actualHostInRegistry = domainMapping.getProperty(CartridgeConstants.DomainMappingInfo.ACTUAL_HOST); if(actualHostInRegistry != null && actualHost.equalsIgnoreCase(actualHostInRegistry)){ registry.delete(path); registry.commitTransaction(); } catch (RegistryException e) { registry.rollbackTransaction(); log.error("Unable to remove the mapping", e); throw e;
private void addKeystores() throws RegistryException { Registry registry = SecurityServiceHolder.getRegistryService().getGovernanceSystemRegistry(); try { boolean transactionStarted = Transaction.isStarted(); if (!transactionStarted) { registry.beginTransaction(); } if (!registry.resourceExists(SecurityConstants.KEY_STORES)) { Collection kstores = registry.newCollection(); registry.put(SecurityConstants.KEY_STORES, kstores); Resource primResource = registry.newResource(); if (!registry.resourceExists(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE)) { registry.put(RegistryResources.SecurityManagement.PRIMARY_KEYSTORE_PHANTOM_RESOURCE, primResource); } } if (!transactionStarted) { registry.commitTransaction(); } } catch (Exception e) { registry.rollbackTransaction(); throw e; } }
private void deleteResource(String resource) throws RegistryException { registry.beginTransaction(); // Check whether the resource still exists for concurrent cases. if (registry.resourceExists(resource)) { registry.delete(resource); registry.commitTransaction(); } else { // Already deleted by another thread. Do nothing. registry.rollbackTransaction(); if (log.isDebugEnabled()) { log.debug("Confirmation code already deleted in path of resource : " + resource); } } } }
/** * Creates a collection in the given common location. * * @param commonLocation location to create the collection. * @throws RegistryException If fails to create a collection at given location. */ private void createCollection(String commonLocation) throws RegistryException { Registry systemRegistry = CommonUtil.getUnchrootedSystemRegistry(requestContext); //Creating a collection if not exists. if (!systemRegistry.resourceExists(commonLocation)) { systemRegistry.put(commonLocation, systemRegistry.newCollection()); } }
/** * Method to make an aspect to default. * @param path path of the resource * @param aspect the aspect to be removed. * @param registry registry instance to be used */ public static void setDefaultLifeCycle(String path, String aspect, Registry registry) throws RegistryException { Resource resource = registry.get(path); if(resource != null) { resource.setProperty("registry.LC.name", aspect); registry.put(path, resource); } }
public void updateDataRetentionPeriod(TimeRange timeRange) throws BAMException { try { Collection configCollection; if (registry.resourceExists(BAMRegistryResources.GLOBAL_CONFIG_PATH)) { configCollection = (Collection)registry.get(BAMRegistryResources.GLOBAL_CONFIG_PATH); } else { configCollection = registry.newCollection(); } configCollection.setProperty(BAMRegistryResources.DATA_RETENTION_PROPERTY, timeRange.toString()); registry.put(BAMRegistryResources.GLOBAL_CONFIG_PATH, configCollection); } catch (RegistryException e) { String msg = "Could not save the data retention policy in registry"; log.error(msg); throw new BAMException(msg, e); } }
private void persistTrustedService(String groupName, String serviceName, String trustedService, String certAlias) throws SecurityConfigException { Registry registry; String resourcePath; Resource resource; try { resourcePath = RegistryResources.SERVICE_GROUPS + groupName + RegistryResources.SERVICES + serviceName + "/trustedServices"; registry = getConfigSystemRegistry(); //TODO: Multitenancy if (registry != null) { if (registry.resourceExists(resourcePath)) { resource = registry.get(resourcePath); } else { resource = registry.newResource(); } if (resource.getProperty(trustedService) != null) { resource.removeProperty(trustedService); } resource.addProperty(trustedService, certAlias); registry.put(resourcePath, resource); } } catch (Exception e) { log.error("Error occured while adding trusted service for STS", e); throw new SecurityConfigException("Error occured while adding trusted service for STS", e); } }
public boolean unSubscribeMobileApp(String userId, String appId) throws AppManagementException { String path = "users/" + userId + "/subscriptions/mobileapp/" + appId; boolean isUnSubscribed = false; try { if (registry.resourceExists(path)) { registry.delete(path); isUnSubscribed = true; } } catch (org.wso2.carbon.registry.api.RegistryException e) { handleException("Error occurred while removing subscription registry resource for mobileapp with id :" + appId, e); } return isUnSubscribed; }
public static boolean createRegistryCollection(String path) throws MobileDeviceMgtPluginException { try { if (! MobileDeviceManagementUtil.getConfigurationRegistry().resourceExists(path)) { Resource resource = MobileDeviceManagementUtil.getConfigurationRegistry().newCollection(); MobileDeviceManagementUtil.getConfigurationRegistry().beginTransaction(); MobileDeviceManagementUtil.getConfigurationRegistry().put(path, resource); MobileDeviceManagementUtil.getConfigurationRegistry().commitTransaction(); } return true; } catch (MobileDeviceMgtPluginException e) { throw new MobileDeviceMgtPluginException( "Error occurred while creating a registry collection : " + e.getMessage(), e); } catch (RegistryException e) { throw new MobileDeviceMgtPluginException( "Error occurred while creating a registry collection : " + e.getMessage(), e); } }
/*** * Read the configuration file at server start up. * @param tenantId * @deprecated due to UI implementation. */ @Deprecated public static void initTokenExpiryTimesOfSps(int tenantId) { try { Registry registry = OAuth2ServiceComponentHolder.getRegistryService().getConfigSystemRegistry(tenantId); if (!registry.resourceExists(OAuthConstants.TOKEN_EXPIRE_TIME_RESOURCE_PATH)) { Resource resource = registry.newResource(); registry.put(OAuthConstants.TOKEN_EXPIRE_TIME_RESOURCE_PATH, resource); } } catch (RegistryException e) { log.error("Error while creating registry collection for :" + OAuthConstants.TOKEN_EXPIRE_TIME_RESOURCE_PATH, e); } }
public PublisherDataHolder retrieveSubscriber(String id, boolean returnSecrets) throws EntitlementException { try { if (registry.resourceExists(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER + RegistryConstants.PATH_SEPARATOR + id)) { Resource resource = registry.get(PDPConstants.ENTITLEMENT_POLICY_PUBLISHER + RegistryConstants.PATH_SEPARATOR + id); return new PublisherDataHolder(resource, returnSecrets); } } catch (RegistryException e) { log.error("Error while retrieving subscriber detail of id : " + id, e); throw new EntitlementException("Error while retrieving subscriber detail of id : " + id, e); } throw new EntitlementException("No Subscriber is defined for given Id"); }
private static boolean loadMetaData() throws ReportingException { try { RegistryService registryService = ReportingTemplateComponent.getRegistryService(); Registry registry = registryService.getConfigSystemRegistry(); registry.beginTransaction(); String location = ReportConstants.REPORT_META_DATA_PATH + ReportConstants.METADATA_FILE_NAME; Resource resource = null; if (registry.resourceExists(location)) { resource = registry.get(location); loadXML(resource); registry.commitTransaction(); return true; } else { registry.commitTransaction(); return false; } } catch (RegistryException e) { log.error("Exception occurred in loading the mete-data of reports", e); throw new ReportingException("Exception occurred in loading the mete-data of reports", e); } }
private void persistPolicy(AxisService service, OMElement policy, String policyID) throws RegistryException { //Registry registryToLoad = SecurityServiceHolder.getRegistryService().getConfigSystemRegistry(); Resource resource = registry.newResource(); resource.setContent(policy.toString()); String servicePath = getRegistryServicePath(service); String policyResourcePath = servicePath + RegistryResources.POLICIES + policyID; registry.put(policyResourcePath, resource); }
@Override public void createLink(RequestContext requestContext) throws RegistryException { String symlinkPath = requestContext.getResourcePath().getPath(); String targetResourcePath = requestContext.getTargetPath(); if (requestContext.getRegistry().resourceExists(targetResourcePath)) { Resource r = requestContext.getRegistry().get(targetResourcePath); r.addProperty("registry.resource.symlink.path", symlinkPath); requestContext.getRegistry().put(targetResourcePath, r); } }
public static void removeRegistryResource(String resourcePath) throws RegistryException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); Registry registry = ServiceHolder.getRegistryService().getConfigSystemRegistry(tenantId); if (registry.resourceExists(resourcePath)) { Resource resource = registry.get(resourcePath); registry.delete(resourcePath); } }
private static void removeEndpointDependencies(String servicePath, Registry registry) throws RegistryException { // update lock check removed from for loop to prevent the database lock Association[] associations = registry.getAllAssociations(servicePath); for (Association association : associations) { String path = association.getDestinationPath(); if (registry.resourceExists(path)) { Resource endpointResource = registry.get(path); if (CommonConstants.ENDPOINT_MEDIA_TYPE.equals(endpointResource.getMediaType())) { registry.removeAssociation(servicePath, path, CommonConstants.DEPENDS); registry.removeAssociation(path, servicePath, CommonConstants.USED_BY); } } } }
private void deleteChildRecursively(String path,Registry registry) throws RegistryException { Resource currentResource = registry.get(path); if((currentResource instanceof Collection) && ((Collection)currentResource).getChildCount() == 0 ){ String[] childPaths = ((Collection)currentResource).getChildren(); for (String childPath : childPaths) { deleteChildRecursively(childPath,registry); } registry.delete(path); } else { registry.delete(path); } } }
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); }
public boolean hasXmppSettings(String userId) { boolean hasSettings = false; try { hasSettings = registry.resourceExists(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId); } catch (RegistryException e) { log.error("Error when checking the availability of the user " + userId, e); } return hasSettings; } }
/** * Factory method creating a new <code>RegistryNode</code> from a node at a given Registry path. * * @param path Registry path of the node * @return A new instance representing the Registry node at <code>path</code> * @throws CmisObjectNotFoundException if <code>path</code> does not identify a Registry node * @throws CmisRuntimeException */ public RegistryObject getNode(String path) throws RegistryException { return create(repository.get(path)); }