Java Code Examples for org.wso2.carbon.registry.core.Registry

The following examples show how to use org.wso2.carbon.registry.core.Registry. 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
Source Project: carbon-identity-framework   Source File: EntitlementUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void addSamplePolicies(Registry registry) {

        File policyFolder = new File(CarbonUtils.getCarbonHome() + File.separator
                + "repository" + File.separator + "resources" + File.separator
                + "identity" + File.separator + "policies" + File.separator + "xacml"
                + File.separator + "default");

        File[] fileList;
        if (policyFolder.exists() && ArrayUtils.isNotEmpty(fileList = policyFolder.listFiles())) {
            for (File policyFile : fileList) {
                if (policyFile.isFile()) {
                    PolicyDTO policyDTO = new PolicyDTO();
                    try {
                        policyDTO.setPolicy(FileUtils.readFileToString(policyFile));
                        EntitlementUtil.addFilesystemPolicy(policyDTO, registry, false);
                    } catch (Exception e) {
                        // log and ignore
                        log.error("Error while adding sample XACML policies", e);
                    }
                }
            }
        }
    }
 
Example 2
Source Project: carbon-identity   Source File: DefaultPolicyDataStore.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String getGlobalPolicyAlgorithmName() {

    Registry registry = EntitlementServiceComponent.
            getGovernanceRegistry(CarbonContext.getThreadLocalCarbonContext().getTenantId());
    String algorithm = null;
    try {

        if (registry.resourceExists(policyDataCollection)) {
            Collection collection = (Collection) registry.get(policyDataCollection);
            algorithm = collection.getProperty("globalPolicyCombiningAlgorithm");
        }
    } catch (RegistryException e) {
        if (log.isDebugEnabled()) {
            log.debug(e);
        }
    }

    // set default
    if (algorithm == null) {
        algorithm = "deny-overrides";
    }

    return algorithm;
}
 
Example 3
Source Project: carbon-commons   Source File: RemoteTaskUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static Object[] lookupRemoteTask(String remoteTaskId) throws TaskException {
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
                MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
        Registry registry = RegistryBasedTaskRepository.getRegistry();
        Resource res = registry.get(resourcePathFromRemoteTaskId(remoteTaskId));
        Object[] result = new Object[3];
        result[0] = Integer.parseInt(res.getProperty(REMOTE_TASK_TENANT_ID).toString());
        result[1] = res.getProperty(REMOTE_TASK_TASK_TYPE);
        result[2] = res.getProperty(REMOTE_TASK_TASK_NAME);
        return result;
    } catch (Exception e) {
        throw new TaskException(e.getMessage(), Code.UNKNOWN, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 4
Source Project: carbon-apimgt   Source File: APIMgtGoogleAnalyticsUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the google analytics publisher by reading tenants google analytics
 * configuration from the registry
 *
 * @param tenantDomain Tenant domain of the current tenant
 */
public void init(String tenantDomain) {
    configKey = APIConstants.GA_CONFIGURATION_LOCATION;

    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);

        Registry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry();
        Resource resource = registry.get(configKey);
        InputStream in = resource.getContentStream();
        StAXOMBuilder builder = new StAXOMBuilder(in);
        this.gaConfig = new GoogleAnalyticsConfig(builder.getDocumentElement());
    } catch (RegistryException | XMLStreamException e) {
        // flow should not break. Therefore ignoring the exception
        log.error("Failed to retrieve google analytics configurations for tenant:" + tenantDomain);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 5
Source Project: carbon-commons   Source File: MetadataFinder.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }

}
 
