Continue structural port from Spring Boot to Undertow
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
package io.kamax.mxisd.threepid.connector;
|
||||
|
||||
public interface IThreePidConnector {
|
||||
public interface ThreePidConnector {
|
||||
|
||||
String getId();
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.connector.email;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.connector.EmailSmtpConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class BuiltInEmailConnectorSupplier implements EmailConnectorSupplier {
|
||||
|
||||
@Override
|
||||
public Optional<EmailConnector> apply(EmailConfig cfg, Mxisd mxisd) {
|
||||
if (StringUtils.equals(EmailSmtpConnector.ID, cfg.getConnector())) {
|
||||
EmailSmtpConfig smtpCfg = GsonUtil.get().fromJson(cfg.getConnectors().getOrDefault(EmailSmtpConnector.ID, new JsonObject()), EmailSmtpConfig.class);
|
||||
return Optional.of(new EmailSmtpConnector(smtpCfg));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,9 +21,9 @@
|
||||
package io.kamax.mxisd.threepid.connector.email;
|
||||
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.threepid.connector.IThreePidConnector;
|
||||
import io.kamax.mxisd.threepid.connector.ThreePidConnector;
|
||||
|
||||
public interface IEmailConnector extends IThreePidConnector {
|
||||
public interface EmailConnector extends ThreePidConnector {
|
||||
|
||||
@Override
|
||||
default String getMedium() {
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.connector.email;
|
||||
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface EmailConnectorSupplier extends BiFunction<EmailConfig, Mxisd, Optional<EmailConnector>> {
|
||||
|
||||
}
|
||||
@@ -40,7 +40,9 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
public class EmailSmtpConnector implements IEmailConnector {
|
||||
public class EmailSmtpConnector implements EmailConnector {
|
||||
|
||||
public static final String ID = "smtp";
|
||||
|
||||
private transient final Logger log = LoggerFactory.getLogger(EmailSmtpConnector.class);
|
||||
|
||||
@@ -48,7 +50,7 @@ public class EmailSmtpConnector implements IEmailConnector {
|
||||
private Session session;
|
||||
|
||||
public EmailSmtpConnector(EmailSmtpConfig cfg) {
|
||||
this.cfg = cfg;
|
||||
this.cfg = cfg.build();
|
||||
|
||||
Properties sCfg = new Properties();
|
||||
sCfg.setProperty("mail.smtp.host", cfg.getHost());
|
||||
@@ -68,7 +70,7 @@ public class EmailSmtpConnector implements IEmailConnector {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "smtp";
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
|
||||
package io.kamax.mxisd.threepid.connector.phone;
|
||||
|
||||
public class BlackholePhoneConnector implements IPhoneConnector {
|
||||
public class BlackholePhoneConnector implements PhoneConnector {
|
||||
|
||||
public static final String ID = "none";
|
||||
|
||||
@Override
|
||||
public void send(String recipient, String content) {
|
||||
@@ -29,7 +31,7 @@ public class BlackholePhoneConnector implements IPhoneConnector {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "BLACKHOLE";
|
||||
return ID;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.connector.phone;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.connector.PhoneTwilioConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneConfig;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class BuiltInPhoneConnectorSupplier implements PhoneConnectorSupplier {
|
||||
|
||||
@Override
|
||||
public Optional<PhoneConnector> apply(PhoneConfig cfg, Mxisd mxisd) {
|
||||
if (StringUtils.equals(PhoneSmsTwilioConnector.ID, cfg.getConnector())) {
|
||||
PhoneTwilioConfig cCfg = GsonUtil.get().fromJson(cfg.getConnectors().getOrDefault(PhoneSmsTwilioConnector.ID, new JsonObject()), PhoneTwilioConfig.class);
|
||||
return Optional.of(new PhoneSmsTwilioConnector(cCfg));
|
||||
}
|
||||
|
||||
if (StringUtils.equals(BlackholePhoneConnector.ID, cfg.getConnector())) {
|
||||
return Optional.of(new BlackholePhoneConnector());
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,9 +21,9 @@
|
||||
package io.kamax.mxisd.threepid.connector.phone;
|
||||
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.threepid.connector.IThreePidConnector;
|
||||
import io.kamax.mxisd.threepid.connector.ThreePidConnector;
|
||||
|
||||
public interface IPhoneConnector extends IThreePidConnector {
|
||||
public interface PhoneConnector extends ThreePidConnector {
|
||||
|
||||
@Override
|
||||
default String getMedium() {
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.connector.phone;
|
||||
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneConfig;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface PhoneConnectorSupplier extends BiFunction<PhoneConfig, Mxisd, Optional<PhoneConnector>> {
|
||||
|
||||
}
|
||||
@@ -29,14 +29,16 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PhoneSmsTwilioConnector implements IPhoneConnector {
|
||||
public class PhoneSmsTwilioConnector implements PhoneConnector {
|
||||
|
||||
public static final String ID = "twilio";
|
||||
|
||||
private transient final Logger log = LoggerFactory.getLogger(PhoneSmsTwilioConnector.class);
|
||||
|
||||
private PhoneTwilioConfig cfg;
|
||||
|
||||
public PhoneSmsTwilioConnector(PhoneTwilioConfig cfg) {
|
||||
this.cfg = cfg;
|
||||
this.cfg = cfg.build();
|
||||
|
||||
Twilio.init(cfg.getAccountSid(), cfg.getAuthToken());
|
||||
log.info("Twilio API has been initiated");
|
||||
@@ -44,7 +46,7 @@ public class PhoneSmsTwilioConnector implements IPhoneConnector {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "twilio";
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification;
|
||||
package io.kamax.mxisd.threepid.generator;
|
||||
|
||||
import io.kamax.mxisd.as.IMatrixIdInvite;
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class GenericTemplateNotificationGenerator extends PlaceholderNotificationGenerator implements INotificationGenerator {
|
||||
public abstract class GenericTemplateNotificationGenerator extends PlaceholderNotificationGenerator implements NotificationGenerator {
|
||||
|
||||
private transient final Logger log = LoggerFactory.getLogger(GenericTemplateNotificationGenerator.class);
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification;
|
||||
package io.kamax.mxisd.threepid.generator;
|
||||
|
||||
import io.kamax.mxisd.as.IMatrixIdInvite;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
|
||||
public interface INotificationGenerator {
|
||||
public interface NotificationGenerator {
|
||||
|
||||
String getId();
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification;
|
||||
package io.kamax.mxisd.threepid.generator;
|
||||
|
||||
import io.kamax.matrix.ThreePid;
|
||||
import io.kamax.mxisd.as.IMatrixIdInvite;
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.generator.email;
|
||||
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailTemplateConfig;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class BuiltInEmailGeneratorSupplier implements EmailGeneratorSupplier {
|
||||
|
||||
private boolean processed = false;
|
||||
private EmailGenerator obj;
|
||||
|
||||
@Override
|
||||
public Optional<EmailGenerator> apply(EmailConfig emailConfig, Mxisd mxisd) {
|
||||
if (!processed) {
|
||||
if (StringUtils.equals(GenericEmailNotificationGenerator.ID, emailConfig.getGenerator())) {
|
||||
EmailTemplateConfig cfg = Optional.ofNullable(emailConfig.getGenerators().get(GenericEmailNotificationGenerator.ID))
|
||||
.map(json -> GsonUtil.get().fromJson(json, EmailTemplateConfig.class))
|
||||
.orElseGet(EmailTemplateConfig::new);
|
||||
obj = new GenericEmailNotificationGenerator(cfg, emailConfig, mxisd.getConfig().getMatrix(), mxisd.getConfig().getServer());
|
||||
}
|
||||
}
|
||||
|
||||
processed = true;
|
||||
return Optional.ofNullable(obj);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,12 +18,12 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification.email;
|
||||
package io.kamax.mxisd.threepid.generator.email;
|
||||
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.threepid.notification.INotificationGenerator;
|
||||
import io.kamax.mxisd.threepid.generator.NotificationGenerator;
|
||||
|
||||
public interface IEmailNotificationGenerator extends INotificationGenerator {
|
||||
public interface EmailGenerator extends NotificationGenerator {
|
||||
|
||||
@Override
|
||||
default String getMedium() {
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.generator.email;
|
||||
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface EmailGeneratorSupplier extends BiFunction<EmailConfig, Mxisd, Optional<EmailGenerator>> {
|
||||
|
||||
}
|
||||
@@ -18,27 +18,29 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification.email;
|
||||
package io.kamax.mxisd.threepid.generator.email;
|
||||
|
||||
import io.kamax.matrix.ThreePid;
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailTemplateConfig;
|
||||
import io.kamax.mxisd.threepid.notification.GenericTemplateNotificationGenerator;
|
||||
import io.kamax.mxisd.threepid.generator.GenericTemplateNotificationGenerator;
|
||||
|
||||
public class EmailNotificationGenerator extends GenericTemplateNotificationGenerator implements IEmailNotificationGenerator {
|
||||
public class GenericEmailNotificationGenerator extends GenericTemplateNotificationGenerator implements EmailGenerator {
|
||||
|
||||
public static final String ID = "template";
|
||||
|
||||
private EmailConfig cfg;
|
||||
|
||||
public EmailNotificationGenerator(EmailTemplateConfig templateCfg, EmailConfig cfg, MatrixConfig mxCfg, ServerConfig srvCfg) {
|
||||
super(mxCfg, srvCfg, templateCfg);
|
||||
public GenericEmailNotificationGenerator(EmailTemplateConfig templateCfg, EmailConfig cfg, MatrixConfig mxCfg, ServerConfig srvCfg) {
|
||||
super(mxCfg, srvCfg, templateCfg.build());
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "template";
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.generator.phone;
|
||||
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneSmsTemplateConfig;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class BuiltInPhoneGeneratorSupplier implements PhoneGeneratorSupplier {
|
||||
|
||||
@Override
|
||||
public Optional<PhoneGenerator> apply(PhoneConfig cfg, Mxisd mxisd) {
|
||||
if (StringUtils.equals(SmsNotificationGenerator.ID, cfg.getGenerator())) {
|
||||
PhoneSmsTemplateConfig genCfg = Optional.ofNullable(cfg.getGenerators().get(SmsNotificationGenerator.ID))
|
||||
.map(json -> GsonUtil.get().fromJson(json, PhoneSmsTemplateConfig.class))
|
||||
.orElseGet(PhoneSmsTemplateConfig::new);
|
||||
return Optional.of(new SmsNotificationGenerator(mxisd.getConfig().getMatrix(), mxisd.getConfig().getServer(), genCfg));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,11 +18,11 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification.phone;
|
||||
package io.kamax.mxisd.threepid.generator.phone;
|
||||
|
||||
import io.kamax.mxisd.threepid.notification.INotificationGenerator;
|
||||
import io.kamax.mxisd.threepid.generator.NotificationGenerator;
|
||||
|
||||
public interface IPhoneNotificationGenerator extends INotificationGenerator {
|
||||
public interface PhoneGenerator extends NotificationGenerator {
|
||||
|
||||
default String getMedium() {
|
||||
return "msisdn";
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.generator.phone;
|
||||
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneConfig;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public interface PhoneGeneratorSupplier extends BiFunction<PhoneConfig, Mxisd, Optional<PhoneGenerator>> {
|
||||
}
|
||||
@@ -18,22 +18,24 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification.phone;
|
||||
package io.kamax.mxisd.threepid.generator.phone;
|
||||
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneSmsTemplateConfig;
|
||||
import io.kamax.mxisd.threepid.notification.GenericTemplateNotificationGenerator;
|
||||
import io.kamax.mxisd.threepid.generator.GenericTemplateNotificationGenerator;
|
||||
|
||||
public class SmsNotificationGenerator extends GenericTemplateNotificationGenerator implements IPhoneNotificationGenerator {
|
||||
public class SmsNotificationGenerator extends GenericTemplateNotificationGenerator implements PhoneGenerator {
|
||||
|
||||
public static final String ID = "template";
|
||||
|
||||
public SmsNotificationGenerator(MatrixConfig mxCfg, ServerConfig srvCfg, PhoneSmsTemplateConfig cfg) {
|
||||
super(mxCfg, srvCfg, cfg);
|
||||
super(mxCfg, srvCfg, cfg.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "template";
|
||||
return ID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sarl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.notification;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.Mxisd;
|
||||
import io.kamax.mxisd.config.threepid.connector.EmailSendGridConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneConfig;
|
||||
import io.kamax.mxisd.exception.ConfigurationException;
|
||||
import io.kamax.mxisd.notification.NotificationHandlerSupplier;
|
||||
import io.kamax.mxisd.notification.NotificationHandlers;
|
||||
import io.kamax.mxisd.threepid.connector.email.EmailConnector;
|
||||
import io.kamax.mxisd.threepid.connector.email.EmailConnectorSupplier;
|
||||
import io.kamax.mxisd.threepid.connector.phone.PhoneConnector;
|
||||
import io.kamax.mxisd.threepid.connector.phone.PhoneConnectorSupplier;
|
||||
import io.kamax.mxisd.threepid.generator.email.EmailGenerator;
|
||||
import io.kamax.mxisd.threepid.generator.email.EmailGeneratorSupplier;
|
||||
import io.kamax.mxisd.threepid.generator.phone.PhoneGenerator;
|
||||
import io.kamax.mxisd.threepid.generator.phone.PhoneGeneratorSupplier;
|
||||
import io.kamax.mxisd.threepid.notification.email.EmailRawNotificationHandler;
|
||||
import io.kamax.mxisd.threepid.notification.email.EmailSendGridNotificationHandler;
|
||||
import io.kamax.mxisd.threepid.notification.phone.PhoneNotificationHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
public class BuiltInNotificationHandlerSupplier implements NotificationHandlerSupplier {
|
||||
|
||||
@Override
|
||||
public void accept(Mxisd mxisd) {
|
||||
String emailHandler = mxisd.getConfig().getNotification().getHandler().get(ThreePidMedium.Email.getId());
|
||||
acceptEmail(emailHandler, mxisd);
|
||||
|
||||
String phoneHandler = mxisd.getConfig().getNotification().getHandler().get(ThreePidMedium.PhoneNumber.getId());
|
||||
acceptPhone(phoneHandler, mxisd);
|
||||
}
|
||||
|
||||
private void acceptEmail(String handler, Mxisd mxisd) {
|
||||
if (StringUtils.equals(EmailRawNotificationHandler.ID, handler)) {
|
||||
JsonObject emailCfgJson = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.Email.getId());
|
||||
if (Objects.nonNull(emailCfgJson)) {
|
||||
EmailConfig emailCfg = GsonUtil.get().fromJson(emailCfgJson, EmailConfig.class);
|
||||
|
||||
if (org.apache.commons.lang.StringUtils.isBlank(emailCfg.getGenerator())) {
|
||||
throw new ConfigurationException("notification.email.generator");
|
||||
}
|
||||
|
||||
if (org.apache.commons.lang.StringUtils.isBlank(emailCfg.getConnector())) {
|
||||
throw new ConfigurationException("notification.email.connector");
|
||||
}
|
||||
|
||||
List<EmailGenerator> generators = StreamSupport
|
||||
.stream(ServiceLoader.load(EmailGeneratorSupplier.class).spliterator(), false)
|
||||
.map(s -> s.apply(emailCfg, mxisd))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<EmailConnector> connectors = StreamSupport
|
||||
.stream(ServiceLoader.load(EmailConnectorSupplier.class).spliterator(), false)
|
||||
.map(s -> s.apply(emailCfg, mxisd))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
NotificationHandlers.register(() -> new EmailRawNotificationHandler(emailCfg, generators, connectors));
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.equals(EmailSendGridNotificationHandler.ID, handler)) {
|
||||
JsonObject cfgJson = mxisd.getConfig().getNotification().getHandlers().get(EmailSendGridNotificationHandler.ID);
|
||||
if (Objects.nonNull(cfgJson)) {
|
||||
EmailSendGridConfig cfg = GsonUtil.get().fromJson(cfgJson, EmailSendGridConfig.class);
|
||||
NotificationHandlers.register(() -> new EmailSendGridNotificationHandler(mxisd.getConfig(), cfg));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void acceptPhone(String handler, Mxisd mxisd) {
|
||||
if (StringUtils.equals(PhoneNotificationHandler.ID, handler)) {
|
||||
JsonObject cfgJson = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.PhoneNumber.getId());
|
||||
if (Objects.nonNull(cfgJson)) {
|
||||
PhoneConfig cfg = GsonUtil.get().fromJson(cfgJson, PhoneConfig.class);
|
||||
|
||||
List<PhoneGenerator> generators = StreamSupport
|
||||
.stream(ServiceLoader.load(PhoneGeneratorSupplier.class).spliterator(), false)
|
||||
.map(s -> s.apply(cfg, mxisd))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<PhoneConnector> connectors = StreamSupport
|
||||
.stream(ServiceLoader.load(PhoneConnectorSupplier.class).spliterator(), false)
|
||||
.map(s -> s.apply(cfg, mxisd))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
NotificationHandlers.register(() -> new PhoneNotificationHandler(cfg, generators, connectors));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,14 +23,15 @@ package io.kamax.mxisd.threepid.notification;
|
||||
import io.kamax.mxisd.as.IMatrixIdInvite;
|
||||
import io.kamax.mxisd.exception.ConfigurationException;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.notification.INotificationHandler;
|
||||
import io.kamax.mxisd.threepid.connector.IThreePidConnector;
|
||||
import io.kamax.mxisd.notification.NotificationHandler;
|
||||
import io.kamax.mxisd.threepid.connector.ThreePidConnector;
|
||||
import io.kamax.mxisd.threepid.generator.NotificationGenerator;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class GenericNotificationHandler<A extends IThreePidConnector, B extends INotificationGenerator> implements INotificationHandler {
|
||||
public abstract class GenericNotificationHandler<A extends ThreePidConnector, B extends NotificationGenerator> implements NotificationHandler {
|
||||
|
||||
private A connector;
|
||||
private B generator;
|
||||
|
||||
@@ -22,23 +22,26 @@ package io.kamax.mxisd.threepid.notification.email;
|
||||
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||
import io.kamax.mxisd.threepid.connector.email.IEmailConnector;
|
||||
import io.kamax.mxisd.threepid.connector.email.EmailConnector;
|
||||
import io.kamax.mxisd.threepid.generator.email.EmailGenerator;
|
||||
import io.kamax.mxisd.threepid.notification.GenericNotificationHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class EmailRawNotificationHandler extends GenericNotificationHandler<IEmailConnector, IEmailNotificationGenerator> {
|
||||
public class EmailRawNotificationHandler extends GenericNotificationHandler<EmailConnector, EmailGenerator> {
|
||||
|
||||
public static final String ID = "raw";
|
||||
|
||||
private EmailConfig cfg;
|
||||
|
||||
public EmailRawNotificationHandler(EmailConfig cfg, List<IEmailNotificationGenerator> generators, List<IEmailConnector> connectors) {
|
||||
public EmailRawNotificationHandler(EmailConfig cfg, List<EmailGenerator> generators, List<EmailConnector> connectors) {
|
||||
this.cfg = cfg;
|
||||
process(connectors, generators);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "raw";
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,7 +60,7 @@ public class EmailRawNotificationHandler extends GenericNotificationHandler<IEma
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void send(IEmailConnector connector, String recipient, String content) {
|
||||
protected void send(EmailConnector connector, String recipient, String content) {
|
||||
connector.send(
|
||||
cfg.getIdentity().getFrom(),
|
||||
cfg.getIdentity().getName(),
|
||||
|
||||
@@ -18,19 +18,18 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.threepid.connector.email;
|
||||
package io.kamax.mxisd.threepid.notification.email;
|
||||
|
||||
import com.sendgrid.SendGrid;
|
||||
import com.sendgrid.SendGridException;
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.as.IMatrixIdInvite;
|
||||
import io.kamax.mxisd.config.MatrixConfig;
|
||||
import io.kamax.mxisd.config.ServerConfig;
|
||||
import io.kamax.mxisd.config.MxisdConfig;
|
||||
import io.kamax.mxisd.config.threepid.connector.EmailSendGridConfig;
|
||||
import io.kamax.mxisd.exception.FeatureNotAvailable;
|
||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||
import io.kamax.mxisd.notification.INotificationHandler;
|
||||
import io.kamax.mxisd.threepid.notification.PlaceholderNotificationGenerator;
|
||||
import io.kamax.mxisd.notification.NotificationHandler;
|
||||
import io.kamax.mxisd.threepid.generator.PlaceholderNotificationGenerator;
|
||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -45,22 +44,24 @@ import static com.sendgrid.SendGrid.Email;
|
||||
import static com.sendgrid.SendGrid.Response;
|
||||
import static io.kamax.mxisd.config.threepid.connector.EmailSendGridConfig.EmailTemplate;
|
||||
|
||||
public class EmailSendGridNotificationHandler extends PlaceholderNotificationGenerator implements INotificationHandler {
|
||||
public class EmailSendGridNotificationHandler extends PlaceholderNotificationGenerator implements NotificationHandler {
|
||||
|
||||
public static final String ID = "sendgrid";
|
||||
|
||||
private transient final Logger log = LoggerFactory.getLogger(EmailSendGridNotificationHandler.class);
|
||||
|
||||
private EmailSendGridConfig cfg;
|
||||
private SendGrid sendgrid;
|
||||
|
||||
public EmailSendGridNotificationHandler(MatrixConfig mxCfg, ServerConfig srvCfg, EmailSendGridConfig cfg) {
|
||||
super(mxCfg, srvCfg);
|
||||
public EmailSendGridNotificationHandler(MxisdConfig mCfg, EmailSendGridConfig cfg) {
|
||||
super(mCfg.getMatrix(), mCfg.getServer());
|
||||
this.cfg = cfg;
|
||||
this.sendgrid = new SendGrid(cfg.getApi().getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "sendgrid";
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,23 +22,26 @@ package io.kamax.mxisd.threepid.notification.phone;
|
||||
|
||||
import io.kamax.matrix.ThreePidMedium;
|
||||
import io.kamax.mxisd.config.threepid.medium.PhoneConfig;
|
||||
import io.kamax.mxisd.threepid.connector.phone.IPhoneConnector;
|
||||
import io.kamax.mxisd.threepid.connector.phone.PhoneConnector;
|
||||
import io.kamax.mxisd.threepid.generator.phone.PhoneGenerator;
|
||||
import io.kamax.mxisd.threepid.notification.GenericNotificationHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PhoneNotificationHandler extends GenericNotificationHandler<IPhoneConnector, IPhoneNotificationGenerator> {
|
||||
public class PhoneNotificationHandler extends GenericNotificationHandler<PhoneConnector, PhoneGenerator> {
|
||||
|
||||
public static final String ID = "raw";
|
||||
|
||||
private PhoneConfig cfg;
|
||||
|
||||
public PhoneNotificationHandler(PhoneConfig cfg, List<IPhoneConnector> connectors, List<IPhoneNotificationGenerator> generators) {
|
||||
public PhoneNotificationHandler(PhoneConfig cfg, List<PhoneGenerator> generators, List<PhoneConnector> connectors) {
|
||||
this.cfg = cfg;
|
||||
process(connectors, generators);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "raw";
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,7 +60,7 @@ public class PhoneNotificationHandler extends GenericNotificationHandler<IPhoneC
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void send(IPhoneConnector connector, String recipient, String content) {
|
||||
protected void send(PhoneConnector connector, String recipient, String content) {
|
||||
connector.send(recipient, content);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public class ThreePidSession implements IThreePidSession {
|
||||
dao.getNextLink(),
|
||||
dao.getToken()
|
||||
);
|
||||
|
||||
timestamp = Instant.ofEpochMilli(dao.getCreationTime());
|
||||
isValidated = dao.getValidated();
|
||||
if (isValidated) {
|
||||
@@ -81,7 +82,6 @@ public class ThreePidSession implements IThreePidSession {
|
||||
this.attempt = attempt;
|
||||
this.nextLink = nextLink;
|
||||
this.token = token;
|
||||
|
||||
this.timestamp = Instant.now();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user