Java Code Examples for org.wso2.carbon.registry.core.Resource#removeProperty()

The following examples show how to use org.wso2.carbon.registry.core.Resource#removeProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParameterDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @param parameterDO
 * @throws IdentityException
 */
public void removeParameter(ParameterDO parameterDO) throws IdentityException {
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Removing parameter");
    }

    try {
        path = IdentityRegistryResources.CARD_ISSUER;
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
            if (resource != null) {
                resource.removeProperty(parameterDO.getName());
                registry.put(path, resource);
            }
        }
    } catch (RegistryException e) {
        log.error("Error while removing parameter", e);
        throw IdentityException.error("Error while removing parameter", e);
    }
}
 
Example 2
Source File: ApplicationManagementServiceImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Remove trusted service
 *
 * @param groupName      Group name
 * @param serviceName    Service name
 * @param trustedService Trusted service name
 * @throws org.wso2.carbon.registry.api.RegistryException
 */
private void removeTrustedService(String groupName, String serviceName,
                                  String trustedService) throws RegistryException {

    String resourcePath = RegistryResources.SERVICE_GROUPS + groupName +
                RegistryResources.SERVICES + serviceName + "/trustedServices";
    Registry registry = getConfigSystemRegistry();
    if (registry != null) {
        if (registry.resourceExists(resourcePath)) {
            Resource resource = registry.get(resourcePath);
            if (resource.getProperty(trustedService) != null) {
                resource.removeProperty(trustedService);
            }
            registry.put(resourcePath, resource);
        }
    }
}
 
Example 3
Source File: STSAdminServiceImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void removeTrustedService(String groupName, String serviceName, String trustedService)
        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 && registry.resourceExists(resourcePath)) {
            resource = registry.get(resourcePath);
            if (resource.getProperty(trustedService) != null) {
                resource.removeProperty(trustedService);
            }
            registry.put(resourcePath, resource);
        }
    } catch (Exception e) {
        log.error("Error occured while removing trusted service for STS", e);
        throw new SecurityConfigException("Error occured while adding trusted service for STS",
                e);
    }
}
 
Example 4
Source File: ParameterDAO.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param parameterDO
 * @throws IdentityException
 */
public void removeParameter(ParameterDO parameterDO) throws IdentityException {
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Removing parameter");
    }

    try {
        path = IdentityRegistryResources.CARD_ISSUER;
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
            if (resource != null) {
                resource.removeProperty(parameterDO.getName());
                registry.put(path, resource);
            }
        }
    } catch (RegistryException e) {
        log.error("Error while removing parameter", e);
        throw IdentityException.error("Error while removing parameter", e);
    }
}
 
Example 5
Source File: GatewayUtils.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the given registry property from the given tenant registry path
 *
 * @param propertyName property name
 * @param path         resource path
 * @param tenantDomain
 * @throws AxisFault
 */
public static void deleteRegistryProperty(String propertyName, String path, String tenantDomain)
        throws AxisFault {

    try {
        UserRegistry registry = getRegistry(tenantDomain);
        PrivilegedCarbonContext.startTenantFlow();
        if (tenantDomain != null && StringUtils.isNotEmpty(tenantDomain)) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
        } else {
            PrivilegedCarbonContext.getThreadLocalCarbonContext()
                    .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
        }
        Resource resource = registry.get(path);
        if (resource != null && resource.getProperty(propertyName) != null) {
            resource.removeProperty(propertyName);
            registry.put(resource.getPath(), resource);
            resource.discard();
        }
    } catch (RegistryException | APIManagementException e) {
        String msg = "Failed to delete secure endpoint password alias " + e.getMessage();
        throw new AxisFault(msg, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 6
Source File: OpenIDAdminDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Create or update the OpenID admin.
 *
 * @param opAdmin openID admin
 * @throws IdentityException if error occurs while creating or updating the OpenID admin
 */
public void createOrUpdate(OpenIDAdminDO opAdmin) throws IdentityException {
    String path = null;
    Resource resource = null;

    try {
        path = IdentityRegistryResources.OPEN_ID_ADMIN_SETTINGS;
        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Creating new openid admin");
            }
            resource = registry.newResource();
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Updating openid admin");
            }
            resource = registry.get(path);
            resource.removeProperty(IdentityRegistryResources.SUB_DOMAIN);
            resource.removeProperty(IdentityRegistryResources.OPENID_PATTERN);
        }
        resource.addProperty(IdentityRegistryResources.SUB_DOMAIN, opAdmin.getSubDomain());
        resource.addProperty(IdentityRegistryResources.OPENID_PATTERN, opAdmin
                .getTenantOpenIDPattern());
        registry.put(path, resource);
    } catch (RegistryException e) {
        log.error("Error while creating/updating openid admin", e);
        throw IdentityException.error("Error while creating/updating openid admin", e);
    }
}
 
Example 7
Source File: ParameterDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param parameterDO
 * @throws IdentityException
 */
public void createOrUpdateParameter(ParameterDO parameterDO) throws IdentityException {
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Creating or updating parameter");
    }

    try {
        path = IdentityRegistryResources.CARD_ISSUER;
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
        } else {
            resource = registry.newResource();
        }

        if (resource.getProperty(parameterDO.getName()) != null) {
            resource.removeProperty(parameterDO.getName());
        }

        resource.addProperty(parameterDO.getName(), parameterDO.getValue());
        registry.put(path, resource);
    } catch (RegistryException e) {
        log.error("Error while creating or updating parameter", e);
        throw IdentityException.error("Error while creating or updating parameter", e);
    }
}
 