Example 6
Source Project: carbon-apimgt   Source File: APIConsumerImplTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTagsWithAttributes() throws Exception {
    Registry userRegistry = Mockito.mock(Registry.class);
    APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
    System.setProperty(CARBON_HOME, "");
    PowerMockito.mockStatic(GovernanceUtils.class);
    UserRegistry userRegistry1 = Mockito.mock(UserRegistry.class);
    Mockito.when(registryService.getGovernanceUserRegistry(Mockito.anyString(), Mockito.anyInt())).
            thenReturn(userRegistry1);
    Mockito.when(registryService.getGovernanceSystemRegistry(Mockito.anyInt())).thenReturn(userRegistry1);
    List<TermData> list = new ArrayList<TermData>();
    TermData termData = new TermData("testTerm", 10);
    list.add(termData);
    Mockito.when(GovernanceUtils.getTermDataList(Mockito.anyMap(), Mockito.anyString(), Mockito.anyString(),
            Mockito.anyBoolean())).thenReturn(list);
    ResourceDO resourceDO = Mockito.mock(ResourceDO.class);
    Resource resource = new ResourceImpl("dw", resourceDO);
    resource.setContent("testContent");
    Mockito.when(userRegistry1.resourceExists(Mockito.anyString())).thenReturn(true);
    Mockito.when(userRegistry1.get(Mockito.anyString())).thenReturn(resource);
    assertNotNull(apiConsumer.getTagsWithAttributes("testDomain"));
}
 
Example 7
/**
 * @param registry
 * @param paramName
 * @param value
 * @throws IdentityException
 */
public void createOrUpdateParameter(Registry registry, String paramName, String value)
        throws IdentityException {

    if (paramName == null || value == null) {
        throw IdentityException.error("Invalid inputs");
    }

    ParameterDO param = null;
    param = new ParameterDO();
    paramName = paramName.trim();
    param.setName(paramName);

    param.setValue(value);

    ParameterDAO dao = new ParameterDAO(registry);
    dao.createOrUpdateParameter(param);
}
 
Example 8
Source Project: product-es   Source File: MigrateFrom200to210.java    License: 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 9
Source Project: carbon-identity   Source File: IdentityTenantUtil.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static Registry getRegistryForAnonymousSession(String domainName, String username)
        throws IdentityException {
    try {
        if (domainName == null && username == null) {
            domainName = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
        }
        if (username == null) {
            return AnonymousSessionUtil.getSystemRegistryByDomainName(registryService,
                    realmService, domainName);
        } else {
            return AnonymousSessionUtil.getSystemRegistryByUserName(registryService,
                    realmService, username);
        }
    } catch (CarbonException e) {
        log.error("Error obtaining a registry instance", e);
        throw IdentityException.error("Error obtaining a registry instance", e);
    }
}
 
Example 10
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 11
Source Project: carbon-apimgt   Source File: DocumentIndexer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Fetch api status and access control details to document artifacts
 *
 * @param registry
 * @param documentResource
 * @param fields
 * @throws RegistryException
 * @throws APIManagementException
 */
private void fetchRequiredDetailsFromAssociatedAPI(Registry registry, Resource documentResource,
        Map<String, List<String>> fields) throws RegistryException, APIManagementException {
    Association apiAssociations[] = registry
            .getAssociations(documentResource.getPath(), APIConstants.DOCUMENTATION_ASSOCIATION);

    //a document can have one api association
    Association apiAssociation = apiAssociations[0];
    String apiPath = apiAssociation.getSourcePath();

    if (registry.resourceExists(apiPath)) {
        Resource apiResource = registry.get(apiPath);
        GenericArtifactManager apiArtifactManager = APIUtil.getArtifactManager(registry, APIConstants.API_KEY);
        GenericArtifact apiArtifact = apiArtifactManager.getGenericArtifact(apiResource.getUUID());
        String apiStatus = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_STATUS).toLowerCase();
        String publisherRoles = apiResource.getProperty(APIConstants.PUBLISHER_ROLES);
        fields.put(APIConstants.API_OVERVIEW_STATUS, Arrays.asList(apiStatus));
        fields.put(APIConstants.PUBLISHER_ROLES, Arrays.asList(publisherRoles));
    } else {
        log.warn("API does not exist at " + apiPath);
    }
}
 
