Remove SES sender, it breaks shit
This commit is contained in:
parent
16793f1813
commit
92f4d414a5
3 changed files with 0 additions and 97 deletions
|
@ -1,50 +0,0 @@
|
||||||
package com.gwidgets.providers;
|
|
||||||
|
|
||||||
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
|
|
||||||
import com.amazonaws.services.simpleemail.model.Body;
|
|
||||||
import com.amazonaws.services.simpleemail.model.Content;
|
|
||||||
import com.amazonaws.services.simpleemail.model.Destination;
|
|
||||||
import com.amazonaws.services.simpleemail.model.Message;
|
|
||||||
import com.amazonaws.services.simpleemail.model.SendEmailRequest;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.jboss.logging.Logger;
|
|
||||||
import org.keycloak.email.EmailException;
|
|
||||||
import org.keycloak.email.EmailSenderProvider;
|
|
||||||
import org.keycloak.models.UserModel;
|
|
||||||
|
|
||||||
public class SESEmailSenderProvider implements EmailSenderProvider {
|
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger("org.keycloak.events");
|
|
||||||
|
|
||||||
private final AmazonSimpleEmailService sesClient;
|
|
||||||
|
|
||||||
public SESEmailSenderProvider(
|
|
||||||
AmazonSimpleEmailService sesClient) {
|
|
||||||
this.sesClient = sesClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(Map<String, String> config, UserModel user, String subject, String textBody,
|
|
||||||
String htmlBody) throws EmailException {
|
|
||||||
this.send(config, user.getEmail(), subject, textBody, htmlBody);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(Map<String, String> config, String address, String subject, String textBody, String htmlBody) throws EmailException {
|
|
||||||
log.info("attempting to send email using aws ses for " + address);
|
|
||||||
|
|
||||||
Message message = new Message().withSubject(new Content().withData(subject))
|
|
||||||
.withBody(new Body().withHtml(new Content().withData(htmlBody))
|
|
||||||
.withText(new Content().withData(textBody).withCharset("UTF-8")));
|
|
||||||
|
|
||||||
SendEmailRequest sendEmailRequest = new SendEmailRequest()
|
|
||||||
.withSource("example<" + config.get("from") + ">")
|
|
||||||
.withMessage(message).withDestination(new Destination().withToAddresses(address));
|
|
||||||
|
|
||||||
sesClient.sendEmail(sendEmailRequest);
|
|
||||||
log.info("email sent to " + address + " successfully");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package com.gwidgets.providers;
|
|
||||||
|
|
||||||
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
|
|
||||||
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
|
|
||||||
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
|
|
||||||
import java.util.Objects;
|
|
||||||
import org.keycloak.Config.Scope;
|
|
||||||
import org.keycloak.email.EmailSenderProvider;
|
|
||||||
import org.keycloak.email.EmailSenderProviderFactory;
|
|
||||||
import org.keycloak.models.KeycloakSession;
|
|
||||||
import org.keycloak.models.KeycloakSessionFactory;
|
|
||||||
|
|
||||||
public class SESEmailSenderProviderFactory implements EmailSenderProviderFactory {
|
|
||||||
|
|
||||||
private static AmazonSimpleEmailService sesClientInstance;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EmailSenderProvider create(KeycloakSession session) {
|
|
||||||
//using singleton pattern to avoid creating the client each time create is called
|
|
||||||
if (sesClientInstance == null) {
|
|
||||||
String awsRegion = Objects.requireNonNull(System.getenv("AWS_REGION"));
|
|
||||||
|
|
||||||
sesClientInstance =
|
|
||||||
AmazonSimpleEmailServiceClientBuilder
|
|
||||||
.standard().withCredentials(new EnvironmentVariableCredentialsProvider())
|
|
||||||
.withRegion(awsRegion)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SESEmailSenderProvider(sesClientInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init(Scope config) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postInit(KeycloakSessionFactory factory) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void close() {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return "default";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
com.gwidgets.providers.SESEmailSenderProviderFactory
|
|
Loading…
Add table
Reference in a new issue