Java Code Examples for org.wso2.carbon.registry.core.Registry#delete()

The following examples show how to use org.wso2.carbon.registry.core.Registry#delete() . 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: MigrateFrom200to210.java    From product-es with Apache License 2.0 6 votes vote down vote up
/**
 * This method removes the store.json file at config registry which will fix issue REGISTRY-3528
 * @param tenant tenant
 * @throws UserStoreException
 * @throws RegistryException
 * @throws XMLStreamException
 */
private void clean(Tenant tenant) throws UserStoreException, RegistryException, XMLStreamException {

    int tenantId = tenant.getId();
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenant.getDomain(), true);
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
        String adminName = ServiceHolder.getRealmService().getTenantUserRealm(tenantId).getRealmConfiguration()
                .getAdminUserName();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(adminName);
        ServiceHolder.getTenantRegLoader().loadTenantRegistry(tenantId);
        Registry registry = ServiceHolder.getRegistryService().getConfigUserRegistry(adminName,tenantId);
        if(registry.resourceExists(Constants.STORE_CONFIG_PATH)){
            registry.delete(Constants.STORE_CONFIG_PATH);
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }

}
 
Example 2
Source File: RegistryPolicyStoreManageModule.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deletePolicy(String policyIdentifier) {

    Registry registry;
    String policyPath;
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (policyIdentifier == null || policyIdentifier.trim().length() == 0) {
        return false;
    }

    try {
        registry = EntitlementServiceComponent.getRegistryService().
                getGovernanceSystemRegistry(tenantId);

        policyPath = policyStorePath + policyIdentifier;
        registry.delete(policyPath);
        return true;
    } catch (RegistryException e) {
        log.error(e);
        return false;
    }
}
 
Example 3
Source File: RegistryManager.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public synchronized void remove(String resourcePath) throws RegistryException {
    Registry registry = getRegistry();

    try {
        registry.beginTransaction();
        registry.delete(resourcePath);
        registry.commitTransaction();
    } catch (RegistryException e) {
        try {
            registry.rollbackTransaction();
        } catch (RegistryException e1) {
            if (log.isErrorEnabled()) {
                log.error("Could not rollback transaction", e1);
            }
        }
        throw new RegistryException("Could not remove registry resource: [resource-path] " + resourcePath, e);
    }
}
 
Example 4
Source File: RegistryManager.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public synchronized void remove(String resourcePath) throws RegistryException {
    Registry registry = getRegistry();

    try {
        registry.beginTransaction();
        registry.delete(resourcePath);
        registry.commitTransaction();
    } catch (RegistryException e) {
        try {
            registry.rollbackTransaction();
        } catch (RegistryException e1) {
            if (log.isErrorEnabled()) {
                log.error("Could not rollback transaction", e1);
            }
        }
        throw new RegistryException("Could not remove registry resource: [resource-path] " + resourcePath, e);
    }
}
 
Example 5
Source File: DefaultPolicyDataStore.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public void removePolicyData(String policyId) throws EntitlementException {

    Registry registry = EntitlementServiceComponent.
            getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId());
    try {
        String path = policyDataCollection + policyId;
        if (registry.resourceExists(path)) {
            registry.delete(path);
        }
    } catch (RegistryException e) {
        log.error("Error while deleting Policy data in policy store ", e);
        throw new EntitlementException("Error while deleting Policy data in policy store");
    }

}
 
Example 6
Source File: RegistryPolicyStoreManageModule.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deletePolicy(String policyIdentifier) {

    Registry registry;
    String policyPath;
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (policyIdentifier == null || policyIdentifier.trim().length() == 0) {
        return false;
    }

    try {
        registry = EntitlementServiceComponent.getRegistryService().
                getGovernanceSystemRegistry(tenantId);

        policyPath = policyStorePath + policyIdentifier;
        registry.delete(policyPath);
        return true;
    } catch (RegistryException e) {
        log.error(e);
        return false;
    }
}
 
Example 7
Source File: RegistryBasedTrustedServiceStore.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Remove the given trusted service with realmName
 *
 * @param realmName - the realm of the service
 * @throws Exception
 */
public void removeTrustedService(String realmName) throws Exception {
    realmName = replaceSlashWithConstantString(realmName);
    try {
        Registry registry = IdentityPassiveSTSServiceComponent.getConfigSystemRegistry();
        String trustedServicePath = registryTrustedServicePath + realmName;
        if (registry.resourceExists(trustedServicePath)) {
            registry.delete(trustedServicePath);
        } else {
            throw new Exception(realmName + " ,No such trusted service exists to delete.");
        }

    } catch (RegistryException e) {
        String error = "Error occurred when removing a trusted service due to error in accessing registry.";
        throw new Exception(error, e);
    }
}
 