Example 12
Source Project: carbon-apimgt   Source File: APIConsumerImplTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetPublishedAPIsByProvider() throws APIManagementException, RegistryException {
    Registry userRegistry = Mockito.mock(Registry.class);
    APIConsumerImpl apiConsumer = new APIConsumerImplWrapper(userRegistry, apiMgtDAO);
    PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(true, false);
    PowerMockito.when(APIUtil.isAllowDisplayAPIsWithMultipleStatus()).thenReturn(true, false);
    GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
    PowerMockito.when(APIUtil.getArtifactManager((UserRegistry)(Mockito.anyObject()), Mockito.anyString())).
            thenReturn(artifactManager);
    Association association = Mockito.mock(Association.class);
    Association[] associations = new Association[]{association};
    Mockito.when(userRegistry.getAssociations(Mockito.anyString(), Mockito.anyString())).thenReturn(associations);
    Mockito.when(association.getDestinationPath()).thenReturn("testPath");
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(userRegistry.get("testPath")).thenReturn(resource);
    Mockito.when(resource.getUUID()).thenReturn("testID");
    GenericArtifact genericArtifact = Mockito.mock(GenericArtifact.class);
    Mockito.when(artifactManager.getGenericArtifact(Mockito.anyString())).thenReturn(genericArtifact);
    Mockito.when(genericArtifact.getAttribute("overview_status")).thenReturn("PUBLISHED");
    APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
    API api = new API(apiId1);
    Mockito.when(APIUtil.getAPI(genericArtifact)).thenReturn(api);
    assertNotNull(apiConsumer.getPublishedAPIsByProvider("testID", 10));
    assertNotNull(apiConsumer.getPublishedAPIsByProvider("testID", 10));
}
 
Example 13
Source Project: carbon-identity   Source File: SecurityUIUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static String getUrl() throws Exception {

        if (url == null) {
            ServiceHolder serviceHodler = ServiceHolder.getInstance();
            RegistryService regService = serviceHodler.getRegistryService();
            Registry systemRegistry = regService.getConfigSystemRegistry();
            Resource resource = systemRegistry.get("/carbon/connection/props");
            String servicePath = resource.getProperty("service-path");
            String contextRoot = resource.getProperty("context-root");

            String host = resource.getProperty("host-name");
            contextRoot = StringUtils.equals("/", contextRoot) ? "" : contextRoot;

            host = (host == null) ? "localhost" : host;
            String port = System.getProperty("carbon.https.port");
            StringBuilder urlValue = new StringBuilder();
            url = (urlValue.append("https://").append(host).append(":").append(port).append("/").append(contextRoot).append(servicePath).append("/")).toString();
        }

        return url;
    }
 
Example 14
/**
 * @param registry
 * @param paramName
 * @param value
 * @throws IdentityException
 */
public void createOrUpdateParameter(Registry registry, String paramName, String value)
        throws IdentityException {

    if (paramName == null || value == null) {
        throw IdentityException.error("Invalid inputs");
    }

    ParameterDO param = null;
    param = new ParameterDO();
    paramName = paramName.trim();
    param.setName(paramName);

    if (value != null) {
        param.setValue(value);
    }

    ParameterDAO dao = new ParameterDAO(registry);
    dao.createOrUpdateParameter(param);
}
 
Example 15
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 16
Source Project: product-ei   Source File: RegistryDataManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  Obtain the STS policy paths from registry
 *
 * @param registry
 * @return
 * @throws RegistryException
 */
private List<String> getSTSPolicyPaths(Registry registry) throws RegistryException {
    List<String> policyPaths = new ArrayList<>();
    if (registry.resourceExists(Constant.SERVICE_GROUPS_PATH)) {
        Collection serviceGroups = (Collection) registry.get(Constant.SERVICE_GROUPS_PATH);
        if (serviceGroups != null) {
            for (String serviceGroupPath : serviceGroups.getChildren()) {
                if (StringUtils.isNotEmpty(serviceGroupPath) &&
                        serviceGroupPath.contains(Constant.STS_SERVICE_GROUP)) {
                    String policyCollectionPath = new StringBuilder().append(serviceGroupPath)
                            .append(Constant.SECURITY_POLICY_RESOURCE_PATH).toString();
                    Collection policies = (Collection) registry.get(policyCollectionPath);
                    if (policies != null) {
                        policyPaths.addAll(Arrays.asList(policies.getChildren()));
                    }
                }
            }
        }
    }
    return policyPaths;
}
 
