Search in sources :

Example 1 with ConfigurationManager

use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-identity-framework by wso2.

the class ConfigurationManagerComponent method activate.

/**
 * Register ConfigurationManager as an OSGI service.
 *
 * @param componentContext OSGI service component context.
 */
@Activate
protected void activate(ComponentContext componentContext) {
    try {
        BundleContext bundleContext = componentContext.getBundleContext();
        ConfigurationDAO configurationDAO = new ConfigurationDAOImpl();
        bundleContext.registerService(ConfigurationDAO.class.getName(), configurationDAO, null);
        bundleContext.registerService(ConfigurationDAO.class.getName(), new CachedBackedConfigurationDAO(configurationDAO), null);
        ConfigurationManagerConfigurationHolder configurationManagerConfigurationHolder = new ConfigurationManagerConfigurationHolder();
        configurationManagerConfigurationHolder.setConfigurationDAOS(configurationDAOs);
        bundleContext.registerService(ConfigurationManager.class.getName(), new ConfigurationManagerImpl(configurationManagerConfigurationHolder), null);
        ConfigurationManagerComponentDataHolder.getInstance().setConfigurationManagementEnabled(isConfigurationManagementEnabled());
        setUseCreatedTime();
    } catch (Throwable e) {
        log.error("Error while activating ConfigurationManagerComponent.", e);
    }
}
Also used : CachedBackedConfigurationDAO(org.wso2.carbon.identity.configuration.mgt.core.dao.impl.CachedBackedConfigurationDAO) ConfigurationDAO(org.wso2.carbon.identity.configuration.mgt.core.dao.ConfigurationDAO) CachedBackedConfigurationDAO(org.wso2.carbon.identity.configuration.mgt.core.dao.impl.CachedBackedConfigurationDAO) ConfigurationDAOImpl(org.wso2.carbon.identity.configuration.mgt.core.dao.impl.ConfigurationDAOImpl) ConfigurationManagerImpl(org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManagerImpl) ConfigurationManager(org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager) BundleContext(org.osgi.framework.BundleContext) ConfigurationManagerConfigurationHolder(org.wso2.carbon.identity.configuration.mgt.core.model.ConfigurationManagerConfigurationHolder) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with ConfigurationManager

use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-identity-framework by wso2.

the class ConfigStoreBasedTemplateHandler method listTemplates.

@Override
public List<Template> listTemplates(String templateType, Integer limit, Integer offset, Condition searchCondition) throws TemplateManagementException {
    ConfigurationManager configManager = TemplateManagerDataHolder.getInstance().getConfigurationManager();
    try {
        Resources resourcesList;
        if (searchCondition == null) {
            resourcesList = configManager.getResourcesByType(templateType);
        } else {
            resourcesList = configManager.getTenantResources(searchCondition);
        }
        return resourcesList.getResources().stream().map(resource -> {
            resource.setResourceType(templateType);
            return new ResourceToTemplate().apply(resource);
        }).collect(Collectors.toList());
    } catch (ConfigurationManagementException e) {
        if (ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_TYPE_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
            if (log.isDebugEnabled()) {
                log.debug("Template type : '" + templateType + "' has not been created in the database.", e);
            }
            return Collections.emptyList();
        } else if (ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCES_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
            if (log.isDebugEnabled()) {
                String message = "Templates do not exist for template type: " + templateType;
                if (searchCondition != null) {
                    message = message + ", and search  criteria:" + searchCondition.toString();
                }
                log.debug(message, e);
            }
            return Collections.emptyList();
        }
        throw handleServerException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_LIST_TEMPLATES, e, templateType, getTenantDomainFromCarbonContext());
    }
}
Also used : ResourceToTemplate(org.wso2.carbon.identity.template.mgt.function.ResourceToTemplate) WSTrustConnectorValidator.validateWSTrustTemplateAvailability(org.wso2.carbon.identity.template.mgt.handler.impl.WSTrustConnectorValidator.validateWSTrustTemplateAvailability) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) ConfigurationManager(org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) TemplateHandler(org.wso2.carbon.identity.template.mgt.handler.TemplateHandler) EnumUtils(org.apache.commons.lang3.EnumUtils) TemplateMgtUtils.getTenantDomainFromCarbonContext(org.wso2.carbon.identity.template.mgt.util.TemplateMgtUtils.getTenantDomainFromCarbonContext) Condition(org.wso2.carbon.identity.configuration.mgt.core.search.Condition) TemplateMgtUtils.handleClientException(org.wso2.carbon.identity.template.mgt.util.TemplateMgtUtils.handleClientException) TemplateToResource(org.wso2.carbon.identity.template.mgt.function.TemplateToResource) TemplateToResourceAdd(org.wso2.carbon.identity.template.mgt.function.TemplateToResourceAdd) TemplateMgtUtils.handleServerException(org.wso2.carbon.identity.template.mgt.util.TemplateMgtUtils.handleServerException) ResourceTypeAdd(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceTypeAdd) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ConfigurationConstants(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) TemplateManagementException(org.wso2.carbon.identity.template.mgt.exception.TemplateManagementException) TemplateMgtConstants(org.wso2.carbon.identity.template.mgt.TemplateMgtConstants) TemplateManagerDataHolder(org.wso2.carbon.identity.template.mgt.internal.TemplateManagerDataHolder) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) Collections(java.util.Collections) Template(org.wso2.carbon.identity.template.mgt.model.Template) InputStream(java.io.InputStream) ResourceToTemplate(org.wso2.carbon.identity.template.mgt.function.ResourceToTemplate) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) ConfigurationManager(org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager)