Example 8
Source File: StratosApiV41Utils.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
private static void clearMetadata(String applicationId) throws RestAPIException {

        PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

        String resourcePath = METADATA_REG_PATH + applicationId;
        Registry registry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext()
                .getRegistry(RegistryType.SYSTEM_GOVERNANCE);
        try {
            registry.beginTransaction();
            if (registry.resourceExists(resourcePath)) {
                registry.delete(resourcePath);
                log.info(String.format("Application metadata removed: [application-id] %s", applicationId));
            }
            registry.commitTransaction();
        } catch (RegistryException e) {
            try {
                registry.rollbackTransaction();
            } catch (RegistryException e1) {
                log.error("Could not rollback transaction", e1);
            }
            throw new RestAPIException(
                    String.format("Application metadata removed: [application-id] %s", applicationId), e);
        }
    }
 
Example 9
Source File: RegistryManager.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void remove(String resourcePath) throws RegistryException {
    Registry registry = getRegistry();

    try {
        registry.beginTransaction();
        registry.delete(resourcePath);
        registry.commitTransaction();
    } catch (RegistryException e) {
        try {
            registry.rollbackTransaction();
        } catch (RegistryException e1) {
            if (log.isErrorEnabled()) {
                log.error("Could not rollback transaction", e1);
            }
        }
        throw new RegistryException("Could not remove registry resource: [resource-path] " + resourcePath, e);
    }
}
 
Example 10
Source File: RegistryRecoveryDataStore.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void deleteOldResourcesIfFound(Registry registry, String userName, String secretKeyPath) {
    try {
        if (registry.resourceExists(secretKeyPath.toLowerCase())) {
            Collection collection = (Collection) registry.get(secretKeyPath.toLowerCase());
            String[] resources = collection.getChildren();
            for (String resource : resources) {
                String[] splittedResource = resource.split("___");
                if (splittedResource.length == 3) {
                    //PRIMARY USER STORE
                    if (resource.contains("___" + userName + "___")) {
                        registry.delete(resource);
                    }
                } else if (splittedResource.length == 2) {
                    //SECONDARY USER STORE. Resource is a collection.
                    deleteOldResourcesIfFound(registry, userName, resource);
                }
            }
        }
    } catch (RegistryException e) {
        log.error("Error while deleting the old confirmation code \n" + e);
    }

}
 
Example 11
Source File: ChallengeQuestionProcessor.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param questionDTOs
 * @throws IdentityException
 */
public void setChallengeQuestions(ChallengeQuestionDTO[] questionDTOs) throws IdentityException {
    Registry registry = null;
    try {
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        registry = IdentityMgtServiceComponent.getRegistryService().getConfigSystemRegistry(tenantId);

        if (!registry.resourceExists(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH)) {
            Collection securityQuestionResource = registry.newCollection();
            registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH, securityQuestionResource);
        }
        Resource identityMgtResource = registry.get(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH);
        if (identityMgtResource != null) {
            String questionCollectionPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS;
            if (registry.resourceExists(questionCollectionPath)) {
                registry.delete(questionCollectionPath);
            }

            Collection questionCollection = registry.newCollection();
            registry.put(questionCollectionPath, questionCollection);

            for (int i = 0; i < questionDTOs.length; i++) {
                Resource resource = registry.newResource();
                resource.addProperty("question", questionDTOs[i].getQuestion());
                resource.addProperty("isPromoteQuestion", String.valueOf(questionDTOs[i].isPromoteQuestion()));
                resource.addProperty("questionSetId", questionDTOs[i].getQuestionSetId());
                registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS +
                        RegistryConstants.PATH_SEPARATOR + "question" + i +
                        RegistryConstants.PATH_SEPARATOR, resource);
            }
        }
    } catch (RegistryException e) {
        throw IdentityException.error("Error while setting challenge question.", e);
    }

}
 
Example 12
Source File: MetadataApiRegistry.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
/**
 * Delete the resource identified by the applicationId, if exist.
 *
 * @param applicationId ID of the application.
 * @return True if resource exist and able to delete, else false.
 * @throws RegistryException, MetadataException
 */
public boolean deleteApplicationProperties(String applicationId) throws RegistryException, MetadataException {
    if (StringUtils.isBlank(applicationId)) {
        throw new IllegalArgumentException("Application ID can not be null");
    }
    Registry registry = getRegistry();
    String resourcePath = mainResource + applicationId;

    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)) {
            registry.delete(resourcePath);
            log.info(String.format("Registry properties removed for [application-id] %s", applicationId));
        }
        return true;
    } catch (Exception e) {
        throw new MetadataException(
                String.format("Could not remove registry resource: [resource-path] %s", resourcePath), e);
    } finally {
        try {
            releaseWriteLock(applicationId);
        } catch (MetadataException ignored) {
        }
    }
}
 