Example 17
Source Project: carbon-apimgt   Source File: UserAwareAPIProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Map<Documentation, API> searchAPIDoc(Registry registry, int tenantID, String username, String searchTerm)
        throws APIManagementException {
    Map<Documentation, API> apiByDocumentation = APIUtil
            .searchAPIsByDoc(registry, tenantId, username, searchTerm, APIConstants.PUBLISHER_CLIENT);
    Map<Documentation, API> filteredAPIDocumentation = new HashMap<Documentation, API>();
    if (apiByDocumentation != null) {
        for (Map.Entry<Documentation, API> entry : apiByDocumentation.entrySet()) {
            API api = entry.getValue();
            if (api != null) {
                checkAccessControlPermission(api.getId());
                filteredAPIDocumentation.put(entry.getKey(), api);
            }
        }
        return filteredAPIDocumentation;
    }
    return null;
}
 
Example 18
Source Project: attic-stratos   Source File: RegistryManager.java    License: 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 19
private static void init() {

        Registry registry;
        IdentityMgtConfig.getInstance(realmService.getBootstrapRealmConfiguration());
        recoveryProcessor = new RecoveryProcessor();
        try {
            registry = IdentityMgtServiceComponent.getRegistryService()
                    .getConfigSystemRegistry();
            if (!registry
                    .resourceExists(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH)) {
                Collection questionCollection = registry.newCollection();
                registry.put(IdentityMgtConstants.IDENTITY_MANAGEMENT_PATH,
                        questionCollection);
                loadDefaultChallenges();
            }
        } catch (RegistryException e) {
            log.error("Error while creating registry collection for org.wso2.carbon.identity.mgt component", e);
        }

    }
 
Example 20
Source Project: carbon-commons   Source File: RemoteTaskUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String createRemoteTaskMapping(int tenantId, String taskType,
        String taskName) throws TaskException {
    try {
        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
                MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true);
        Registry registry = RegistryBasedTaskRepository.getRegistry();
        Resource res = registry.newResource();
        res.setProperty(REMOTE_TASK_TENANT_ID, Integer.toString(tenantId));
        res.setProperty(REMOTE_TASK_TASK_TYPE, taskType);
        res.setProperty(REMOTE_TASK_TASK_NAME, taskName);
        String remoteTaskId = generateRemoteTaskID();
        registry.put(resourcePathFromRemoteTaskId(remoteTaskId), res);
        return remoteTaskId;
    } catch (Exception e) {
        throw new TaskException(e.getMessage(), Code.UNKNOWN, e);
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }
}
 
Example 21
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 22
Source Project: carbon-identity-framework   Source File: PAPPolicyStore.java    License: Apache License 2.0 5 votes vote down vote up
public PAPPolicyStore(Registry registry) throws EntitlementException {
    if (registry == null) {
        log.error("Registry reference not set");
        throw new EntitlementException("Registry reference not set");
    }
    this.registry = registry;
}
 
Example 23
Source Project: carbon-identity   Source File: SecurityConfigAdmin.java    License: Apache License 2.0 5 votes vote down vote up
public SecurityConfigAdmin(UserRealm realm, Registry registry, AxisConfiguration config) throws SecurityConfigException {
    this.axisConfig = config;
    this.registry = registry;
    this.realm = realm;

    try {
        this.govRegistry = SecurityServiceHolder.getRegistryService().getGovernanceSystemRegistry(
                ((UserRegistry) registry).getTenantId());
    } catch (Exception e) {
        log.error("Error when obtaining the governance registry instance.");
        throw new SecurityConfigException(
                "Error when obtaining the governance registry instance.", e);
    }
}
 
