Search in sources :

Example 1 with EventPublisherConfigurationException

use of org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException in project identity-governance by wso2-extensions.

the class ResourceManagerImpl method destroyEventPublisherConfiguration.

/**
 * This is used to destroy an existing EventPublisher.
 * As per the implementation in analytics-common we need to add the publisher as a file before destroying it.
 *
 * @param eventPublisherConfiguration Event Publisher Configuration.
 * @throws ConfigurationManagementException Configuration Management Exception.
 */
private void destroyEventPublisherConfiguration(EventPublisherConfiguration eventPublisherConfiguration) throws EventPublisherConfigurationException {
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    EventPublisherConfigurationFile eventPublisherConfigurationFile = new EventPublisherConfigurationFile();
    eventPublisherConfigurationFile.setTenantId(tenantId);
    eventPublisherConfigurationFile.setEventPublisherName(eventPublisherConfiguration.getEventPublisherName());
    eventPublisherConfigurationFile.setFileName(eventPublisherConfiguration.getEventPublisherName());
    eventPublisherConfigurationFile.setStatus(EventPublisherConfigurationFile.Status.DEPLOYED);
    TenantResourceManagerDataHolder.getInstance().getCarbonEventPublisherService().addEventPublisherConfigurationFile(eventPublisherConfigurationFile, tenantId);
    TenantResourceManagerDataHolder.getInstance().getCarbonEventPublisherService().removeEventPublisherConfigurationFile(eventPublisherConfiguration.getEventPublisherName(), tenantId);
}
Also used : EventPublisherConfigurationFile(org.wso2.carbon.event.publisher.core.config.EventPublisherConfigurationFile)

Example 2 with EventPublisherConfigurationException

use of org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException in project identity-api-server by wso2.

the class NotificationSenderManagementService method validateEmailSenderUpdateRequestAndGetPublisherInSuperTenant.

/**
 * Validate the email Sender put request and get the corresponding super tenant's event publisher configuration.
 *
 * @param senderName Email sender's name.
 * @param tenantId   Tenant id.
 * @return Corresponding super tenant's event publisher's configuration.
 */
