Search in sources :

Example 1 with SMSSenderUpdateRequest

use of org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest in project identity-api-server by wso2.

the class NotificationSenderManagementService method buildSMSSenderAddFromSMSSenderUpdateRequest.

/**
 * Build SMS sender add object from SMS sender update request.
 *
 * @param senderName             SMS sender's name.
 * @param smsSenderUpdateRequest SMS sender's update request body.
 * @return SMS sender add object.
 */
private SMSSenderAdd buildSMSSenderAddFromSMSSenderUpdateRequest(String senderName, SMSSenderUpdateRequest smsSenderUpdateRequest) {
    SMSSenderAdd smsSenderAdd = new SMSSenderAdd();
    smsSenderAdd.setName(senderName);
    smsSenderAdd.setProvider(smsSenderUpdateRequest.getProvider());
    smsSenderAdd.setProviderURL(smsSenderUpdateRequest.getProviderURL());
    smsSenderAdd.setKey(smsSenderUpdateRequest.getKey());
    smsSenderAdd.setSecret(smsSenderUpdateRequest.getSecret());
    smsSenderAdd.setSender(smsSenderUpdateRequest.getSender());
    smsSenderAdd.setProperties(smsSenderUpdateRequest.getProperties());
    return smsSenderAdd;
}
Also used : SMSSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderAdd)

Example 2 with SMSSenderUpdateRequest

use of org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest in project identity-api-server by wso2.

the class NotificationSenderManagementService method updateSMSSender.

/**
 * Update sms sender details by name.
 *
 * @param senderName             SMS sender' name.
 * @param smsSenderUpdateRequest SMS sender's updated configurations.
 * @return Updated SMS sender.
 */
public SMSSender updateSMSSender(String senderName, SMSSenderUpdateRequest smsSenderUpdateRequest) {
    Resource smsSenderResource = null;
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    EventPublisherConfiguration publisherInSuperTenant = validateSmsSenderUpdateRequestAndGetPublisherInSuperTenant(senderName, smsSenderUpdateRequest, tenantId);
    SMSSenderAdd smsSenderAdd = buildSMSSenderAddFromSMSSenderUpdateRequest(senderName, smsSenderUpdateRequest);
    addDefaultProperties(smsSenderAdd, publisherInSuperTenant);
    try {
        InputStream inputStream = generateSMSPublisher(smsSenderAdd);
        smsSenderResource = buildResourceFromSmsSenderAdd(smsSenderAdd, inputStream);
        NotificationSenderServiceHolder.getNotificationSenderConfigManager().replaceResource(PUBLISHER_RESOURCE_TYPE, smsSenderResource);
    } catch (ConfigurationManagementException e) {
        throw handleConfigurationMgtException(e, ERROR_CODE_ERROR_UPDATING_NOTIFICATION_SENDER, senderName);
    } catch (ParserConfigurationException e) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_PARSER_CONFIG_EXCEPTION, e.getMessage());
    } catch (TransformerException e) {
        throw handleException(Response.Status.INTERNAL_SERVER_ERROR, ERROR_CODE_TRANSFORMER_EXCEPTION, e.getMessage());
    }
    return buildSmsSenderFromResource(smsSenderResource);
}
Also used : InputStream(java.io.InputStream) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) EventPublisherConfiguration(org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) SMSSenderAdd(org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderAdd) TransformerException(javax.xml.transform.TransformerException)

Example 3 with SMSSenderUpdateRequest

use of org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderUpdateRequest 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)

Aggregations

InputStream (java.io.InputStream)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 EventPublisherConfiguration (org.wso2.carbon.event.publisher.core.config.EventPublisherConfiguration)2 SMSSenderAdd (org.wso2.carbon.identity.api.server.notification.sender.v1.model.SMSSenderAdd)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Response (javax.ws.rs.core.Response)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang.StringUtils)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 SMSProviderPayloadTemplateManager (org.wso2.carbon.email.mgt.SMSProviderPayloadTemplateManager)1 SMSProviderTemplate (org.wso2.carbon.email.mgt.model.SMSProviderTemplate)1 EventPublisherService (org.wso2.carbon.event.publisher.core.EventPublisherService)1 EventPublisherConfigurationException (org.wso2.carbon.event.publisher.core.exception.EventPublisherConfigurationException)1