Example 24
Source Project: product-es   Source File: EmailUserNameMigrationClient.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This method extracts the artifact types which contains '@{overview_provider}' in the storage path, and call the
 * migration method.
 * @param tenant The tenant object
 * @throws UserStoreException
 * @throws RegistryException
 * @throws XMLStreamException
 */
private void migrate(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().getGovernanceUserRegistry(adminName, tenantId);
        GovernanceUtils.loadGovernanceArtifacts((UserRegistry) registry);
        List<GovernanceArtifactConfiguration> configurations = GovernanceUtils.
                findGovernanceArtifactConfigurations(registry);
        for (GovernanceArtifactConfiguration governanceArtifactConfiguration : configurations) {
            String pathExpression = governanceArtifactConfiguration.getPathExpression();
            if (pathExpression.contains(Constants.OVERVIEW_PROVIDER) ||
                hasOverviewProviderElement(governanceArtifactConfiguration)) {
                String shortName = governanceArtifactConfiguration.getKey();
                GenericArtifactManager artifactManager = new GenericArtifactManager(registry, shortName);
                GenericArtifact[] artifacts = artifactManager.getAllGenericArtifacts();
                migrateArtifactsWithEmailUserName(artifacts, registry);
            }
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }

}
 
Example 25
@Override
public void removeServiceProviderConfiguration(String issuer) throws IdentityApplicationManagementException {
    try {
        IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager();
        Registry configSystemRegistry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
                getRegistry(RegistryType.SYSTEM_CONFIGURATION);
        persistenceManager.removeServiceProvider(configSystemRegistry, issuer);
    } catch (IdentityException e) {
        log.error("Erro while deleting the issuer", e);
        throw new IdentityApplicationManagementException("Error while deleting SAML issuer " + e.getMessage());
    }
}
 
Example 26
Source Project: carbon-identity   Source File: STSAdminServiceImpl.java    License: 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 27
Source Project: carbon-commons   Source File: ReportingResourcesSupplier.java    License: Apache License 2.0 5 votes vote down vote up
public String getJRXMLFileContent(String componentName, String reportTemplate) throws ReportingException{
    String template;
    Registry registry;

        try {
            registry = ReportingComponent.getRegistryService().getConfigSystemRegistry();
        } catch (RegistryException e) {
            throw new ReportingException("Failed to get registry",e);
        }
        template = CommonUtil.getJRXMLFileContent(componentName,reportTemplate, registry);
        return template;
}
 
Example 28
Source Project: carbon-identity   Source File: SAMLApplicationDAOImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void removeServiceProviderConfiguration(String issuer) throws IdentityApplicationManagementException {
    try {
        IdentityPersistenceManager persistenceManager = IdentityPersistenceManager.getPersistanceManager();
        Registry configSystemRegistry = (Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
                getRegistry(RegistryType.SYSTEM_CONFIGURATION);
        persistenceManager.removeServiceProvider(configSystemRegistry, issuer);
    } catch (IdentityException e) {
        log.error("Erro while deleting the issuer", e);
        throw new IdentityApplicationManagementException("Error while deleting SAML issuer " + e.getMessage());
    }
}
 
Example 29
Source Project: carbon-commons   Source File: AbstractMetaDataHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void saveMetadata
        () throws ReportingException {
    try {
        RegistryService registryService = ReportingTemplateComponent.getRegistryService();
        Registry registry = registryService.getConfigSystemRegistry();
        registry.beginTransaction();
        Resource reportFilesResource = registry.newResource();
        reportFilesResource.setContent(reportsElement.toString());
        String location = ReportConstants.REPORT_META_DATA_PATH + ReportConstants.METADATA_FILE_NAME;
        registry.put(location, reportFilesResource);
        registry.commitTransaction();
    } catch (RegistryException e) {
        throw new ReportingException("Exception occured in loading the meta-data of reports", e);
    }
}
 
Example 30
public static Registry getGovernanceRegistry(int tenantId) {
    try {
        return registryService.getGovernanceSystemRegistry(tenantId);
    } catch (RegistryException e) {
        // ignore
    }
    return null;
}