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

The following examples show how to use org.wso2.carbon.registry.core.Registry. 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: IdentityMgtServiceComponent.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: RegistryDataManager.java    From product-ei with 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 #3
Source File: APIConsumerImplTest.java    From carbon-apimgt with 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 #4
Source File: IdentityPersistenceManager.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * @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 #5
Source File: RegistryDataManager.java    From product-ei with 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 #6
Source File: SecurityDeploymentInterceptor.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: DocumentIndexer.java    From carbon-apimgt with 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 #8
Source File: UserAwareAPIProvider.java    From carbon-apimgt with 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 #9
Source File: IdentityPersistenceManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @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 #10
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 #11
Source File: APIConsumerImplTest.java    From carbon-apimgt with 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 #12
Source File: SecurityUIUtil.java    From carbon-identity with 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 #13
Source File: MetadataFinder.java    From carbon-commons with 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 #14
Source File: APIMgtGoogleAnalyticsUtils.java    From carbon-apimgt with 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 #15
Source File: RemoteTaskUtils.java    From carbon-commons with 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 #16
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 #17
Source File: DefaultPolicyDataStore.java    From carbon-identity with 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 #18
Source File: RemoteTaskUtils.java    From carbon-commons with 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 #19
Source File: IdentityTenantUtil.java    From carbon-identity with 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 #20
Source File: EntitlementUtil.java    From carbon-identity-framework with 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 #21
Source File: APIImportUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method adds API sequences to the imported API. If the sequence is a newly defined one, it is added.
 *
 * @param pathToArchive location of the extracted folder of the API
 */
private static void addSOAPToREST(String pathToArchive, API importedApi, Registry registry)
        throws APIImportExportException {

    String inFlowFileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + IN;
    String outFlowFileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + OUT;

    //Adding in-sequence, if any
    if (CommonUtil.checkFileExistence(inFlowFileLocation)) {
        APIIdentifier apiId = importedApi.getId();
        String soapToRestLocationIn =
                APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiId.getProviderName()
                        + RegistryConstants.PATH_SEPARATOR + apiId.getApiName() + RegistryConstants.PATH_SEPARATOR
                        + apiId.getVersion() + RegistryConstants.PATH_SEPARATOR
                        + SOAPToRESTConstants.SequenceGen.SOAP_TO_REST_IN_RESOURCE;
        String soapToRestLocationOut =
                APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiId.getProviderName()
                        + RegistryConstants.PATH_SEPARATOR + apiId.getApiName() + RegistryConstants.PATH_SEPARATOR
                        + apiId.getVersion() + RegistryConstants.PATH_SEPARATOR
                        + SOAPToRESTConstants.SequenceGen.SOAP_TO_REST_OUT_RESOURCE;
        try {
            // Import inflow mediation logic
            Path inFlowDirectory = Paths.get(inFlowFileLocation);
            ImportMediationLogic(inFlowDirectory, registry, soapToRestLocationIn);

            // Import outflow mediation logic
            Path outFlowDirectory = Paths.get(outFlowFileLocation);
            ImportMediationLogic(outFlowDirectory, registry, soapToRestLocationOut);

        } catch (DirectoryIteratorException e) {
            throw new APIImportExportException("Error in importing SOAP to REST mediation logic", e);
        }
    }
}
 
Example #22
Source File: DataSourceDAO.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the datasource registry instance of the tenant
 *
 * @param tenantId
 * @return
 * @throws DataSourceException
 */
private static Registry getRegistry(int tenantId) throws DataSourceException {

    Registry registry = DataSourceUtils.getConfRegistryForTenant(tenantId);
    if (log.isDebugEnabled()) {
        log.debug("Retrieving the config registry for tenant: " + tenantId);
    }
    return registry;
}
 
Example #23
Source File: SAMLApplicationDAOImpl.java    From carbon-identity with 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 #24
Source File: SecurityConfigAdmin.java    From carbon-identity with 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 #25
Source File: AbstractAPIManager.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private GenericArtifactManager getAPIGenericArtifactManager(APIIdentifier identifier, Registry registry)
        throws APIManagementException {

    String tenantDomain = getTenantDomain(identifier);
    GenericArtifactManager manager = genericArtifactCache.get(tenantDomain);
    if (manager != null) {
        return manager;
    }
    manager = getAPIGenericArtifactManagerFromUtil(registry, APIConstants.API_KEY);
    genericArtifactCache.put(tenantDomain, manager);
    return manager;
}
 
Example #26
Source File: AbstractMetaDataHandler.java    From carbon-commons with 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 #27
Source File: EntitlementServiceComponent.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static Registry getGovernanceRegistry(int tenantId) {
    try {
        return registryService.getGovernanceSystemRegistry(tenantId);
    } catch (RegistryException e) {
        // ignore
    }
    return null;
}
 
Example #28
Source File: ProviderMigrationClient.java    From product-es with Apache License 2.0 5 votes vote down vote up
private String getStoragePath(String rxtPath, Registry registry)
        throws RegistryException, IOException, SAXException, ParserConfigurationException {
    Resource artifactRxt = registry.get(rxtPath);
    byte[] rxtContent = (byte[]) artifactRxt.getContent();
    String rxtContentString = RegistryUtils.decodeBytes(rxtContent);
    Document dom = stringToDocument(rxtContentString);
    Node storagePath = dom.getElementsByTagName(Constants.STORAGE_PATH).item(0);
    return storagePath.getFirstChild().getNodeValue();
}
 
Example #29
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 #30
Source File: APIMRegistryServiceImpl.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override
public String getConfigRegistryResourceContent(String tenantDomain, final String registryLocation)
                                    throws UserStoreException, RegistryException {
    String content = null;
    if (tenantDomain == null) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }

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

        int tenantId = ServiceReferenceHolder.getInstance().getRealmService().getTenantManager().getTenantId(tenantDomain);
        Registry registry = ServiceReferenceHolder.getInstance().getRegistryService().getConfigSystemRegistry(tenantId);
        APIUtil.loadTenantRegistry(tenantId);
        if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
            APIUtil.loadTenantConf(tenantId);
        }

        if (registry.resourceExists(registryLocation)) {
            Resource resource = registry.get(registryLocation);
            content = getString(resource);
        }
    } catch (APIManagementException e) {
        log.error("Error occurred while loading tenant configuration for '" + tenantDomain + "'");

    } finally {
        PrivilegedCarbonContext.endTenantFlow();
    }

    return content;
}