Java Code Examples for org.wso2.carbon.registry.core.exceptions.RegistryException

The following examples show how to use org.wso2.carbon.registry.core.exceptions.RegistryException. These examples are extracted from open source projects. 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
/**
 * This helps to find resources un a recursive manner
 *
 * @param node           attribute value node
 * @param parentResource parent resource Name
 * @return child resource set
 * @throws RegistryException throws
 */
private EntitlementTreeNodeDTO getChildResources(EntitlementTreeNodeDTO node,
                                                 String parentResource) throws RegistryException {

    if (registry.resourceExists(parentResource)) {
        String[] resourcePath = parentResource.split("/");
        EntitlementTreeNodeDTO childNode =
                new EntitlementTreeNodeDTO(resourcePath[resourcePath.length - 1]);
        node.addChildNode(childNode);
        Resource root = registry.get(parentResource);
        if (root instanceof Collection) {
            Collection collection = (Collection) root;
            String[] resources = collection.getChildren();
            for (String resource : resources) {
                getChildResources(childNode, resource);
            }
        }
    }
    return node;
}
 
Example 2
Source Project: carbon-identity-framework   Source File: PAPPolicyStore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This returns given policy as Registry resource
 *
 * @param policyId   policy id
 * @param collection
 * @return policy as Registry resource
 * @throws EntitlementException throws, if fails
 */
public Resource getPolicy(String policyId, String collection) throws EntitlementException {
    String path = null;

    if (log.isDebugEnabled()) {
        log.debug("Retrieving entitlement policy");
    }

    try {
        path = collection + policyId;

        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Trying to access an entitlement policy which does not exist");
            }
            return null;
        }
        return registry.get(path);
    } catch (RegistryException e) {
        log.error("Error while retrieving entitlement policy " + policyId + " PAP policy store", e);
        throw new EntitlementException("Error while retrieving entitlement policy " + policyId
                                       + " PAP policy store");
    }
}
 
Example 3
Source Project: carbon-identity-framework   Source File: PAPPolicyStore.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param policyId
 * @throws EntitlementException
 */
public void removePolicy(String policyId) throws EntitlementException {
    String path = null;

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

    try {
        path = PDPConstants.ENTITLEMENT_POLICY_PAP + policyId;
        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Trying to access an entitlement policy which does not exist");
            }
            return;
        }
        registry.delete(path);
    } catch (RegistryException e) {
        log.error("Error while removing entitlement policy " + policyId + " from PAP policy store", e);
        throw new EntitlementException("Error while removing policy " + policyId + " from PAP policy store");
    }
}
 
Example 4
Source Project: carbon-identity-framework   Source File: PolicyPublisher.java    License: Apache License 2.0 6 votes vote down vote up
public void deleteSubscriber(String subscriberId) throws EntitlementException {

        String subscriberPath;

        if (subscriberId == null) {
            log.error("Subscriber Id can not be null");
            throw new EntitlementException("Subscriber Id can not be null");
        }

        if (EntitlementConstants.PDP_SUBSCRIBER_ID.equals(subscriberId.trim())) {
            log.error("Can not delete PDP publisher");
            throw new EntitlementException("Can not delete PDP publisher");
        }

        try {
            subscriberPath = PDPConstants.ENTITLEMENT_POLICY_PUBLISHER +
                    RegistryConstants.PATH_SEPARATOR + subscriberId;

            if (registry.resourceExists(subscriberPath)) {
                registry.delete(subscriberPath);
            }
        } catch (RegistryException e) {
            log.error("Error while deleting subscriber details", e);
            throw new EntitlementException("Error while deleting subscriber details", e);
        }
    }
 
Example 5
Source Project: carbon-identity-framework   Source File: PolicyPublisher.java    License: Apache License 2.0 6 votes vote down vote up
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");
    }
 
Example 6
/**
 * This returns given policy as Registry resource
 *
 * @param policyId policy id
 * @return policy as Registry resource
 * @throws EntitlementException throws, if fails
 */
