-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
1,504 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...rc/main/java/edu/internet2/tier/shibboleth/admin/ui/configuration/EmailConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.configuration; | ||
|
||
import edu.internet2.tier.shibboleth.admin.ui.security.repository.UserRepository; | ||
import edu.internet2.tier.shibboleth.admin.ui.service.EmailService; | ||
import edu.internet2.tier.shibboleth.admin.ui.service.EmailServiceImpl; | ||
import lombok.Setter; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.support.ResourceBundleMessageSource; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.thymeleaf.TemplateEngine; | ||
import org.thymeleaf.spring5.SpringTemplateEngine; | ||
import org.thymeleaf.templatemode.TemplateMode; | ||
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; | ||
import org.thymeleaf.templateresolver.ITemplateResolver; | ||
|
||
import java.util.Collections; | ||
|
||
/** | ||
* @author Bill Smith (wsmith@unicon.net) | ||
*/ | ||
@Configuration | ||
@ConfigurationProperties("shibui.mail") | ||
public class EmailConfiguration { | ||
|
||
private static final String EMAIL_TEMPLATE_ENCODING = "UTF-8"; | ||
|
||
//Configured via @ConfigurationProperties (using setter method) with 'shibui.mail.text-email-template-path-prefix' property and | ||
// default value set here if that property is not explicitly set in application.properties | ||
@Setter | ||
private String textEmailTemplatePathPrefix = "/mail/text/"; | ||
|
||
//Configured via @ConfigurationProperties (using setter method) with 'shibui.mail.html-email-template-path-prefix' property and | ||
// default value set here if that property is not explicitly set in application.properties | ||
@Setter | ||
private String htmlEmailTemplatePathPrefix = "/mail/html/"; | ||
|
||
//Configured via @ConfigurationProperties (using setter method) with 'shibui.mail.system-email-address' property and | ||
// default value set here if that property is not explicitly set in application.properties | ||
@Setter | ||
private String systemEmailAddress = "doNotReply@shibui.org"; | ||
|
||
@Autowired | ||
private JavaMailSender javaMailSender; | ||
|
||
@Autowired | ||
private UserRepository userRepository; | ||
|
||
@Bean | ||
public ResourceBundleMessageSource emailMessageSource() { | ||
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); | ||
messageSource.setBasename("mail/mailMessages"); | ||
return messageSource; | ||
} | ||
|
||
@Bean | ||
public TemplateEngine textEmailTemplateEngine() { | ||
final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); | ||
templateEngine.addTemplateResolver(textTemplateResolver()); | ||
templateEngine.setTemplateEngineMessageSource(emailMessageSource()); | ||
return templateEngine; | ||
} | ||
|
||
@Bean | ||
public TemplateEngine htmlEmailTemplateEngine() { | ||
final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); | ||
templateEngine.addTemplateResolver(htmlTemplateResolver()); | ||
templateEngine.setTemplateEngineMessageSource(emailMessageSource()); | ||
return templateEngine; | ||
} | ||
|
||
private ITemplateResolver textTemplateResolver() { | ||
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); | ||
templateResolver.setOrder(1); | ||
templateResolver.setResolvablePatterns(Collections.singleton("*")); | ||
templateResolver.setPrefix(textEmailTemplatePathPrefix); | ||
templateResolver.setSuffix(".txt"); | ||
templateResolver.setTemplateMode(TemplateMode.TEXT); | ||
templateResolver.setCharacterEncoding(EMAIL_TEMPLATE_ENCODING); | ||
templateResolver.setCacheable(false); | ||
return templateResolver; | ||
} | ||
|
||
private ITemplateResolver htmlTemplateResolver() { | ||
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); | ||
templateResolver.setOrder(1); | ||
templateResolver.setResolvablePatterns(Collections.singleton("*")); | ||
templateResolver.setPrefix(htmlEmailTemplatePathPrefix); | ||
templateResolver.setSuffix(".html"); | ||
templateResolver.setTemplateMode(TemplateMode.HTML); | ||
templateResolver.setCharacterEncoding(EMAIL_TEMPLATE_ENCODING); | ||
templateResolver.setCacheable(false); | ||
return templateResolver; | ||
} | ||
|
||
@Bean | ||
public EmailService emailService() { | ||
return new EmailServiceImpl(javaMailSender, | ||
emailMessageSource(), | ||
textEmailTemplateEngine(), | ||
htmlEmailTemplateEngine(), | ||
systemEmailAddress, | ||
userRepository); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/edu/internet2/tier/shibboleth/admin/ui/service/EmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package edu.internet2.tier.shibboleth.admin.ui.service; | ||
|
||
import javax.mail.MessagingException; | ||
import java.util.Locale; | ||
|
||
/** | ||
* @author Bill Smith (wsmith@unicon.net) | ||
*/ | ||
public interface EmailService { | ||
void sendMail(String emailTemplate, String fromAddress, String[] recipients, String subject, Locale locale) throws MessagingException; | ||
void sendNewUserMail(String newUsername) throws MessagingException; | ||
String[] getSystemAdminEmailAddresses(); | ||
} |
Oops, something went wrong.