private EventPublisherConfiguration validateEmailSenderUpdateRequestAndGetPublisherInSuperTenant(String senderName, int tenantId) {
    EventPublisherService eventPublisherService = NotificationSenderServiceHolder.getEventPublisherService();
    EventPublisherConfiguration publisherInSuperTenant = null;
    try {
        // Check whether a publisher exists to replace.
        NotificationSenderServiceHolder.getNotificationSenderConfigManager().getResource(PUBLISHER_RESOURCE_TYPE, senderName);
        startSuperTenantFlow();
        List<EventPublisherConfiguration> activeEventPublisherConfigurations = eventPublisherService.getAllActiveEventPublisherConfigurations();
        if (activeEventPublisherConfigurations == null) {
            throw handleException(Response.Status.NOT_FOUND, ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND, "carbon.super");
        }
        startTenantFlow(tenantId);
        // Check whether the super tenant has a publisher with the defined name.
        publisherInSuperTenant = activeEventPublisherConfigurations.stream().filter(publisher -> publisher.getEventPublisherName().equals(senderName)).findAny().orElse(null);
        if (publisherInSuperTenant == null) {
            throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT, senderName);
        }
    } catch (EventPublisherConfigurationException e) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, e.getMessage());
    } catch (ConfigurationManagementException e) {
        // If resource not found by id.
        if (RESOURCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) {
            throw handleConfigurationMgtException(e, ERROR_CODE_NO_RESOURCE_EXISTS, senderName);
        }
        throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER, senderName);
    }
    return publisherInSuperTenant;
}
Also used : INLINE_BODY_PROPERTY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.INLINE_BODY_PROPERTY) StringUtils(org.apache.commons.lang.StringUtils) MultitenantConstants(org.wso2.carbon.utils.multitenancy.MultitenantConstants) NOTIFICATION_SENDER_ERROR_PREFIX(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.NOTIFICATION_SENDER_ERROR_PREFIX) NotificationSenderUtils.generateSMSPublisher(org.wso2.carbon.identity.api.server.notification.sender.v1.core.utils.NotificationSenderUtils.generateSMSPublisher) ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER) TenantResourceManagementException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementException) EmailSenderUpdateRequest(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderUpdateRequest) CONFIG_MGT_ERROR_CODE_DELIMITER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.CONFIG_MGT_ERROR_CODE_DELIMITER) ERROR_CODE_CONFLICT_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_CONFLICT_PUBLISHER) RESOURCE_NOT_EXISTS_ERROR_CODE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.RESOURCE_NOT_EXISTS_ERROR_CODE) SMSSenderUpdateRequest(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest) ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) STREAM_NAME(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.STREAM_NAME) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) PASSWORD(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PASSWORD) Map(java.util.Map) ERROR_CODE_SMS_PROVIDER_REQUIRED(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PROVIDER_REQUIRED) SMS_PUBLISHER_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMS_PUBLISHER_TYPE) ERROR_CODE_SMS_PROVIDER_URL_REQUIRED(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PROVIDER_URL_REQUIRED) ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER) KEY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.KEY) NotificationSenderManagementConstants(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants) PUBLISHER_RESOURCE_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PUBLISHER_RESOURCE_TYPE) SMTP_SERVER_HOST(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMTP_SERVER_HOST) ERROR_CODE_SMS_PAYLOAD_NOT_FOUND(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PAYLOAD_NOT_FOUND) TenantResourceManagementClientException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException) ERROR_CODE_PARSER_CONFIG_EXCEPTION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_PARSER_CONFIG_EXCEPTION) Collectors(java.util.stream.Collectors) ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER) SMSProviderTemplate(org.wso2.carbon.email.mgt.model.SMSProviderTemplate) ConfigurationManagementServerException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException) List(java.util.List) SMTP_PORT(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMTP_PORT) INTERNAL_PROPERTIES(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.INTERNAL_PROPERTIES) USERNAME(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.USERNAME) Response(javax.ws.rs.core.Response) PROVIDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PROVIDER) ConfigurationManagementClientException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException) DEFAULT_EMAIL_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.DEFAULT_EMAIL_PUBLISHER) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_NO_RESOURCE_EXISTS(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_NO_RESOURCE_EXISTS) PUBLISHER_TYPE_PROPERTY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PUBLISHER_TYPE_PROPERTY) SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SENDER) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantResourceManagementServerException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementServerException) ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER) TransformerException(javax.xml.transform.TransformerException) SMSProviderPayloadTemplateManager(org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager) ERROR_CODE_RESOURCE_RE_DEPLOY_ERROR(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_RESOURCE_RE_DEPLOY_ERROR) ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND) SECRET(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SECRET) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) NotificationSenderServiceHolder(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderServiceHolder) ArrayList(java.util.ArrayList) ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT) CollectionUtils(org.apache.commons.collections.CollectionUtils) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) Properties(org.wso2.carbon.identity.api.server.notification.sender.v1.model.Properties) EMAIL_PUBLISHER_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.EMAIL_PUBLISHER_TYPE) EmailSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderAdd) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) STREAM_VERSION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.STREAM_VERSION) NotificationSenderUtils.generateEmailPublisher(org.wso2.carbon.identity.api.server.notification.sender.v1.core.utils.NotificationSenderUtils.generateEmailPublisher) EmailSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSender) PROVIDER_URL(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PROVIDER_URL) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) SMSSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSender) SMSSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderAdd) Attribute(org.wso2.carbon.identity.configuration.mgt.core.model.Attribute) ERROR_CODE_TRANSFORMER_EXCEPTION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_TRANSFORMER_EXCEPTION) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DEFAULT_SMS_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.DEFAULT_SMS_PUBLISHER) FROM_ADDRESS(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.FROM_ADDRESS) Log(org.apache.commons.logging.Log) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) InputStream(java.io.InputStream) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException)

Example 3 with EventPublisherConfigurationException

use of org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException in project identity-api-server by wso2.

the class NotificationSenderManagementService method validateSmsSenderUpdateRequestAndGetPublisherInSuperTenant.

