From e3998ef3d430afddddf79cccda087741968f8df9 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 6 Feb 2024 23:04:25 -0800 Subject: [PATCH] Migrate to springboot emai. --- .../config/common/CommonConfig.java | 1 - .../config/rest/RestAppConfig.java | 2 +- .../wisemapping/service/MailerService.java | 13 ++--- .../wisemapping/service/NotifierFilter.java | 54 ------------------- wise-api/src/main/resources/application.yml | 32 ++++++----- .../resources/spring/wisemapping-mail.xml | 31 ----------- 6 files changed, 23 insertions(+), 110 deletions(-) delete mode 100644 wise-api/src/main/java/com/wisemapping/service/NotifierFilter.java delete mode 100755 wise-api/src/main/resources/spring/wisemapping-mail.xml diff --git a/wise-api/src/main/java/com/wisemapping/config/common/CommonConfig.java b/wise-api/src/main/java/com/wisemapping/config/common/CommonConfig.java index 52d113cb..f945cbdf 100644 --- a/wise-api/src/main/java/com/wisemapping/config/common/CommonConfig.java +++ b/wise-api/src/main/java/com/wisemapping/config/common/CommonConfig.java @@ -12,6 +12,5 @@ import org.springframework.context.annotation.ImportResource; @ComponentScan(basePackageClasses = {AuthenticationProvider.class, MindmapServiceImpl.class, LabelManagerImpl.class, VelocityEngineUtils.class}) @Import({JPAConfig.class, SecurityConfig.class}) @EnableAutoConfiguration -@ImportResource(value = {"classpath:spring/wisemapping-mail.xml"}) public class CommonConfig { } diff --git a/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java b/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java index 7ee683a9..65546bd1 100644 --- a/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java +++ b/wise-api/src/main/java/com/wisemapping/config/rest/RestAppConfig.java @@ -54,7 +54,7 @@ public class RestAppConfig { })) .csrf(AbstractHttpConfigurer::disable) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) -// .httpBasic(withDefaults()) + .httpBasic(withDefaults()) .build(); } } diff --git a/wise-api/src/main/java/com/wisemapping/service/MailerService.java b/wise-api/src/main/java/com/wisemapping/service/MailerService.java index d38d42ca..9e04da1c 100644 --- a/wise-api/src/main/java/com/wisemapping/service/MailerService.java +++ b/wise-api/src/main/java/com/wisemapping/service/MailerService.java @@ -38,21 +38,18 @@ public final class MailerService { //~ Instance fields ...................................................................................... -// @Autowired + @Autowired private JavaMailSender mailSender; @Autowired private VelocityEngineWrapper velocityEngineWrapper; - @Value("${mail.serverSendEmail}") + @Value("${app.mail.serverSendEmail}") private String serverFromEmail; - @Value("${mail.supportEmail}") + @Value("${app.mail.supportEmail}") private String supportEmail; - @Value("${mail.errorReporterEmail:}") - private String errorReporterEmail; - //~ Methods .............................................................................................. public String getServerSenderEmail() { @@ -86,8 +83,4 @@ public final class MailerService { public String getSupportEmail() { return supportEmail; } - - public String getErrorReporterEmail() { - return errorReporterEmail; - } } diff --git a/wise-api/src/main/java/com/wisemapping/service/NotifierFilter.java b/wise-api/src/main/java/com/wisemapping/service/NotifierFilter.java deleted file mode 100644 index d6f171a9..00000000 --- a/wise-api/src/main/java/com/wisemapping/service/NotifierFilter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright [2022] [wisemapping] - * - * Licensed under WiseMapping Public License, Version 1.0 (the "License"). - * It is basically the Apache License, Version 2.0 (the "License") plus the - * "powered by wisemapping" text requirement on every single page; - * you may not use this file except in compliance with the License. - * You may obtain a copy of the license at - * - * http://www.wisemapping.org/license - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.wisemapping.service; - -import org.jetbrains.annotations.NotNull; -import org.springframework.util.DigestUtils; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -public class NotifierFilter { - public static final int MAX_CACHE_ENTRY = 500; - private final Map emailByMd5 = Collections.synchronizedMap(new LinkedHashMap() { - protected boolean removeEldestEntry(Map.Entry eldest) { - return size() > MAX_CACHE_ENTRY; - } - }); - - public boolean hasBeenSend(@NotNull final String email, @NotNull final Map model) { - - final StringBuilder buff = new StringBuilder(); - for (String key : model.keySet()) { - if (!key.equals("mapXML")) { - buff.append(key); - buff.append("="); - buff.append(model.get(key)); - } - } - - final String digest = DigestUtils.md5DigestAsHex(buff.toString().getBytes()); - boolean result = emailByMd5.containsKey(digest); - if (!result) { - emailByMd5.put(digest, email); - } - return result; - } - -} diff --git a/wise-api/src/main/resources/application.yml b/wise-api/src/main/resources/application.yml index b02c1c65..13c110ba 100755 --- a/wise-api/src/main/resources/application.yml +++ b/wise-api/src/main/resources/application.yml @@ -1,6 +1,17 @@ # SpringBoot Configuration ... spring: + mail: + host: smtp.example.com + port: 25 + username: setusername + password: setpassword + properties: + mail: + smtp: + connectiontimeout: 5000 + timeout: 3000 + writetimeout: 5000 output: ansi: enabled=always: @@ -38,13 +49,20 @@ logging: root: TRACE # Application Configuration. - app: jwt: secret: dlqxKAg685SaKhsQXIMeM=JWCw3bkl3Ei3Tb7LMlnd19oMd66burPNlJ0Po1qguyjgpakQTk2CN3 expirationMin: 10080 # One week admin: user: admin@wisemapping.org + mail: + serverSendEmail: root@localhost + supportEmail: root@localhost + + + + + google: ads: @@ -56,18 +74,6 @@ google: enabled: true secretKey: 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe siteKey: 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI -mail: - password: '' - serverSendEmail: root@localhost - smtp: - auth: false - host: localhost - port: 25 - quitwait: false - starttls: - enable: false - supportEmail: root@localhost - username: root security: oauth2: google: diff --git a/wise-api/src/main/resources/spring/wisemapping-mail.xml b/wise-api/src/main/resources/spring/wisemapping-mail.xml deleted file mode 100755 index 7a097fe9..00000000 --- a/wise-api/src/main/resources/spring/wisemapping-mail.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - ${mail.smtp.auth:false} - ${mail.smtp.starttls.enable:false} - ${mail.smtp.quitwait:true} - - - - - - - - - messages - - - -