Example 8
Source File: SecureVaultPasswordMigrationClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * remove secure vault password property
 *
 * @param name property name
 */
private void removeProperty(String name) {
    log.info("Removing old passwords.");
    try {
        Resource resource = userRegistry.get(SECURE_VAULT_PATH);
        resource.removeProperty(name);
        userRegistry.put(resource.getPath(), resource);
        resource.discard();
    } catch (RegistryException e) {
        throw new MigrationClientException("Error occurred while removing property", e);
    }
}
 
Example 9
Source File: STSAdminServiceImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 10
Source File: OpenIDAdminDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param rp
 * @throws IdentityException
 */
public void createOrUpdate(OpenIDAdminDO opAdmin) throws IdentityException {
    String path = null;
    Resource resource = null;

    try {
        path = IdentityRegistryResources.OPEN_ID_ADMIN_SETTINGS;
        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Creating new openid admin");
            }
            resource = registry.newResource();
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Updating openid admin");
            }
            resource = registry.get(path);
            resource.removeProperty(IdentityRegistryResources.SUB_DOMAIN);
            resource.removeProperty(IdentityRegistryResources.OPENID_PATTERN);
        }
        resource.addProperty(IdentityRegistryResources.SUB_DOMAIN, opAdmin.getSubDomain());
        resource.addProperty(IdentityRegistryResources.OPENID_PATTERN, opAdmin
                .getTenantOpenIDPattern());
        registry.put(path, resource);
    } catch (RegistryException e) {
        log.error("Error while creating/updating openid admin", e);
        throw IdentityException.error("Error while creating/updating openid admin", e);
    }
}
 
Example 11
Source File: ParameterDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param parameterDO
 * @throws IdentityException
 */
public void createOrUpdateParameter(ParameterDO parameterDO) throws IdentityException {
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Creating or updating parameter");
    }

    try {
        path = IdentityRegistryResources.CARD_ISSUER;
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
        } else {
            resource = registry.newResource();
        }

        if (resource.getProperty(parameterDO.getName()) != null) {
            resource.removeProperty(parameterDO.getName());
        }

        resource.addProperty(parameterDO.getName(), parameterDO.getValue());
        registry.put(path, resource);
    } catch (RegistryException e) {
        log.error("Error while creating or updating parameter", e);
        throw IdentityException.error("Error while creating or updating parameter", e);
    }
}
 
Example 12
Source File: RegistrySubscriptionManager.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void unSubscribe(String subscriptionID) throws EventBrokerException {
    try {
        UserRegistry userRegistry =
                this.registryService.getGovernanceSystemRegistry(EventBrokerHolder.getInstance()
                                                                         .getTenantId());
        String fullPath = this.indexStoragePath;
        if (userRegistry.resourceExists(fullPath)) {
            Resource topicIndexResource = userRegistry.get(fullPath);

            String topicName = topicIndexResource.getProperty(subscriptionID);
            // delete the subscriptions resource
            // if the registry is read only there can be situations where the the subscriptions
            // is not saved to registry and hence the topic name
            if (topicName != null) {
                String resourcePath =  getResourcePath(subscriptionID, topicName);
                if (userRegistry.resourceExists(resourcePath)) {
                    userRegistry.delete(resourcePath);
                }
                String jMSResourcePath =  getJMSSubResourcePath(subscriptionID, topicName);
                if (userRegistry.resourceExists(jMSResourcePath)) {
                    userRegistry.delete(jMSResourcePath);
                }
            }

            topicIndexResource.removeProperty(subscriptionID);

            userRegistry.put(fullPath, topicIndexResource);
        }

    } catch (RegistryException e) {
        throw new EventBrokerException("Cannot access the registry ", e);
    }
}
 
Example 13
Source File: MetadataApiRegistry.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public boolean removePropertyFromApplication(String applicationId, String propertyKey)
        throws RegistryException, MetadataException {
    Registry registry = getRegistry();
    String resourcePath = mainResource + applicationId;
    Resource nodeResource;

    try {
        acquireWriteLock(applicationId);
        // We are using only super tenant registry to persist
        PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        if (registry.resourceExists(resourcePath)) {
            nodeResource = registry.get(resourcePath);
            if (nodeResource.getProperty(propertyKey) == null) {
                log.info(String.format("Registry property not found: [application-id] %s [key] %s ", applicationId,
                        propertyKey));
                return false;
            } else {
                nodeResource.removeProperty(propertyKey);
                registry.put(resourcePath, nodeResource);
            }
        } else {
            log.error("Registry resource not not found at " + resourcePath);
            return false;
        }

        log.info(String.format("Registry property removed: [application-id] %s, [key] %s", applicationId,
                propertyKey));
        return true;
    } catch (Exception e) {
        throw new MetadataException(
                String.format("Could not remove registry resource: [resource-path] %s, [key] %s", resourcePath,
                        propertyKey), e);
    } finally {
        try {
            releaseWriteLock(applicationId);
        } catch (MetadataException ignored) {
        }
    }
}