/**
 * Validate the SMS Sender put request and get the corresponding super tenant's event publisher configuration.
 *
 * @param senderName             SMS sender's name.
 * @param smsSenderUpdateRequest SMS Sender put request.
 * @param tenantId               Tenant id.
 * @return Corresponding super tenant's event publisher's configuration.
 */
private EventPublisherConfiguration validateSmsSenderUpdateRequestAndGetPublisherInSuperTenant(String senderName, SMSSenderUpdateRequest smsSenderUpdateRequest, int tenantId) {
    EventPublisherConfiguration publisherInSuperTenant = null;
    EventPublisherService eventPublisherService = NotificationSenderServiceHolder.getEventPublisherService();
    SMSProviderPayloadTemplateManager smsProviderPayloadTemplateManager = NotificationSenderServiceHolder.getSmsProviderPayloadTemplateManager();
    Map<String, String> properties = new HashMap<>();
    if (smsSenderUpdateRequest.getProperties() != null) {
        smsSenderUpdateRequest.getProperties().stream().map(property -> properties.put(property.getKey(), property.getValue())).collect(Collectors.toList());
    }
    try {
        // Check whether a publisher exists to replace.
        NotificationSenderServiceHolder.getNotificationSenderConfigManager().getResource(PUBLISHER_RESOURCE_TYPE, senderName);
        if (StringUtils.isEmpty(smsSenderUpdateRequest.getProvider())) {
            throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PROVIDER_REQUIRED, null);
        }
        if (StringUtils.isEmpty(properties.get(INLINE_BODY_PROPERTY))) {
            SMSProviderTemplate sendSmsAPIPayload = smsProviderPayloadTemplateManager.getSMSProviderPayloadTemplateByProvider(smsSenderUpdateRequest.getProvider());
            if (sendSmsAPIPayload == null) {
                throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PAYLOAD_NOT_FOUND, smsSenderUpdateRequest.getProvider());
            }
        }
        if (StringUtils.isEmpty(smsSenderUpdateRequest.getProviderURL())) {
            throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PROVIDER_URL_REQUIRED, null);
        }
        startSuperTenantFlow();
        List<EventPublisherConfiguration> activeEventPublisherConfigurations = eventPublisherService.getAllActiveEventPublisherConfigurations();
        if (activeEventPublisherConfigurations == null) {
            throw handleException(Response.Status.NOT_FOUND, ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND, "carbon.super");
        }
        startTenantFlow(tenantId);
        // Check whether the super tenant has a publisher with the defined name.
        publisherInSuperTenant = activeEventPublisherConfigurations.stream().filter(publisher -> publisher.getEventPublisherName().equals(senderName)).findAny().orElse(null);
        if (publisherInSuperTenant == null) {
            throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT, senderName);
        }
    } catch (ConfigurationManagementException e) {
        // If resource not found by id.
        if (RESOURCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) {
            throw handleConfigurationMgtException(e, ERROR_CODE_NO_RESOURCE_EXISTS, senderName);
        }
        throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER, senderName);
    } catch (EventPublisherConfigurationException e) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, e.getMessage());
    }
    return publisherInSuperTenant;
}
Also used : SMSProviderPayloadTemplateManager(org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager) INLINE_BODY_PROPERTY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.INLINE_BODY_PROPERTY) StringUtils(org.apache.commons.lang.StringUtils) MultitenantConstants(org.wso2.carbon.utils.multitenancy.MultitenantConstants) NOTIFICATION_SENDER_ERROR_PREFIX(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.NOTIFICATION_SENDER_ERROR_PREFIX) NotificationSenderUtils.generateSMSPublisher(org.wso2.carbon.identity.api.server.notification.sender.v1.core.utils.NotificationSenderUtils.generateSMSPublisher) ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER) TenantResourceManagementException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementException) EmailSenderUpdateRequest(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderUpdateRequest) CONFIG_MGT_ERROR_CODE_DELIMITER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.CONFIG_MGT_ERROR_CODE_DELIMITER) ERROR_CODE_CONFLICT_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_CONFLICT_PUBLISHER) RESOURCE_NOT_EXISTS_ERROR_CODE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.RESOURCE_NOT_EXISTS_ERROR_CODE) SMSSenderUpdateRequest(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest) ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) STREAM_NAME(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.STREAM_NAME) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) PASSWORD(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PASSWORD) Map(java.util.Map) ERROR_CODE_SMS_PROVIDER_REQUIRED(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PROVIDER_REQUIRED) SMS_PUBLISHER_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMS_PUBLISHER_TYPE) ERROR_CODE_SMS_PROVIDER_URL_REQUIRED(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PROVIDER_URL_REQUIRED) ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER) KEY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.KEY) NotificationSenderManagementConstants(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants) PUBLISHER_RESOURCE_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PUBLISHER_RESOURCE_TYPE) SMTP_SERVER_HOST(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMTP_SERVER_HOST) ERROR_CODE_SMS_PAYLOAD_NOT_FOUND(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PAYLOAD_NOT_FOUND) TenantResourceManagementClientException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException) ERROR_CODE_PARSER_CONFIG_EXCEPTION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_PARSER_CONFIG_EXCEPTION) Collectors(java.util.stream.Collectors) ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER) SMSProviderTemplate(org.wso2.carbon.email.mgt.model.SMSProviderTemplate) ConfigurationManagementServerException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException) List(java.util.List) SMTP_PORT(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMTP_PORT) INTERNAL_PROPERTIES(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.INTERNAL_PROPERTIES) USERNAME(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.USERNAME) Response(javax.ws.rs.core.Response) PROVIDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PROVIDER) ConfigurationManagementClientException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException) DEFAULT_EMAIL_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.DEFAULT_EMAIL_PUBLISHER) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_NO_RESOURCE_EXISTS(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_NO_RESOURCE_EXISTS) PUBLISHER_TYPE_PROPERTY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PUBLISHER_TYPE_PROPERTY) SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SENDER) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantResourceManagementServerException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementServerException) ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER) TransformerException(javax.xml.transform.TransformerException) SMSProviderPayloadTemplateManager(org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager) ERROR_CODE_RESOURCE_RE_DEPLOY_ERROR(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_RESOURCE_RE_DEPLOY_ERROR) ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND) SECRET(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SECRET) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) NotificationSenderServiceHolder(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderServiceHolder) ArrayList(java.util.ArrayList) ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT) CollectionUtils(org.apache.commons.collections.CollectionUtils) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) Properties(org.wso2.carbon.identity.api.server.notification.sender.v1.model.Properties) EMAIL_PUBLISHER_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.EMAIL_PUBLISHER_TYPE) EmailSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderAdd) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) STREAM_VERSION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.STREAM_VERSION) NotificationSenderUtils.generateEmailPublisher(org.wso2.carbon.identity.api.server.notification.sender.v1.core.utils.NotificationSenderUtils.generateEmailPublisher) EmailSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSender) PROVIDER_URL(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PROVIDER_URL) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) SMSSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSender) SMSSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderAdd) Attribute(org.wso2.carbon.identity.configuration.mgt.core.model.Attribute) ERROR_CODE_TRANSFORMER_EXCEPTION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_TRANSFORMER_EXCEPTION) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DEFAULT_SMS_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.DEFAULT_SMS_PUBLISHER) FROM_ADDRESS(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.FROM_ADDRESS) Log(org.apache.commons.logging.Log) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) InputStream(java.io.InputStream) SMSProviderTemplate(org.wso2.carbon.email.mgt.model.SMSProviderTemplate) HashMap(java.util.HashMap) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException)

