Migrate to springboot emai.

This commit is contained in:
Paulo Gustavo Veiga 2024-02-06 23:04:25 -08:00
parent 88d5f0df43
commit e3998ef3d4
6 changed files with 23 additions and 110 deletions

View File

@ -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 {
}

View File

@ -54,7 +54,7 @@ public class RestAppConfig {
}))
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
// .httpBasic(withDefaults())
.httpBasic(withDefaults())
.build();
}
}

View File

@ -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;
}
}

View File

@ -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<String, String> emailByMd5 = Collections.synchronizedMap(new LinkedHashMap<String, String>() {
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > MAX_CACHE_ENTRY;
}
});
public boolean hasBeenSend(@NotNull final String email, @NotNull final Map<String, String> 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;
}
}

View File

@ -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:

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.smtp.host}"/>
<property name="port" value="${mail.smtp.port}"/>
<property name="protocol" value="smtp"/>
<property name="username" value="${mail.username}"/>
<property name="password" value="${mail.password}"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">${mail.smtp.auth:false}</prop>
<prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable:false}</prop>
<prop key="mail.smtp.quitwait">${mail.smtp.quitwait:true}</prop>
</props>
</property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="defaultEncoding" value="UTF-8"/>
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>
</beans>