Example 3 with ConfigurationManager

use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-identity-framework by wso2.

the class ConfigStoreBasedTemplateHandler method addTemplateToConfigStore.

private String addTemplateToConfigStore(Template template) throws TemplateManagementException {
    if (!isValidTemplateType(template.getTemplateType().toString())) {
        throw handleClientException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_INVALID_TEMPLATE_TYPE, template.getTemplateType().toString());
    }
    ConfigurationManager configManager = TemplateManagerDataHolder.getInstance().getConfigurationManager();
    try {
        Resource resource = configManager.addResource(template.getTemplateType().toString(), new TemplateToResourceAdd().apply(template));
        configManager.addFile(template.getTemplateType().toString(), template.getTemplateName(), template.getTemplateName() + "_template_object", IOUtils.toInputStream(template.getTemplateScript()));
        return resource.getResourceId();
    } catch (ConfigurationManagementException e) {
        if (ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_ALREADY_EXISTS.getCode().equals(e.getErrorCode())) {
            throw handleClientException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_TEMPLATE_ALREADY_EXIST, e, template.getTemplateName());
        } else if (ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_TYPE_DOES_NOT_EXISTS.getCode().equals(e.getErrorCode())) {
            // in the database, create the resource-type and retry the template creation.
            try {
                createResourceType(template.getTemplateType().toString());
                return addTemplateToConfigStore(template);
            } catch (ConfigurationManagementException e1) {
                throw handleServerException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_INSERT_TEMPLATE, e, template.getTemplateName());
            }
        } else {
            throw handleServerException(TemplateMgtConstants.ErrorMessages.ERROR_CODE_INSERT_TEMPLATE, e, template.getTemplateName());
        }
    }
}
Also used : Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) TemplateToResource(org.wso2.carbon.identity.template.mgt.function.TemplateToResource) TemplateToResourceAdd(org.wso2.carbon.identity.template.mgt.function.TemplateToResourceAdd) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) ConfigurationManager(org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager)

Example 4 with ConfigurationManager

use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-identity-framework by wso2.

the class ConfigStoreBasedTemplateHandler method createResourceType.

private void createResourceType(String templateType) throws ConfigurationManagementException {
    ConfigurationManager configManager = TemplateManagerDataHolder.getInstance().getConfigurationManager();
    ResourceTypeAdd resourceType = new ResourceTypeAdd();
    resourceType.setName(templateType);
    resourceType.setDescription("This is the resource type for " + templateType);
    configManager.addResourceType(resourceType);
}
Also used : ResourceTypeAdd(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceTypeAdd) ConfigurationManager(org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager)

Example 5 with ConfigurationManager

use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-identity-framework by wso2.

the class ConfigurationManagementUtils method getConfigurationManager.

public static ConfigurationManager getConfigurationManager() {
    ConfigurationManagerComponentDataHolder.setUseCreatedTime(true);
    ConfigurationManagerConfigurationHolder configurationHolder = new ConfigurationManagerConfigurationHolder();
    ConfigurationDAO configurationDAO = new ConfigurationDAOImpl();
    configurationHolder.setConfigurationDAOS(Collections.singletonList(configurationDAO));
    ConfigurationManager configurationManager = new ConfigurationManagerImpl(configurationHolder);
    ConfigurationManagerComponentDataHolder.getInstance().setConfigurationManagementEnabled(true);
    return configurationManager;
}
Also used : ConfigurationDAO(org.wso2.carbon.identity.configuration.mgt.core.dao.ConfigurationDAO) ConfigurationDAOImpl(org.wso2.carbon.identity.configuration.mgt.core.dao.impl.ConfigurationDAOImpl) ConfigurationManagerImpl(org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManagerImpl) ConfigurationManager(org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager) ConfigurationManagerConfigurationHolder(org.wso2.carbon.identity.configuration.mgt.core.model.ConfigurationManagerConfigurationHolder)

Aggregations

ConfigurationManager (org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager)8 File (java.io.File)5 IOException (java.io.IOException)5 ConfigurationManagementException (org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException)5 Resource (org.wso2.carbon.identity.configuration.mgt.core.model.Resource)4 TemplateToResource (org.wso2.carbon.identity.template.mgt.function.TemplateToResource)4 ConfigurationManager (org.wso2.carbon.mediation.initializer.configurations.ConfigurationManager)4 InputStream (java.io.InputStream)3 Lock (java.util.concurrent.locks.Lock)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)3 ConfigurationDAO (org.wso2.carbon.identity.configuration.mgt.core.dao.ConfigurationDAO)3 ConfigurationDAOImpl (org.wso2.carbon.identity.configuration.mgt.core.dao.impl.ConfigurationDAOImpl)3 ConfigurationManagerConfigurationHolder (org.wso2.carbon.identity.configuration.mgt.core.model.ConfigurationManagerConfigurationHolder)3 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)3 ServerContextInformation (org.apache.synapse.ServerContextInformation)2 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)2 BundleContext (org.osgi.framework.BundleContext)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 Activate (org.osgi.service.component.annotations.Activate)2