Example 4 with EventPublisherConfigurationException

use of org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException in project identity-api-server by wso2.

the class NotificationSenderManagementService method validateEmailSenderAddAndGetPublisherInSuperTenant.

/**
 * Validate the email Sender post request and get the corresponding super tenant's event publisher configuration.
 *
 * @param emailSenderAdd Email sender post request.
 * @param tenantId       Tenant id.
 * @return Corresponding super tenant's event publisher's configuration.
 */
private EventPublisherConfiguration validateEmailSenderAddAndGetPublisherInSuperTenant(EmailSenderAdd emailSenderAdd, int tenantId) {
    String emailSenderAddName = emailSenderAdd.getName();
    EventPublisherConfiguration publisherInSuperTenant = null;
    EventPublisherService eventPublisherService = NotificationSenderServiceHolder.getEventPublisherService();
    List<EventPublisherConfiguration> activeEventPublisherConfigurations = null;
    try {
        startSuperTenantFlow();
        activeEventPublisherConfigurations = eventPublisherService.getAllActiveEventPublisherConfigurations();
        if (activeEventPublisherConfigurations == null) {
            throw handleException(Response.Status.NOT_FOUND, ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND, "carbon.super");
        }
        startTenantFlow(tenantId);
        // Set the default publisher name if name is not defined.
        if (StringUtils.isEmpty(emailSenderAdd.getName())) {
            emailSenderAddName = DEFAULT_EMAIL_PUBLISHER;
        }
        // Check whether the super tenant has a publisher with the defined name.
        String finalEmailSenderAddName = emailSenderAddName;
        publisherInSuperTenant = activeEventPublisherConfigurations.stream().filter(publisher -> publisher.getEventPublisherName().equals(finalEmailSenderAddName)).findAny().orElse(null);
        if (publisherInSuperTenant == null) {
            throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT, emailSenderAddName);
        }
        // Check whether a publisher already exists with the same name in the particular tenant to be added.
        Resource resource = NotificationSenderServiceHolder.getNotificationSenderConfigManager().getResource(PUBLISHER_RESOURCE_TYPE, emailSenderAddName);
        if (resource != null) {
            throw handleException(Response.Status.CONFLICT, ERROR_CODE_CONFLICT_PUBLISHER, emailSenderAddName);
        }
    } catch (EventPublisherConfigurationException e) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, e.getMessage());
    } catch (ConfigurationManagementException e) {
        if (!RESOURCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) {
            throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER, emailSenderAddName);
        }
    }
    return publisherInSuperTenant;
}
Also used : INLINE_BODY_PROPERTY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.INLINE_BODY_PROPERTY) StringUtils(org.apache.commons.lang.StringUtils) MultitenantConstants(org.wso2.carbon.utils.multitenancy.MultitenantConstants) NOTIFICATION_SENDER_ERROR_PREFIX(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.NOTIFICATION_SENDER_ERROR_PREFIX) NotificationSenderUtils.generateSMSPublisher(org.wso2.carbon.identity.api.server.notification.sender.v1.core.utils.NotificationSenderUtils.generateSMSPublisher) ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER) TenantResourceManagementException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementException) EmailSenderUpdateRequest(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderUpdateRequest) CONFIG_MGT_ERROR_CODE_DELIMITER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.CONFIG_MGT_ERROR_CODE_DELIMITER) ERROR_CODE_CONFLICT_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_CONFLICT_PUBLISHER) RESOURCE_NOT_EXISTS_ERROR_CODE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.RESOURCE_NOT_EXISTS_ERROR_CODE) SMSSenderUpdateRequest(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest) ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) STREAM_NAME(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.STREAM_NAME) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) PASSWORD(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PASSWORD) Map(java.util.Map) ERROR_CODE_SMS_PROVIDER_REQUIRED(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PROVIDER_REQUIRED) SMS_PUBLISHER_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMS_PUBLISHER_TYPE) ERROR_CODE_SMS_PROVIDER_URL_REQUIRED(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PROVIDER_URL_REQUIRED) ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER) KEY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.KEY) NotificationSenderManagementConstants(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants) PUBLISHER_RESOURCE_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PUBLISHER_RESOURCE_TYPE) SMTP_SERVER_HOST(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMTP_SERVER_HOST) ERROR_CODE_SMS_PAYLOAD_NOT_FOUND(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PAYLOAD_NOT_FOUND) TenantResourceManagementClientException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException) ERROR_CODE_PARSER_CONFIG_EXCEPTION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_PARSER_CONFIG_EXCEPTION) Collectors(java.util.stream.Collectors) ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER) SMSProviderTemplate(org.wso2.carbon.email.mgt.model.SMSProviderTemplate) ConfigurationManagementServerException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException) List(java.util.List) SMTP_PORT(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMTP_PORT) INTERNAL_PROPERTIES(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.INTERNAL_PROPERTIES) USERNAME(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.USERNAME) Response(javax.ws.rs.core.Response) PROVIDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PROVIDER) ConfigurationManagementClientException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException) DEFAULT_EMAIL_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.DEFAULT_EMAIL_PUBLISHER) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_NO_RESOURCE_EXISTS(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_NO_RESOURCE_EXISTS) PUBLISHER_TYPE_PROPERTY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PUBLISHER_TYPE_PROPERTY) SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SENDER) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantResourceManagementServerException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementServerException) ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER) TransformerException(javax.xml.transform.TransformerException) SMSProviderPayloadTemplateManager(org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager) ERROR_CODE_RESOURCE_RE_DEPLOY_ERROR(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_RESOURCE_RE_DEPLOY_ERROR) ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND) SECRET(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SECRET) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) NotificationSenderServiceHolder(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderServiceHolder) ArrayList(java.util.ArrayList) ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT) CollectionUtils(org.apache.commons.collections.CollectionUtils) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) Properties(org.wso2.carbon.identity.api.server.notification.sender.v1.model.Properties) EMAIL_PUBLISHER_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.EMAIL_PUBLISHER_TYPE) EmailSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderAdd) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) STREAM_VERSION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.STREAM_VERSION) NotificationSenderUtils.generateEmailPublisher(org.wso2.carbon.identity.api.server.notification.sender.v1.core.utils.NotificationSenderUtils.generateEmailPublisher) EmailSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSender) PROVIDER_URL(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PROVIDER_URL) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) SMSSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSender) SMSSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderAdd) Attribute(org.wso2.carbon.identity.configuration.mgt.core.model.Attribute) ERROR_CODE_TRANSFORMER_EXCEPTION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_TRANSFORMER_EXCEPTION) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DEFAULT_SMS_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.DEFAULT_SMS_PUBLISHER) FROM_ADDRESS(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.FROM_ADDRESS) Log(org.apache.commons.logging.Log) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) InputStream(java.io.InputStream) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException)

