use of io.kamax.mxisd.Mxisd in project mxisd by kamax-io.
the class BuiltInNotificationHandlerSupplier method acceptPhone.
private void acceptPhone(String handler, Mxisd mxisd) {
if (StringUtils.equals(PhoneNotificationHandler.ID, handler)) {
Object o = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.PhoneNumber.getId());
if (Objects.nonNull(o)) {
PhoneConfig cfg;
try {
cfg = GsonUtil.get().fromJson(GsonUtil.makeObj(o), PhoneConfig.class);
} catch (JsonSyntaxException e) {
throw new ConfigurationException("Invalid configuration for threepid msisdn notification");
}
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));
}
}
}
use of io.kamax.mxisd.Mxisd in project mxisd by kamax-io.
the class BuiltInNotificationHandlerSupplier method acceptEmail.
private void acceptEmail(String handler, Mxisd mxisd) {
if (StringUtils.equals(EmailRawNotificationHandler.ID, handler)) {
Object o = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.Email.getId());
if (Objects.nonNull(o)) {
EmailConfig emailCfg;
try {
emailCfg = GsonUtil.get().fromJson(GsonUtil.makeObj(o), EmailConfig.class);
} catch (JsonSyntaxException e) {
throw new ConfigurationException("Invalid configuration for threepid email notification");
}
if (StringUtils.isBlank(emailCfg.getGenerator())) {
throw new ConfigurationException("notification.email.generator");
}
if (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)) {
Object cfgJson = mxisd.getConfig().getNotification().getHandlers().get(EmailSendGridNotificationHandler.ID);
if (Objects.nonNull(cfgJson)) {
EmailSendGridConfig cfg;
try {
cfg = GsonUtil.get().fromJson(GsonUtil.get().toJson(cfgJson), EmailSendGridConfig.class);
} catch (JsonSyntaxException e) {
throw new ConfigurationException("Invalid configuration for threepid email sendgrid handler");
}
NotificationHandlers.register(() -> new EmailSendGridNotificationHandler(mxisd.getConfig(), cfg));
}
}
}
use of io.kamax.mxisd.Mxisd in project mxisd by kamax-io.
the class AuthManagerTest method beforeClass.
// FIXME we should be able to easily build the class ourselves
// FIXME use constants
@BeforeClass
public static void beforeClass() {
MxisdConfig cfg = new MxisdConfig();
cfg.getMatrix().setDomain("localhost");
cfg.getKey().setPath(":memory:");
cfg.getStorage().getProvider().getSqlite().setDatabase(":memory:");
MemoryThreePid mem3pid = new MemoryThreePid();
mem3pid.setMedium("email");
mem3pid.setAddress("john@localhost");
MemoryIdentityConfig validCfg = new MemoryIdentityConfig();
validCfg.setUsername("john");
validCfg.setPassword("doe");
validCfg.getThreepids().add(mem3pid);
MemoryIdentityConfig illegalUser = new MemoryIdentityConfig();
illegalUser.setUsername("JANE");
illegalUser.setPassword("doe");
cfg.getMemory().setEnabled(true);
cfg.getMemory().getIdentities().add(validCfg);
cfg.getMemory().getIdentities().add(illegalUser);
Mxisd m = new Mxisd(cfg);
m.start();
mgr = m.getAuth();
}
use of io.kamax.mxisd.Mxisd in project mxisd by kamax-io.
the class MxisdTest method before.
@Before
public void before() {
MxisdConfig cfg = MxisdConfig.forDomain("localhost").inMemory();
MemoryThreePid mem3pid = new MemoryThreePid();
mem3pid.setMedium("email");
mem3pid.setAddress("john@localhost");
MemoryIdentityConfig memCfg = new MemoryIdentityConfig();
memCfg.setUsername("john");
memCfg.getThreepids().add(mem3pid);
cfg.getMemory().setEnabled(true);
cfg.getMemory().getIdentities().add(memCfg);
m = new Mxisd(cfg);
m.start();
}
use of io.kamax.mxisd.Mxisd in project mxisd by kamax-io.
the class InviteCommandProcessor method process.
@Override
public void process(Mxisd m, _MatrixClient client, _MatrixRoom room, CommandLine cmdLine) {
if (cmdLine.getArgs().length < 2) {
room.sendNotice(buildHelp());
} else {
String arg = cmdLine.getArgList().get(1);
String response;
if (StringUtils.equals("list", arg)) {
StrBuilder b = new StrBuilder();
List<IThreePidInviteReply> invites = m.getInvite().listInvites();
if (invites.isEmpty()) {
b.appendln("No invites!");
response = b.toString();
} else {
b.appendln("Invites:");
for (IThreePidInviteReply invite : invites) {
b.appendNewLine().append("ID: ").append(invite.getId());
b.appendNewLine().append("Room: ").append(invite.getInvite().getRoomId());
b.appendNewLine().append("Medium: ").append(invite.getInvite().getMedium());
b.appendNewLine().append("Address: ").append(invite.getInvite().getAddress());
b.appendNewLine();
}
response = b.appendNewLine().append("Total: " + invites.size()).toString();
}
} else if (StringUtils.equals("show", arg)) {
if (cmdLine.getArgList().size() < 3) {
response = buildHelp();
} else {
String id = cmdLine.getArgList().get(2);
IThreePidInviteReply invite = m.getInvite().getInvite(id);
StrBuilder b = new StrBuilder();
b.appendln("Details for Invitation #" + id);
b.appendNewLine().append("Room: ").append(invite.getInvite().getRoomId());
b.appendNewLine().append("Sender: ").append(invite.getInvite().getSender().toString());
b.appendNewLine().append("Medium: ").append(invite.getInvite().getMedium());
b.appendNewLine().append("Address: ").append(invite.getInvite().getAddress());
b.appendNewLine().append("Display name: ").append(invite.getDisplayName());
b.appendNewLine().appendNewLine().append("Properties:");
invite.getInvite().getProperties().forEach((k, v) -> {
b.appendNewLine().append("\t").append(k).append("=").append(v);
});
b.appendNewLine();
response = b.toString();
}
} else if (StringUtils.equals("revoke", arg)) {
if (cmdLine.getArgList().size() < 3) {
response = buildHelp();
} else {
m.getInvite().expireInvite(cmdLine.getArgList().get(2));
response = "OK";
}
} else {
response = buildError("Unknown invite action: " + arg, true);
}
room.sendNotice(response);
}
}
Aggregations