Example 13
Source File: RemoteTaskUtils.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public static void removeRemoteTaskMapping(String remoteTaskId) throws TaskException {
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
                MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
        Registry registry = RegistryBasedTaskRepository.getRegistry();
        registry.delete(resourcePathFromRemoteTaskId(remoteTaskId));
    } catch (Exception e) {
        throw new TaskException(e.getMessage(), Code.UNKNOWN, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 14
Source File: RegistryCleanUpService.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Check if resource has expired and delete.
 *
 * @param registry Registry instance to use.
 * @param resourcePath Path of resource to be deleted.
 * @throws RegistryException
 */
private static void checkAndDeleteRegistryResource (Registry registry, String resourcePath) throws
        RegistryException {

    Resource resource = registry.get(resourcePath);
    long currentEpochTime = System.currentTimeMillis();
    long resourceExpireTime = Long.parseLong(resource.getProperty(EXPIRE_TIME_PROPERTY));
    if (currentEpochTime > resourceExpireTime) {

        registry.delete(resource.getId());
    }
}
 
Example 15
Source File: SimplePAPStatusDataHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private synchronized void deletedPersistedData(String path) throws EntitlementException {

        Registry registry = null;
        int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        try {
            registry = EntitlementServiceComponent.getRegistryService().
                    getGovernanceSystemRegistry(tenantId);
            if (registry.resourceExists(path)) {
                registry.delete(path);
            }
        } catch (RegistryException e) {
            log.error(e);
            throw new EntitlementException("Error while persisting policy status", e);
        }
    }
 
Example 16
Source File: SimplePAPStatusDataHandler.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private synchronized void deletedPersistedData(String path) throws EntitlementException {

        Registry registry = null;
        int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        try {
            registry = EntitlementServiceComponent.getRegistryService().
                    getGovernanceSystemRegistry(tenantId);
            if (registry.resourceExists(path)) {
                registry.delete(path);
            }
        } catch (RegistryException e) {
            log.error(e);
            throw new EntitlementException("Error while persisting policy status", e);
        }
    }
 
Example 17
Source File: RegistryCleanUpService.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Check if resource has expired and delete.
 *
 * @param registry Registry instance to use.
 * @param resourcePath Path of resource to be deleted.
 * @throws RegistryException
 */
private static void checkAndDeleteRegistryResource (Registry registry, String resourcePath) throws
        RegistryException {

    Resource resource = registry.get(resourcePath);
    long currentEpochTime = System.currentTimeMillis();
    long resourceExpireTime = Long.parseLong(resource.getProperty(EXPIRE_TIME_PROPERTY));
    if (currentEpochTime > resourceExpireTime) {

        registry.delete(resource.getId());
    }
}
 
Example 18
Source File: ChallengeQuestionProcessor.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param questionDTOs
 * @throws IdentityException
 */
public void setChallengeQuestions(ChallengeQuestionDTO[] questionDTOs) throws IdentityException {
    Registry registry = null;
    try {
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        registry = IdentityMgtServiceComponent.getRegistryService().getConfigSystemRegistry(tenantId);

        if (!registry.resourceExists(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH)) {
            Collection securityQuestionResource = registry.newCollection();
            registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH, securityQuestionResource);
        }
        Resource identityMgtResource = registry.get(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH);
        if (identityMgtResource != null) {
            String questionCollectionPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS;
            if (registry.resourceExists(questionCollectionPath)) {
                registry.delete(questionCollectionPath);
            }

            Collection questionCollection = registry.newCollection();
            registry.put(questionCollectionPath, questionCollection);

            for (int i = 0; i < questionDTOs.length; i++) {
                Resource resource = registry.newResource();
                resource.addProperty("question", questionDTOs[i].getQuestion());
                resource.addProperty("isPromoteQuestion", String.valueOf(questionDTOs[i].isPromoteQuestion()));
                resource.addProperty("questionSetId", questionDTOs[i].getQuestionSetId());
                registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_QUESTIONS +
                        RegistryConstants.PATH_SEPARATOR + "question" + i +
                        RegistryConstants.PATH_SEPARATOR, resource);
            }
        }
    } catch (RegistryException e) {
        throw IdentityException.error("Error while setting challenge question.", e);
    }

}
 
Example 19
Source File: DefaultPolicyDataStore.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Override
public void removePolicyData(String policyId) throws EntitlementException {

    Registry registry = getGovernanceRegistry();
    try {
        String path = policyDataCollection + policyId;
        if (registry.resourceExists(path)) {
            registry.delete(path);
        }
    } catch (RegistryException e) {
        log.error("Error while deleting Policy data in policy store ", e);
        throw new EntitlementException("Error while deleting Policy data in policy store");
    }

}