Example 5 with EventPublisherConfigurationException

use of org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException in project identity-api-server by wso2.

the class NotificationSenderManagementService method validateSMSSenderAddAndGetPublisherInSuperTenant.

/**
 * Validate the SMS Sender post request and get the corresponding super tenant's event publisher configuration.
 *
 * @param smsSenderAdd SMS sender post request.
 * @param tenantId     Tenant id.
 * @return Corresponding super tenant's event publisher's configuration.
 */
private EventPublisherConfiguration validateSMSSenderAddAndGetPublisherInSuperTenant(SMSSenderAdd smsSenderAdd, int tenantId) {
    String smsSenderAddName = smsSenderAdd.getName();
    EventPublisherConfiguration publisherInSuperTenant = null;
    EventPublisherService eventPublisherService = NotificationSenderServiceHolder.getEventPublisherService();
    SMSProviderPayloadTemplateManager smsProviderPayloadTemplateManager = NotificationSenderServiceHolder.getSmsProviderPayloadTemplateManager();
    List<EventPublisherConfiguration> activeEventPublisherConfigurations = null;
    Map<String, String> properties = new HashMap<>();
    if (smsSenderAdd.getProperties() != null) {
        smsSenderAdd.getProperties().stream().map(property -> properties.put(property.getKey(), property.getValue())).collect(Collectors.toList());
    }
    try {
        if (StringUtils.isEmpty(smsSenderAdd.getProvider())) {
            throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PROVIDER_REQUIRED, null);
        }
        if (StringUtils.isEmpty(properties.get(INLINE_BODY_PROPERTY))) {
            SMSProviderTemplate sendSmsAPIPayload = smsProviderPayloadTemplateManager.getSMSProviderPayloadTemplateByProvider(smsSenderAdd.getProvider());
            if (sendSmsAPIPayload == null) {
                throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PAYLOAD_NOT_FOUND, smsSenderAdd.getProvider());
            }
        }
        if (StringUtils.isEmpty(smsSenderAdd.getProviderURL())) {
            throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_SMS_PROVIDER_URL_REQUIRED, null);
        }
        startSuperTenantFlow();
        activeEventPublisherConfigurations = eventPublisherService.getAllActiveEventPublisherConfigurations();
        if (activeEventPublisherConfigurations == null) {
            throw handleException(Response.Status.NOT_FOUND, ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND, "carbon.super");
        }
        startTenantFlow(tenantId);
        // Set the default publisher name if name is not defined.
        if (StringUtils.isEmpty(smsSenderAdd.getName())) {
            smsSenderAddName = DEFAULT_SMS_PUBLISHER;
        } else {
            smsSenderAddName = smsSenderAdd.getName();
        }
        // Check whether the super tenant has a publisher with the defined name.
        String finalSmsSenderAddName = smsSenderAddName;
        publisherInSuperTenant = activeEventPublisherConfigurations.stream().filter(publisher -> publisher.getEventPublisherName().equals(finalSmsSenderAddName)).findAny().orElse(null);
        if (publisherInSuperTenant == null) {
            throw handleException(Response.Status.BAD_REQUEST, ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT, smsSenderAddName);
        }
        // Check whether a publisher already exists with the same name in the particular tenant to be added.
        Resource resource = NotificationSenderServiceHolder.getNotificationSenderConfigManager().getResource(PUBLISHER_RESOURCE_TYPE, smsSenderAddName);
        if (resource != null) {
            throw handleException(Response.Status.CONFLICT, ERROR_CODE_CONFLICT_PUBLISHER, smsSenderAddName);
        }
    } catch (EventPublisherConfigurationException e) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER, e.getMessage());
    } catch (ConfigurationManagementException e) {
        if (!RESOURCE_NOT_EXISTS_ERROR_CODE.equals(e.getErrorCode())) {
            throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER, smsSenderAddName);
        }
    }
    return publisherInSuperTenant;
}
Also used : SMSProviderPayloadTemplateManager(org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager) INLINE_BODY_PROPERTY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.INLINE_BODY_PROPERTY) StringUtils(org.apache.commons.lang.StringUtils) MultitenantConstants(org.wso2.carbon.utils.multitenancy.MultitenantConstants) NOTIFICATION_SENDER_ERROR_PREFIX(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.NOTIFICATION_SENDER_ERROR_PREFIX) NotificationSenderUtils.generateSMSPublisher(org.wso2.carbon.identity.api.server.notification.sender.v1.core.utils.NotificationSenderUtils.generateSMSPublisher) ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_ADDING_NOTIFICATION_SENDER) TenantResourceManagementException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementException) EmailSenderUpdateRequest(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderUpdateRequest) CONFIG_MGT_ERROR_CODE_DELIMITER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.CONFIG_MGT_ERROR_CODE_DELIMITER) ERROR_CODE_CONFLICT_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_CONFLICT_PUBLISHER) RESOURCE_NOT_EXISTS_ERROR_CODE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.RESOURCE_NOT_EXISTS_ERROR_CODE) SMSSenderUpdateRequest(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest) ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_DELETING_NOTIFICATION_SENDER) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) STREAM_NAME(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.STREAM_NAME) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) PASSWORD(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PASSWORD) Map(java.util.Map) ERROR_CODE_SMS_PROVIDER_REQUIRED(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PROVIDER_REQUIRED) SMS_PUBLISHER_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMS_PUBLISHER_TYPE) ERROR_CODE_SMS_PROVIDER_URL_REQUIRED(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PROVIDER_URL_REQUIRED) ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SERVER_ERRORS_GETTING_EVENT_PUBLISHER) KEY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.KEY) NotificationSenderManagementConstants(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants) PUBLISHER_RESOURCE_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PUBLISHER_RESOURCE_TYPE) SMTP_SERVER_HOST(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMTP_SERVER_HOST) ERROR_CODE_SMS_PAYLOAD_NOT_FOUND(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_SMS_PAYLOAD_NOT_FOUND) TenantResourceManagementClientException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException) ERROR_CODE_PARSER_CONFIG_EXCEPTION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_PARSER_CONFIG_EXCEPTION) Collectors(java.util.stream.Collectors) ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDER) SMSProviderTemplate(org.wso2.carbon.email.mgt.model.SMSProviderTemplate) ConfigurationManagementServerException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException) List(java.util.List) SMTP_PORT(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SMTP_PORT) INTERNAL_PROPERTIES(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.INTERNAL_PROPERTIES) USERNAME(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.USERNAME) Response(javax.ws.rs.core.Response) PROVIDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PROVIDER) ConfigurationManagementClientException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException) DEFAULT_EMAIL_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.DEFAULT_EMAIL_PUBLISHER) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_NO_RESOURCE_EXISTS(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_NO_RESOURCE_EXISTS) PUBLISHER_TYPE_PROPERTY(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PUBLISHER_TYPE_PROPERTY) SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SENDER) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) TenantResourceManagementServerException(org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementServerException) ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER) TransformerException(javax.xml.transform.TransformerException) SMSProviderPayloadTemplateManager(org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager) ERROR_CODE_RESOURCE_RE_DEPLOY_ERROR(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_RESOURCE_RE_DEPLOY_ERROR) ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_NO_ACTIVE_PUBLISHERS_FOUND) SECRET(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.SECRET) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) NotificationSenderServiceHolder(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderServiceHolder) ArrayList(java.util.ArrayList) ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_PUBLISHER_NOT_EXISTS_IN_SUPER_TENANT) CollectionUtils(org.apache.commons.collections.CollectionUtils) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) Properties(org.wso2.carbon.identity.api.server.notification.sender.v1.model.Properties) EMAIL_PUBLISHER_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.EMAIL_PUBLISHER_TYPE) EmailSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSenderAdd) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_ERROR_GETTING_NOTIFICATION_SENDERS_BY_TYPE) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) STREAM_VERSION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.STREAM_VERSION) NotificationSenderUtils.generateEmailPublisher(org.wso2.carbon.identity.api.server.notification.sender.v1.core.utils.NotificationSenderUtils.generateEmailPublisher) EmailSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.EmailSender) PROVIDER_URL(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.PROVIDER_URL) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) SMSSender(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSender) SMSSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderAdd) Attribute(org.wso2.carbon.identity.configuration.mgt.core.model.Attribute) ERROR_CODE_TRANSFORMER_EXCEPTION(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.ErrorMessage.ERROR_CODE_TRANSFORMER_EXCEPTION) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DEFAULT_SMS_PUBLISHER(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.DEFAULT_SMS_PUBLISHER) FROM_ADDRESS(org.wso2.carbon.identity.api.server.notification.sender.common.NotificationSenderManagementConstants.FROM_ADDRESS) Log(org.apache.commons.logging.Log) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) InputStream(java.io.InputStream) SMSProviderTemplate(org.wso2.carbon.email.mgt.model.SMSProviderTemplate) HashMap(java.util.HashMap) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) EventPublisherService(org.wso2.carbon.event.publisher.core.EventPublisherService) EventPublisherConfigurationException(org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException)

Aggregations

EventPublisherService (org.wso2.carbon.event.publisher.core.EventPublisherService)6 EventPublisherConfiguration (org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration)6 InputStream (java.io.InputStream)5 EventPublisherConfigurationException (org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException)5 ConfigurationManagementClientException (org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException)5 ConfigurationManagementException (org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException)5 Resource (org.wso2.carbon.identity.configuration.mgt.core.model.Resource)5 ResourceFile (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile)5 TenantResourceManagementClientException (org.wso2.carbon.identity.tenant.resource.manager.exception.TenantResourceManagementClientException)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Response (javax.ws.rs.core.Response)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 TransformerException (javax.xml.transform.TransformerException)4 CollectionUtils (org.apache.commons.collections.CollectionUtils)4 StringUtils (org.apache.commons.lang.StringUtils)4 Log (org.apache.commons.logging.Log)4