private Resource getPolicyResource(String policyId) throws EntitlementException {
    String path = null;

    if (log.isDebugEnabled()) {
        log.debug("Retrieving entitlement policy");
    }

    try {
        path = policyStorePath + policyId;

        if (!registry.resourceExists(path)) {
            if (log.isDebugEnabled()) {
                log.debug("Trying to access an entitlement policy which does not exist");
            }
            return null;
        }
        return registry.get(path);
    } catch (RegistryException e) {
        log.error("Error while retrieving entitlement policy : " + policyId, e);
        throw new EntitlementException("Error while retrieving entitlement policy : " + policyId, e);
    }
}
 
Example 7
@Override
public boolean isPolicyExist(String policyId) {

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

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

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

        policyPath = policyStorePath + policyId;
        return registry.resourceExists(policyPath);
    } catch (RegistryException e) {
        //ignore
        return false;
    }
}
 
Example 8
@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 9
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;
    }
}
 
Example 10
@Override
public Resource getIdentityResource(String path,
                                    String tenantDomain) throws IdentityRuntimeException {
    startTenantFlow(tenantDomain);
    try {
        Registry registry = getRegistryForTenant(tenantDomain);
        Resource resource = null;

        if (registry.resourceExists(path)) {
            resource = registry.get(path);
        }
        return resource;
    } catch (RegistryException e) {
        String errorMsg = String.format(ERROR_GET_RESOURCE, path, tenantDomain);
        throw IdentityRuntimeException.error(errorMsg, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 11
@Override
public void putIdentityResource(Resource identityResource,
                                String path,
                                String tenantDomain) throws IdentityRuntimeException {
    startTenantFlow(tenantDomain);
    try {
        Registry registry = getRegistryForTenant(tenantDomain);
        registry.put(path, identityResource);
        if (log.isDebugEnabled()) {
            log.debug(String.format(MSG_RESOURCE_PERSIST, path, tenantDomain));
        }
    } catch (RegistryException e) {
        String errorMsg = String.format(ERROR_PERSIST_RESOURCE, tenantDomain, path);
        throw IdentityRuntimeException.error(errorMsg, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 12
public SAMLSSOServiceProviderDO[] getServiceProviders() throws IdentityException {
    List<SAMLSSOServiceProviderDO> serviceProvidersList = new ArrayList<>();
    try {
        if (registry.resourceExists(IdentityRegistryResources.SAML_SSO_SERVICE_PROVIDERS)) {
            Resource samlSSOServiceProvidersResource = registry.get(IdentityRegistryResources
                    .SAML_SSO_SERVICE_PROVIDERS);
            if (samlSSOServiceProvidersResource instanceof Collection) {
                Collection samlSSOServiceProvidersCollection = (Collection) samlSSOServiceProvidersResource;
                String[] resources = samlSSOServiceProvidersCollection.getChildren();
                for (String resource : resources) {
                    getChildResources(resource, serviceProvidersList);
                }
            }
        }
    } catch (RegistryException e) {
        log.error("Error reading Service Providers from Registry", e);
        throw IdentityException.error("Error reading Service Providers from Registry", e);
    }
    return serviceProvidersList.toArray(new SAMLSSOServiceProviderDO[serviceProvidersList.size()]);
}
 
Example 13
/**
 * This helps to find resources in a recursive manner.
 *
 * @param parentResource      parent resource Name.
 * @param serviceProviderList child resource list.
 * @throws RegistryException
 */
private void getChildResources(String parentResource, List<SAMLSSOServiceProviderDO>
        serviceProviderList) throws RegistryException {

    if (registry.resourceExists(parentResource)) {
        Resource resource = registry.get(parentResource);
        if (resource instanceof Collection) {
            Collection collection = (Collection) resource;
            String[] resources = collection.getChildren();
            for (String res : resources) {
                getChildResources(res, serviceProviderList);
            }
        } else {
            serviceProviderList.add(resourceToObject(resource));
        }
    }
}
 
Example 14
Source Project: carbon-identity-framework   Source File: XMPPSettingsDAO.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * retrieve XMPP Settings of a user by providing the userId
 *
 * @param userId
 * @return
 */
public XMPPSettingsDO getXmppSettings(String userId) {

    XMPPSettingsDO xmppSettings = null;

    try {
        if (registry.resourceExists(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId)) {
            xmppSettings = resourceToObject(registry
                    .get(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId));
        }

    } catch (RegistryException e) {
        log.error("Cannot retrieve the XMPP Settings for the user " + userId, e);
    }
    return xmppSettings;
}
 
Example 15
Source Project: carbon-identity-framework   Source File: XMPPSettingsDAO.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether the given user has enabled XMPP based multifactor auth.
 *
 * @param userId
 * @return
 */
public boolean isXmppSettingsEnabled(String userId) {

    boolean isEnabled = false;
    XMPPSettingsDO xmppSettings;
    try {
        if (registry.resourceExists(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId)) {
            xmppSettings = resourceToObject(registry
                    .get(IdentityRegistryResources.XMPP_SETTINGS_ROOT + userId));
            isEnabled = xmppSettings.isXmppEnabled();
        }
    } catch (RegistryException e) {
        log.error("Error when checking the availability of the user " + userId, e);
    }

    return isEnabled;
}
 
Example 16
Source Project: product-ei   Source File: RegistryDataManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Encrypt the registry properties by new algorithm and update
 *
 * @param registry
 * @param resource
 * @param properties
 * @throws RegistryException
 * @throws CryptoException
 */
private void updateRegistryProperties(Registry registry, String resource, List<String> properties)
        throws RegistryException, CryptoException {
    if (registry == null || StringUtils.isEmpty(resource) || CollectionUtils.isEmpty(properties)) {
        return;
    }
    if (registry.resourceExists(resource)) {
        try {
            registry.beginTransaction();
            Resource resourceObj = registry.get(resource);
            for (String encryptedPropertyName : properties) {
                String oldValue = resourceObj.getProperty(encryptedPropertyName);
                String newValue = Utility.getNewEncryptedValue(oldValue);
                if (StringUtils.isNotEmpty(newValue)) {
                    resourceObj.setProperty(encryptedPropertyName, newValue);
                }
            }
            registry.put(resource, resourceObj);
            registry.commitTransaction();
        } catch (RegistryException e) {
            registry.rollbackTransaction();
            log.error("Unable to update the registry resource", e);
            throw e;
        }
    }
}
 
Example 17
/**
 * Returns oAuth consumer secret for a give consumer key.
 *
 * @param consumerKey consumer key
 * @return oAuth consumer secret
 * @throws IdentityException if error occurs while obtaining the consumer secret
 */
public String getOAuthConsumerSecret(String consumerKey) throws IdentityException {
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Retreiving user for OAuth consumer key  " + consumerKey);
    }

    try {
        path = RegistryConstants.PROFILES_PATH + consumerKey;
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
            return resource.getProperty(IdentityRegistryResources.OAUTH_CONSUMER_PATH);
        } else {
            return null;
        }
    } catch (RegistryException e) {
        log.error("Error while retreiving user for OAuth consumer key  " + consumerKey, e);
        throw IdentityException.error("Error while retreiving user for OAuth consumer key  "
                + consumerKey, e);
    }
}
 
Example 18
Source Project: carbon-identity-framework   Source File: OpenIDUserDAO.java    License: Apache License 2.0 6 votes vote down vote up
public String getUserIdForAssociation(String openId) {

        try {
            if (registry
                    .resourceExists(IdentityRegistryResources.OPENID_SIGN_UP
                            + getOpenIdModified(openId))) {
                return resourceToObject(
                        registry.get(IdentityRegistryResources.OPENID_SIGN_UP
                                + getOpenIdModified(openId))).getUserName();
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Unable to find an Sign-Up for " + openId);
                }
            }
        } catch (RegistryException e) {
            log.error("Error retrieving a resource from Registry", e);
        }

        return null;
    }
 
Example 19
Source Project: carbon-identity-framework   Source File: OpenIDAdminDAO.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve OpenID admin for a tenant.
 *
 * @return open id admin of the tenant
 * @throws IdentityException if error occurs while retrieving the OpenID admin
 */
public OpenIDAdminDO getOpenIDAdminDO() throws IdentityException {
    OpenIDAdminDO opdo = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Retrieving OpenID admin for tenant");
    }
    try {
        if (registry.resourceExists(IdentityRegistryResources.OPEN_ID_ADMIN_SETTINGS)) {
            resource = registry.get(IdentityRegistryResources.OPEN_ID_ADMIN_SETTINGS);
            return resourceToObject(resource);
        }
    } catch (RegistryException e) {
        log.error("Error while retreiving openid admin", e);
        throw IdentityException.error("Error while retreiving openid admin", e);
    }
    return opdo;
}
 
Example 20
Source Project: carbon-identity-framework   Source File: ParameterDAO.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param paramName
 * @return
 * @throws IdentityException
 */
public ParameterDO getParameter(String paramName) throws IdentityException {
    ParameterDO param = null;
    String path = null;
    Resource resource = null;

    if (log.isDebugEnabled()) {
        log.debug("Retrieving parameter " + paramName);
    }

    try {
        path = IdentityRegistryResources.CARD_ISSUER;
        param = new ParameterDO();
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
            if (resource != null) {
                param.setName(paramName);
                param.setValue(resource.getProperty(paramName));
            }
        }
    } catch (RegistryException e) {
        log.error("Error while retrieving parameter " + paramName, e);
        throw IdentityException.error("Error while retrieving parameter " + paramName, e);
    }
    return param;
}
 
Example 21
Source Project: carbon-identity-framework   Source File: ParameterDAO.java    License: 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 22
Source Project: carbon-identity-framework   Source File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * gets no of verified user challenges
 *
 * @param userDTO bean class that contains user and tenant Information
 * @return no of verified challenges
 * @throws IdentityException if fails
 */
public static int getVerifiedChallenges(UserDTO userDTO) throws IdentityException {

    int noOfChallenges = 0;

    try {
        UserRegistry registry = IdentityMgtServiceComponent.getRegistryService().
                getConfigSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
        String identityKeyMgtPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_CHALLENGES +
                RegistryConstants.PATH_SEPARATOR + userDTO.getUserId() +
                RegistryConstants.PATH_SEPARATOR + userDTO.getUserId();

        Resource resource;
        if (registry.resourceExists(identityKeyMgtPath)) {
            resource = registry.get(identityKeyMgtPath);
            String property = resource.getProperty(IdentityMgtConstants.VERIFIED_CHALLENGES);
            if (property != null) {
                return Integer.parseInt(property);
            }
        }
    } catch (RegistryException e) {
        log.error("Error while processing userKey", e);
    }

    return noOfChallenges;
}
 
Example 23
Source Project: carbon-identity-framework   Source File: CaptchaUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void setAnonAuthorization(String path, UserRealm userRealm)
        throws RegistryException {

    if (userRealm == null) {
        return;
    }

    try {
        AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
        String everyoneRole = CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME;

        accessControlAdmin.authorizeRole(everyoneRole, path, ActionConstants.GET);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
        accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

    } catch (UserStoreException e) {
        String msg = "Could not set authorizations for the " + path + ".";
        log.error(msg, e);
        throw new RegistryException(msg);
    }
}
 
Example 24
Source Project: product-ei   Source File: RegistryTaskDeletionClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Default constructor
 */
public RegistryTaskDeletionClient() {
    String adminUserName = MigrationClientConfig.getInstance()
                                                .getMigrationConfiguration()
                                                .getProperty(MigrationConstants.ADMIN_USERNAME);

    if (adminUserName.isEmpty()) {
        throw new MigrationClientException("Invalid admin username");
    }

    try {
        this.userRegistry = EIMigrationServiceDataHolder.getRegistryService().getRegistry(adminUserName);
        this.userRegistryResource = userRegistry.get(MigrationConstants.ESB_TASK_PATH);
    } catch (RegistryException e) {
        throw new MigrationClientException("Error occurred while retrieving registry resources", e);
    }
}
 
Example 25
Source Project: product-ei   Source File: RegistryDataManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Method to migrate encrypted password of SYSLOG_PROPERTIES registry resource
 *
 * @param migrateActiveTenantsOnly
 * @throws UserStoreException user store exception
 */
public void migrateSysLogPropertyPassword(boolean migrateActiveTenantsOnly)
        throws UserStoreException, RegistryException, CryptoException {
    try {
        //migrating super tenant configurations
        migrateSysLogPropertyPasswordForTenant(SUPER_TENANT_ID);
        log.info("Sys log property password migrated for tenant : " + SUPER_TENANT_DOMAIN_NAME);
    } catch (Exception e) {
        log.error("Error while migrating Sys log property password for tenant : " + SUPER_TENANT_DOMAIN_NAME, e);
    }
    Tenant[] tenants = MigrationServiceDataHolder.getRealmService().getTenantManager().getAllTenants();
    for (Tenant tenant : tenants) {
        if (migrateActiveTenantsOnly && !tenant.isActive()) {
            log.info("Tenant " + tenant.getDomain() + " is inactive. Skipping SYSLOG_PROPERTIES file migration. ");
            continue;
        }
        try {
            migrateSysLogPropertyPasswordForTenant(tenant.getId());
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
}
 
Example 26
Source Project: micro-integrator   Source File: InfoServiceAdminClient.java    License: Apache License 2.0 5 votes vote down vote up
public InfoServiceAdminClient(String backEndUrl, String sessionCookie) throws RegistryException, AxisFault {
    String serviceName = "InfoAdminService";
    String endPoint = backEndUrl + serviceName;
    try {
        infoAdminServiceStub = new InfoAdminServiceStub(endPoint);
        AuthenticateStub.authenticateStub(sessionCookie, infoAdminServiceStub);
    } catch (AxisFault axisFault) {
        log.error("infoAdminServiceStub Initialization fail " + axisFault.getMessage());
        throw new AxisFault("infoAdminServiceStub Initialization fail " + axisFault.getMessage());
    }

}
 
Example 27
Source Project: micro-integrator   Source File: InfoServiceAdminClient.java    License: Apache License 2.0 5 votes vote down vote up
public InfoServiceAdminClient(String backEndUrl, String userName, String password)
        throws RegistryException, AxisFault {
    String serviceName = "InfoAdminService";
    String endPoint = backEndUrl + serviceName;
    try {
        infoAdminServiceStub = new InfoAdminServiceStub(endPoint);
        AuthenticateStub.authenticateStub(userName, password, infoAdminServiceStub);
    } catch (AxisFault axisFault) {
        log.error("infoAdminServiceStub Initialization fail " + axisFault.getMessage());
        throw new AxisFault("infoAdminServiceStub Initialization fail " + axisFault.getMessage());
    }

}
 
Example 28
private void createRegistryService(Class realClass, WithRegistry withRegistry) {

        try {
            RegistryService registryService = createRegistryService(realClass, withRegistry.tenantId(),
                                                                    withRegistry.tenantDomain());
            Class[] singletonClasses = withRegistry.injectToSingletons();
            injectSingletonVariables(registryService, RegistryService.class, singletonClasses);
        } catch (RegistryException e) {
            log.error("Error creating the registry, for test case : " + realClass.getName(), e);
        }
    }
 
Example 29
/**
 * 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);
    }
}
 
Example 30
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);
        }
    }