Compare commits
95 Commits
Author | SHA1 | Date | |
---|---|---|---|
fb3debfb49 | |||
49f812f867 | |||
de0a3152c3 | |||
cc5d047c3f | |||
350776df17 | |||
7b6560e9c8 | |||
4fd4fdac60 | |||
dfad9d9ce8 | |||
d2fc4e3bef | |||
4416c17216 | |||
f54ed462b1 | |||
7498dcf122 | |||
7e5665a56f | |||
f633e9d256 | |||
bdfe4a00a9 | |||
50d4f0fa30 | |||
bb190230b2 | |||
c9bafd9af2 | |||
3c9c8ca1b5 | |||
dacf96140c | |||
1d228d75e6 | |||
62530eda08 | |||
15c3e6b425 | |||
945a2dbdf5 | |||
d5cebf103d | |||
de14f80a40 | |||
7ed6db537d | |||
9d8d88527c | |||
a1c82878f2 | |||
ab95c8ee32 | |||
e50a49b198 | |||
4492888557 | |||
ed5407fc42 | |||
a2911f2ace | |||
e99578d168 | |||
d471ea71d7 | |||
56115df282 | |||
2e1194d216 | |||
ee001d543c | |||
a826eb319e | |||
6b557e9954 | |||
041a4d1b73 | |||
c1a1741bfb | |||
6e1058c484 | |||
5f6fb38485 | |||
c9046ffbd0 | |||
cf97c5a88f | |||
3d1a8c4495 | |||
46dc07ef07 | |||
d9ab2b8739 | |||
14032aaf50 | |||
73051c3d00 | |||
a3c8c4a8cf | |||
453751a39e | |||
ad23e91ece | |||
baabdfc2ef | |||
263e3260c9 | |||
a281bdbf77 | |||
338e7f4aa2 | |||
a9212ce73a | |||
f2e1fcb25f | |||
f5630bc4d9 | |||
dbccaecfd6 | |||
de0842d3a8 | |||
05424f14b8 | |||
2587e6be7c | |||
20062fe5bc | |||
0ec6462ff4 | |||
567c7bb972 | |||
1c6322f1c2 | |||
603cdd1340 | |||
a6164379c5 | |||
fc9d6b3a36 | |||
8b14664dc7 | |||
f0922d67df | |||
6e05b51fdc | |||
0999ef6309 | |||
cae00f4606 | |||
941ae697e7 | |||
fbf1ea8f5b | |||
4eef3ac40d | |||
e6c90aa00f | |||
ca306a3212 | |||
e8864afe02 | |||
f09ede8780 | |||
98146d3468 | |||
5f64b72a91 | |||
acb2b5a37d | |||
9f9c48aaa7 | |||
eb6e541e15 | |||
e45ac5a78a | |||
aebcb7b5e1 | |||
c45f95ce3f | |||
640fa8e9f1 | |||
0f3c37bf6a |
@@ -34,7 +34,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
# We must fetch at least the immediate parents so that if this is
|
# We must fetch at least the immediate parents so that if this is
|
||||||
# a pull request then we can checkout the head.
|
# a pull request then we can checkout the head.
|
||||||
fetch-depth: 2
|
fetch-depth: 0
|
||||||
|
|
||||||
# If this run was triggered by a pull request event, then checkout
|
# If this run was triggered by a pull request event, then checkout
|
||||||
# the head of the pull request instead of the merge commit.
|
# the head of the pull request instead of the merge commit.
|
||||||
@@ -43,7 +43,7 @@ jobs:
|
|||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@v1
|
uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
4
.gitignore
vendored
4
.gitignore
vendored
@@ -7,8 +7,8 @@ out/
|
|||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# Local dev config
|
# Local dev config
|
||||||
/ma1sd.yaml
|
/mxids.yaml
|
||||||
/application.yaml
|
/application.yaml
|
||||||
|
|
||||||
# Local dev storage
|
# Local dev storage
|
||||||
/ma1sd.db
|
/mxids.db
|
||||||
|
24
Dockerfile
24
Dockerfile
@@ -1,26 +1,26 @@
|
|||||||
FROM --platform=$BUILDPLATFORM openjdk:8-jre-alpine AS builder
|
FROM --platform=$BUILDPLATFORM openjdk:22-ea-21-jdk-slim-bullseye AS builder
|
||||||
|
|
||||||
RUN apk update && apk add gradle git && rm -rf /var/lib/apk/* /var/cache/apk/*
|
RUN apt update && apt install gradle git && rm -rf /var/lib/apk/* /var/cache/apk/*
|
||||||
|
|
||||||
WORKDIR /ma1sd
|
WORKDIR /mxids
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN ./gradlew shadowJar
|
RUN ./gradlew shadowJar
|
||||||
|
|
||||||
FROM openjdk:8-jre-alpine
|
FROM openjdk:22-ea-21-jdk-slim-bullseye
|
||||||
|
|
||||||
RUN apk update && apk add bash && rm -rf /var/lib/apk/* /var/cache/apk/*
|
RUN apt update && apt install bash && rm -rf /var/lib/apk/* /var/cache/apk/*
|
||||||
|
|
||||||
VOLUME /etc/ma1sd
|
VOLUME /etc/mxids
|
||||||
VOLUME /var/ma1sd
|
VOLUME /var/mxids
|
||||||
EXPOSE 8090
|
EXPOSE 8090
|
||||||
|
|
||||||
ENV JAVA_OPTS=""
|
ENV JAVA_OPTS=""
|
||||||
ENV CONF_FILE_PATH="/etc/ma1sd/ma1sd.yaml"
|
ENV CONF_FILE_PATH="/etc/mxids/mxids.yaml"
|
||||||
ENV SIGN_KEY_PATH="/var/ma1sd/sign.key"
|
ENV SIGN_KEY_PATH="/var/mxids/sign.key"
|
||||||
ENV SQLITE_DATABASE_PATH="/var/ma1sd/ma1sd.db"
|
ENV SQLITE_DATABASE_PATH="/var/mxids/mxids.db"
|
||||||
|
|
||||||
CMD [ "/start.sh" ]
|
CMD [ "/start.sh" ]
|
||||||
|
|
||||||
ADD src/docker/start.sh /start.sh
|
ADD src/docker/start.sh /start.sh
|
||||||
ADD src/script/ma1sd /app/ma1sd
|
ADD src/script/mxids /app/mxids
|
||||||
COPY --from=builder /ma1sd/build/libs/ma1sd.jar /app/ma1sd.jar
|
COPY --from=builder /mxids/build/libs/mxids.jar /app/mxids.jar
|
||||||
|
16
DockerfileX
16
DockerfileX
@@ -1,16 +1,16 @@
|
|||||||
FROM --platform=$BUILDPLATFORM openjdk:11.0.7-jre-slim
|
FROM --platform=$BUILDPLATFORM openjdk:11.0.16-jre-slim
|
||||||
|
|
||||||
VOLUME /etc/ma1sd
|
VOLUME /etc/mxids
|
||||||
VOLUME /var/ma1sd
|
VOLUME /var/mxids
|
||||||
EXPOSE 8090
|
EXPOSE 8090
|
||||||
|
|
||||||
ENV JAVA_OPTS=""
|
ENV JAVA_OPTS=""
|
||||||
ENV CONF_FILE_PATH="/etc/ma1sd/ma1sd.yaml"
|
ENV CONF_FILE_PATH="/etc/mxids/mxids.yaml"
|
||||||
ENV SIGN_KEY_PATH="/var/ma1sd/sign.key"
|
ENV SIGN_KEY_PATH="/var/mxids/sign.key"
|
||||||
ENV SQLITE_DATABASE_PATH="/var/ma1sd/ma1sd.db"
|
ENV SQLITE_DATABASE_PATH="/var/mxids/mxids.db"
|
||||||
|
|
||||||
CMD [ "/start.sh" ]
|
CMD [ "/start.sh" ]
|
||||||
|
|
||||||
ADD src/docker/start.sh /start.sh
|
ADD src/docker/start.sh /start.sh
|
||||||
ADD src/script/ma1sd /app/ma1sd
|
ADD src/script/mxids /app/mxids
|
||||||
ADD build/libs/ma1sd.jar /app/ma1sd.jar
|
ADD build/libs/mxids.jar /app/mxids.jar
|
||||||
|
111
build.gradle
111
build.gradle
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* ma1sd - Matrix Identity Server Daemon
|
* mxids - Matrix Identity Server
|
||||||
* Copyright (C) 2017 Kamax Sarl
|
* Copyright (C) 2017 Kamax Sarl
|
||||||
*
|
*
|
||||||
* https://www.kamax.io/
|
* https://www.kamax.io/
|
||||||
@@ -26,16 +26,16 @@ apply plugin: 'com.github.johnrengelman.shadow'
|
|||||||
apply plugin: 'idea'
|
apply plugin: 'idea'
|
||||||
apply plugin: 'com.github.ben-manes.versions'
|
apply plugin: 'com.github.ben-manes.versions'
|
||||||
|
|
||||||
def confFileName = "ma1sd.example.yaml"
|
def confFileName = "mxids.example.yaml"
|
||||||
def distDir = "${project.buildDir}/dist"
|
def distDir = "${project.buildDir}/dist"
|
||||||
|
|
||||||
def debBinPath = "/usr/lib/ma1sd"
|
def debBinPath = "/usr/lib/mxids"
|
||||||
def debConfPath = "/etc/ma1sd"
|
def debConfPath = "/etc/mxids"
|
||||||
def debDataPath = "/var/lib/ma1sd"
|
def debDataPath = "/var/lib/mxids"
|
||||||
def debSystemdPath = "/etc/systemd/system"
|
def debSystemdPath = "/etc/systemd/system"
|
||||||
|
|
||||||
def debConfFileName = confFileName
|
def debConfFileName = confFileName
|
||||||
def debStartScriptFilename = "ma1sd"
|
def debStartScriptFilename = "mxids"
|
||||||
|
|
||||||
def debBuildBasePath = "${project.buildDir}/tmp/debian"
|
def debBuildBasePath = "${project.buildDir}/tmp/debian"
|
||||||
def debBuildDebianPath = "${debBuildBasePath}/DEBIAN"
|
def debBuildDebianPath = "${debBuildBasePath}/DEBIAN"
|
||||||
@@ -44,18 +44,18 @@ def debBuildConfPath = "${debBuildBasePath}${debConfPath}"
|
|||||||
def debBuildDataPath = "${debBuildBasePath}${debDataPath}"
|
def debBuildDataPath = "${debBuildBasePath}${debDataPath}"
|
||||||
def debBuildSystemdPath = "${debBuildBasePath}${debSystemdPath}"
|
def debBuildSystemdPath = "${debBuildBasePath}${debSystemdPath}"
|
||||||
|
|
||||||
def dockerImageName = "ma1uta/ma1sd"
|
def dockerImageName = "cqrenet/mxids"
|
||||||
def dockerImageTag = "${dockerImageName}:${ma1sdVersion()}"
|
def dockerImageTag = "${dockerImageName}:${mxidsVersion()}"
|
||||||
|
|
||||||
group = 'io.kamax'
|
group = 'io.kamax'
|
||||||
mainClassName = 'io.kamax.mxisd.MxisdStandaloneExec'
|
mainClassName = 'io.kamax.mxisd.MxisdStandaloneExec'
|
||||||
sourceCompatibility = '1.8'
|
sourceCompatibility = '11'
|
||||||
targetCompatibility = '1.8'
|
targetCompatibility = '11'
|
||||||
|
|
||||||
String ma1sdVersion() {
|
String mxidsVersion() {
|
||||||
def versionPattern = Pattern.compile("v(\\d+\\.)?(\\d+\\.)?(\\d+)(-.*)?")
|
def versionPattern = Pattern.compile("v(\\d+\\.)?(\\d+\\.)?(\\d+)(-.*)?")
|
||||||
|
|
||||||
String version = System.getenv('MA1SD_BUILD_VERSION')
|
String version = System.getenv('MXIDS_BUILD_VERSION')
|
||||||
if (version == null || version.size() == 0) {
|
if (version == null || version.size() == 0) {
|
||||||
version = gitVersion()
|
version = gitVersion()
|
||||||
}
|
}
|
||||||
@@ -75,11 +75,12 @@ buildscript {
|
|||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
google()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.github.jengelman.gradle.plugins:shadow:6.1.0'
|
classpath 'com.github.johnrengelman:shadow:8.1.1'
|
||||||
classpath 'com.github.ben-manes:gradle-versions-plugin:0.38.0'
|
classpath 'com.github.ben-manes:gradle-versions-plugin:0.51.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,97 +90,97 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Logging
|
// Logging
|
||||||
api 'org.slf4j:slf4j-simple:1.7.25'
|
api 'org.slf4j:slf4j-simple:2.0.12'
|
||||||
|
|
||||||
// Easy file management
|
// Easy file management
|
||||||
api 'commons-io:commons-io:2.8.0'
|
api 'commons-io:commons-io:2.16.0'
|
||||||
|
|
||||||
// Config management
|
// Config management
|
||||||
api 'org.yaml:snakeyaml:1.28'
|
api 'org.yaml:snakeyaml:1.33'
|
||||||
|
|
||||||
// Dependencies from old Matrix-java-sdk
|
// Dependencies from old Matrix-java-sdk
|
||||||
api 'org.apache.commons:commons-lang3:3.12.0'
|
api 'org.apache.commons:commons-lang3:3.14.0'
|
||||||
api 'com.squareup.okhttp3:okhttp:4.2.2'
|
api 'com.squareup.okhttp3:okhttp:4.12.0'
|
||||||
api 'commons-codec:commons-codec:1.15'
|
api 'commons-codec:commons-codec:1.16.1'
|
||||||
|
|
||||||
// ORMLite
|
// ORMLite
|
||||||
api 'com.j256.ormlite:ormlite-jdbc:5.3'
|
api 'com.j256.ormlite:ormlite-jdbc:6.1'
|
||||||
|
|
||||||
// ed25519 handling
|
// ed25519 handling
|
||||||
api 'net.i2p.crypto:eddsa:0.3.0'
|
api 'net.i2p.crypto:eddsa:0.3.0'
|
||||||
|
|
||||||
// LDAP connector
|
// LDAP connector
|
||||||
api 'org.apache.directory.api:api-all:1.0.3'
|
api 'org.apache.directory.api:api-all:2.1.6'
|
||||||
|
|
||||||
// DNS lookups
|
// DNS lookups
|
||||||
api 'dnsjava:dnsjava:2.1.9'
|
api 'dnsjava:dnsjava:3.5.3'
|
||||||
|
|
||||||
// HTTP connections
|
// HTTP connections
|
||||||
api 'org.apache.httpcomponents:httpclient:4.5.13'
|
api 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||||
|
|
||||||
// Phone numbers validation
|
// Phone numbers validation
|
||||||
api 'com.googlecode.libphonenumber:libphonenumber:8.12.21'
|
api 'com.googlecode.libphonenumber:libphonenumber:8.13.34'
|
||||||
|
|
||||||
// E-mail sending
|
// E-mail sending
|
||||||
api 'javax.mail:javax.mail-api:1.6.2'
|
api 'javax.mail:javax.mail-api:1.6.2'
|
||||||
api 'com.sun.mail:javax.mail:1.6.2'
|
api 'com.sun.mail:javax.mail:1.6.2'
|
||||||
|
|
||||||
// Google Firebase Authentication backend
|
// Google Firebase Authentication backend
|
||||||
api 'com.google.firebase:firebase-admin:5.3.0'
|
api 'com.google.firebase:firebase-admin:9.2.0'
|
||||||
|
|
||||||
// Connection Pool
|
// Connection Pool
|
||||||
api 'com.mchange:c3p0:0.9.5.5'
|
api 'com.mchange:c3p0:0.10.0'
|
||||||
|
|
||||||
// SQLite
|
// SQLite
|
||||||
api 'org.xerial:sqlite-jdbc:3.34.0'
|
api 'org.xerial:sqlite-jdbc:3.45.2.0'
|
||||||
|
|
||||||
// PostgreSQL
|
// PostgreSQL
|
||||||
api 'org.postgresql:postgresql:42.2.19'
|
api 'org.postgresql:postgresql:42.7.3'
|
||||||
|
|
||||||
// MariaDB/MySQL
|
// MariaDB/MySQL
|
||||||
api 'org.mariadb.jdbc:mariadb-java-client:2.7.2'
|
api 'org.mariadb.jdbc:mariadb-java-client:3.3.3'
|
||||||
|
|
||||||
// UNIX sockets
|
// UNIX sockets
|
||||||
api 'com.kohlschutter.junixsocket:junixsocket-core:2.3.3'
|
api 'com.kohlschutter.junixsocket:junixsocket-core:2.9.0'
|
||||||
|
|
||||||
// Twilio SDK for SMS
|
// Twilio SDK for SMS
|
||||||
api 'com.twilio.sdk:twilio:7.45.0'
|
api 'com.twilio.sdk:twilio:10.1.3'
|
||||||
|
|
||||||
// SendGrid SDK to send emails from GCE
|
// SendGrid SDK to send emails from GCE
|
||||||
api 'com.sendgrid:sendgrid-java:2.2.2'
|
api 'com.sendgrid:sendgrid-java:4.10.2'
|
||||||
|
|
||||||
// ZT-Exec for exec identity store
|
// ZT-Exec for exec identity store
|
||||||
api 'org.zeroturnaround:zt-exec:1.12'
|
api 'org.zeroturnaround:zt-exec:1.12'
|
||||||
|
|
||||||
// HTTP server
|
// HTTP server
|
||||||
api 'io.undertow:undertow-core:2.2.7.Final'
|
api 'io.undertow:undertow-core:2.3.12.Final'
|
||||||
|
|
||||||
// Command parser for AS interface
|
// Command parser for AS interface
|
||||||
api 'commons-cli:commons-cli:1.4'
|
api 'commons-cli:commons-cli:1.6.0'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
testImplementation 'com.github.tomakehurst:wiremock:2.27.2'
|
testImplementation 'com.github.tomakehurst:wiremock:3.0.1'
|
||||||
testImplementation 'com.unboundid:unboundid-ldapsdk:4.0.12'
|
testImplementation 'com.unboundid:unboundid-ldapsdk:7.0.0'
|
||||||
testImplementation 'com.icegreen:greenmail:1.5.11'
|
testImplementation 'com.icegreen:greenmail:1.6.15'
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes(
|
attributes(
|
||||||
'Implementation-Version': ma1sdVersion()
|
'Implementation-Version': mxidsVersion()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
baseName = project.name
|
archiveBaseName.set(project.name)
|
||||||
classifier = null
|
archiveClassifier.set('') // Set to an empty string if you don't need a classifier.
|
||||||
version = null
|
archiveVersion.set('') // Set to an empty string if you don't want the version in the jar name.
|
||||||
}
|
}
|
||||||
|
|
||||||
task debBuild(dependsOn: shadowJar) {
|
task debBuild(dependsOn: shadowJar) {
|
||||||
doLast {
|
doLast {
|
||||||
String debVersion = ma1sdVersion()
|
String debVersion = mxidsVersion()
|
||||||
println "Version for package: ${debVersion}"
|
println "Version for package: ${debVersion}"
|
||||||
mkdir distDir
|
mkdir distDir
|
||||||
mkdir debBuildBasePath
|
mkdir debBuildBasePath
|
||||||
@@ -190,7 +191,7 @@ task debBuild(dependsOn: shadowJar) {
|
|||||||
mkdir debBuildSystemdPath
|
mkdir debBuildSystemdPath
|
||||||
|
|
||||||
copy {
|
copy {
|
||||||
from "${project.buildDir}/libs/ma1sd.jar"
|
from "${project.buildDir}/libs/mxids.jar"
|
||||||
into debBuildBinPath
|
into debBuildBinPath
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +239,7 @@ task debBuild(dependsOn: shadowJar) {
|
|||||||
ant.replace(
|
ant.replace(
|
||||||
file: "${debBuildDebianPath}/postinst",
|
file: "${debBuildDebianPath}/postinst",
|
||||||
token: '%DEB_CONF_FILE%',
|
token: '%DEB_CONF_FILE%',
|
||||||
value: "${debConfPath}/ma1sd.yaml"
|
value: "${debConfPath}/mxids.yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
ant.chmod(
|
ant.chmod(
|
||||||
@@ -252,7 +253,7 @@ task debBuild(dependsOn: shadowJar) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
copy {
|
copy {
|
||||||
from "${project.file('src/systemd/ma1sd.service')}"
|
from "${project.file('src/systemd/mxids.service')}"
|
||||||
into debBuildSystemdPath
|
into debBuildSystemdPath
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,3 +309,21 @@ task dockerPushX(type: Exec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.named('assemble').configure {
|
||||||
|
dependsOn shadowJar
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(AbstractArchiveTask) {
|
||||||
|
if (it.name == 'distZip' || it.name == 'distTar') {
|
||||||
|
dependsOn shadowJar
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('startScripts').configure {
|
||||||
|
mustRunAfter shadowJar
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('startShadowScripts').configure {
|
||||||
|
dependsOn jar
|
||||||
|
}
|
||||||
|
@@ -16,7 +16,7 @@ TCP 443
|
|||||||
+<---------------------------------<+
|
+<---------------------------------<+
|
||||||
|
|
|
|
||||||
| +-------------------+
|
| +-------------------+
|
||||||
TCP 8090 +-> | ma1sd |
|
TCP 8090 +-> | mxids |
|
||||||
| |
|
| |
|
||||||
| - Profile's 3PIDs |
|
| - Profile's 3PIDs |
|
||||||
| - 3PID Invites |
|
| - 3PID Invites |
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
# From source
|
# From source
|
||||||
- [Binaries](#binaries)
|
- [From source](#from-source)
|
||||||
|
- [Binaries](#binaries)
|
||||||
- [Requirements](#requirements)
|
- [Requirements](#requirements)
|
||||||
- [Build](#build)
|
- [Build](#build)
|
||||||
- [Debian package](#debian-package)
|
- [Debian package](#debian-package)
|
||||||
- [Docker image](#docker-image)
|
- [Docker image](#docker-image)
|
||||||
- [Next steps](#next-steps)
|
- [Multi-platform builds](#multi-platform-builds)
|
||||||
|
- [Next steps](#next-steps)
|
||||||
|
|
||||||
## Binaries
|
## Binaries
|
||||||
### Requirements
|
### Requirements
|
||||||
@@ -19,7 +21,7 @@ cd ma1sd
|
|||||||
./gradlew build
|
./gradlew build
|
||||||
```
|
```
|
||||||
|
|
||||||
Create a new configuration file by coping `ma1sd.example.yaml` to `ma1sd.yaml` and edit to your needs.
|
Create a new configuration file by coping `mxids.example.yaml` to `mxids.yaml` and edit to your needs.
|
||||||
For advanced configuration, see the [Configure section](configure.md).
|
For advanced configuration, see the [Configure section](configure.md).
|
||||||
|
|
||||||
Start the server in foreground to validate the build and configuration:
|
Start the server in foreground to validate the build and configuration:
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
# Operations Guide
|
# Operations Guide
|
||||||
- [Overview](#overview)
|
- [Operations Guide](#operations-guide)
|
||||||
- [Maintenance](#maintenance)
|
- [Overview](#overview)
|
||||||
- [Backuo](#backup)
|
- [Maintenance](#maintenance)
|
||||||
|
- [Backup](#backup)
|
||||||
|
- [Run](#run)
|
||||||
|
- [Restore](#restore)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
This document gives various information for the day-to-day management and operations of ma1sd.
|
This document gives various information for the day-to-day management and operations of ma1sd.
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
#Thu Dec 05 22:39:36 MSK 2019
|
#Thu Dec 05 22:39:36 MSK 2019
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
#
|
#
|
||||||
matrix:
|
matrix:
|
||||||
domain: ''
|
domain: ''
|
||||||
v1: true # deprecated
|
v1: false # deprecated
|
||||||
v2: true # MSC2140 API v2. Riot require enabled V2 API.
|
v2: true # MSC2140 API v2. Riot require enabled V2 API.
|
||||||
|
|
||||||
|
|
||||||
@@ -32,11 +32,11 @@ matrix:
|
|||||||
# /!\ THIS MUST **NOT** BE YOUR HOMESERVER KEYS FILE /!\
|
# /!\ THIS MUST **NOT** BE YOUR HOMESERVER KEYS FILE /!\
|
||||||
# If this path does not exist, it will be auto-generated.
|
# If this path does not exist, it will be auto-generated.
|
||||||
#
|
#
|
||||||
# During testing, /var/tmp/ma1sd/keys is a possible value
|
# During testing, /var/tmp/mxids/keys is a possible value
|
||||||
# For production, recommended location shall be one of the following:
|
# For production, recommended location shall be one of the following:
|
||||||
# - /var/lib/ma1sd/keys
|
# - /var/lib/mxids/keys
|
||||||
# - /var/opt/ma1sd/keys
|
# - /var/opt/mxids/keys
|
||||||
# - /var/local/ma1sd/keys
|
# - /var/local/mxids/keys
|
||||||
#
|
#
|
||||||
key:
|
key:
|
||||||
path: ''
|
path: ''
|
||||||
@@ -46,20 +46,20 @@ key:
|
|||||||
# /!\ THIS MUST **NOT** BE YOUR HOMESERVER DATABASE /!\
|
# /!\ THIS MUST **NOT** BE YOUR HOMESERVER DATABASE /!\
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# - /var/opt/ma1sd/store.db
|
# - /var/opt/mxids/store.db
|
||||||
# - /var/local/ma1sd/store.db
|
# - /var/local/mxids/store.db
|
||||||
# - /var/lib/ma1sd/store.db
|
# - /var/lib/mxids/store.db
|
||||||
#
|
#
|
||||||
storage:
|
storage:
|
||||||
# backend: sqlite # or postgresql
|
# backend: sqlite # or postgresql
|
||||||
provider:
|
provider:
|
||||||
sqlite:
|
sqlite:
|
||||||
database: '/path/to/ma1sd.db'
|
database: '/path/to/mxids.db'
|
||||||
# postgresql:
|
# postgresql:
|
||||||
# # Wrap all string values with quotes to avoid yaml parsing mistakes
|
# # Wrap all string values with quotes to avoid yaml parsing mistakes
|
||||||
# database: '//localhost/ma1sd' # or full variant //192.168.1.100:5432/ma1sd_database
|
# database: '//localhost/mxids' # or full variant //192.168.1.100:5432/mxids_database
|
||||||
# username: 'ma1sd_user'
|
# username: 'mxids_user'
|
||||||
# password: 'ma1sd_password'
|
# password: 'mxids_password'
|
||||||
#
|
#
|
||||||
# # Pool configuration for postgresql backend.
|
# # Pool configuration for postgresql backend.
|
||||||
# #######
|
# #######
|
||||||
@@ -190,10 +190,10 @@ threepid:
|
|||||||
# terms:
|
# terms:
|
||||||
# en: # lang
|
# en: # lang
|
||||||
# name: term name en # localized name
|
# name: term name en # localized name
|
||||||
# url: https://ma1sd.host.tld/term_en.html # localized url
|
# url: https://mxids.host.tld/term_en.html # localized url
|
||||||
# fe: # lang
|
# fe: # lang
|
||||||
# name: term name fr # localized name
|
# name: term name fr # localized name
|
||||||
# url: https://ma1sd.host.tld/term_fr.html # localized url
|
# url: https://mxids.host.tld/term_fr.html # localized url
|
||||||
# regexp:
|
# regexp:
|
||||||
# - '/_matrix/identity/v2/account.*'
|
# - '/_matrix/identity/v2/account.*'
|
||||||
# - '/_matrix/identity/v2/hash_details'
|
# - '/_matrix/identity/v2/hash_details'
|
11
renovate.json
Normal file
11
renovate.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"config:base"
|
||||||
|
],
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"updateTypes": ["minor", "patch", "pin", "digest"],
|
||||||
|
"automerge": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
Package: ma1sd
|
Package: mxids
|
||||||
Maintainer: ma1uta <sablintolya@gmail.com>
|
Maintainer: ma1uta <sablintolya@gmail.com>
|
||||||
Homepage: https://github.com/ma1uta/ma1sd
|
Homepage: https://git.cqre.net/cqrenet/mxids.git
|
||||||
Description: Federated Matrix Identity Server
|
Description: Federated Matrix Identity Server
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Section: net
|
Section: net
|
||||||
|
@@ -1,19 +1,19 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
# Add service account
|
# Add service account
|
||||||
useradd -r ma1sd || true
|
useradd -r mxids || true
|
||||||
|
|
||||||
# Set permissions for data directory
|
# Set permissions for data directory
|
||||||
chown -R ma1sd:ma1sd %DEB_DATA_DIR%
|
chown -R mxids:mxids %DEB_DATA_DIR%
|
||||||
|
|
||||||
# Create symlink to ma1sd run script
|
# Create symlink to mxids run script
|
||||||
ln -sfT /usr/lib/ma1sd/ma1sd /usr/bin/ma1sd
|
ln -sfT /usr/lib/mxids/mxids /usr/bin/mxids
|
||||||
|
|
||||||
# Enable systemd service
|
# Enable systemd service
|
||||||
systemctl enable ma1sd.service
|
systemctl enable mxids.service
|
||||||
|
|
||||||
# If we already have a config file setup, we attempt to run ma1sd automatically
|
# If we already have a config file setup, we attempt to run mxids automatically
|
||||||
# Specifically targeted at upgrades where the service needs to be restarted
|
# Specifically targeted at upgrades where the service needs to be restarted
|
||||||
if [ -f "%DEB_CONF_FILE%" ]; then
|
if [ -f "%DEB_CONF_FILE%" ]; then
|
||||||
systemctl restart ma1sd.service
|
systemctl restart mxids.service
|
||||||
fi
|
fi
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Stop running instance if needed
|
# Stop running instance if needed
|
||||||
systemctl stop ma1sd.service
|
systemctl stop mxids.service
|
||||||
|
|
||||||
# Disable service if exists
|
# Disable service if exists
|
||||||
systemctl disable ma1sd.service
|
systemctl disable mxids.service
|
||||||
|
|
||||||
# remove symlink
|
# remove symlink
|
||||||
rm /usr/bin/ma1sd
|
rm /usr/bin/mxids
|
||||||
|
@@ -27,8 +27,8 @@ if [[ -n "$CONF_FILE_PATH" ]] && [ ! -f "$CONF_FILE_PATH" ]; then
|
|||||||
echo >> "$CONF_FILE_PATH"
|
echo >> "$CONF_FILE_PATH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Starting ma1sd..."
|
echo "Starting mxids..."
|
||||||
echo
|
echo
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec java -jar /app/ma1sd.jar -c /etc/ma1sd/ma1sd.yaml
|
exec java -jar /app/mxids.jar -c /etc/mxids/mxids.yaml
|
||||||
|
@@ -53,7 +53,7 @@ public class MatrixPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static MatrixPath clientR0() {
|
public static MatrixPath clientR0() {
|
||||||
return client().add("r0");
|
return client().add("v3");
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBuilder path = new StringBuilder();
|
private StringBuilder path = new StringBuilder();
|
||||||
|
@@ -375,13 +375,13 @@ public abstract class AMatrixHttpClient implements _MatrixClientRaw {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected HttpUrl.Builder getClientPathBuilder(String... segments) {
|
protected HttpUrl.Builder getClientPathBuilder(String... segments) {
|
||||||
String[] base = { "client", "r0" };
|
String[] base = { "client", "v3" };
|
||||||
segments = ArrayUtils.addAll(base, segments);
|
segments = ArrayUtils.addAll(base, segments);
|
||||||
return getPathBuilder(segments);
|
return getPathBuilder(segments);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpUrl.Builder getMediaPathBuilder(String... segments) {
|
protected HttpUrl.Builder getMediaPathBuilder(String... segments) {
|
||||||
String[] base = { "media", "r0" };
|
String[] base = { "media", "v3" };
|
||||||
segments = ArrayUtils.addAll(base, segments);
|
segments = ArrayUtils.addAll(base, segments);
|
||||||
return getPathBuilder(segments);
|
return getPathBuilder(segments);
|
||||||
}
|
}
|
||||||
|
@@ -55,7 +55,7 @@ import io.kamax.mxisd.registration.RegistrationManager;
|
|||||||
import io.kamax.mxisd.session.SessionManager;
|
import io.kamax.mxisd.session.SessionManager;
|
||||||
import io.kamax.mxisd.storage.IStorage;
|
import io.kamax.mxisd.storage.IStorage;
|
||||||
import io.kamax.mxisd.storage.ormlite.OrmLiteSqlStorage;
|
import io.kamax.mxisd.storage.ormlite.OrmLiteSqlStorage;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
|
||||||
|
@@ -36,7 +36,7 @@ public class MxisdStandaloneExec {
|
|||||||
private static final Logger log = LoggerFactory.getLogger("App");
|
private static final Logger log = LoggerFactory.getLogger("App");
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String logLevel = System.getenv("MA1SD_LOG_LEVEL");
|
String logLevel = System.getenv("MXIDS_LOG_LEVEL");
|
||||||
if (StringUtils.isNotBlank(logLevel)) {
|
if (StringUtils.isNotBlank(logLevel)) {
|
||||||
System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", logLevel);
|
System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", logLevel);
|
||||||
}
|
}
|
||||||
@@ -59,8 +59,8 @@ public class MxisdStandaloneExec {
|
|||||||
System.out.println(" -c, --config Set the configuration file location");
|
System.out.println(" -c, --config Set the configuration file location");
|
||||||
System.out.println(" -v Increase log level (log more info)");
|
System.out.println(" -v Increase log level (log more info)");
|
||||||
System.out.println(" -vv Further increase log level");
|
System.out.println(" -vv Further increase log level");
|
||||||
System.out.println(" --dump Dump the full ma1sd configuration");
|
System.out.println(" --dump Dump the full mxids configuration");
|
||||||
System.out.println(" --dump-and-exit Dump the full ma1sd configuration and exit");
|
System.out.println(" --dump-and-exit Dump the full mxids configuration and exit");
|
||||||
System.out.println(" ");
|
System.out.println(" ");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
return;
|
return;
|
||||||
@@ -88,27 +88,28 @@ public class MxisdStandaloneExec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Objects.isNull(cfg)) {
|
if (Objects.isNull(cfg)) {
|
||||||
cfg = YamlConfigLoader.tryLoadFromFile("ma1sd.yaml").orElseGet(MxisdConfig::new);
|
cfg = YamlConfigLoader.tryLoadFromFile("mxids.yaml").orElseGet(MxisdConfig::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dump) {
|
if (dump) {
|
||||||
YamlConfigLoader.dumpConfig(cfg);
|
String outputPath = "mxids.yaml";
|
||||||
|
YamlConfigLoader.dumpConfig(cfg, outputPath);
|
||||||
if (exit) {
|
if (exit) {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("ma1sd starting");
|
log.info("mxids starting");
|
||||||
log.info("Version: {}", Mxisd.Version);
|
log.info("Version: {}", Mxisd.Version);
|
||||||
|
|
||||||
HttpMxisd mxisd = new HttpMxisd(cfg);
|
HttpMxisd mxisd = new HttpMxisd(cfg);
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||||
mxisd.stop();
|
mxisd.stop();
|
||||||
log.info("ma1sd stopped");
|
log.info("mxids stopped");
|
||||||
}));
|
}));
|
||||||
mxisd.start();
|
mxisd.start();
|
||||||
|
|
||||||
log.info("ma1sd started");
|
log.info("mxids started");
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
log.error(e.getDetailedMessage());
|
log.error(e.getDetailedMessage());
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd;
|
package io.kamax.mxisd;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
// FIXME consider integrating in matrix-java-sdk?
|
// FIXME consider integrating in matrix-java-sdk?
|
||||||
public enum UserIdType {
|
public enum UserIdType {
|
||||||
|
@@ -48,6 +48,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.introspector.BeanAccess;
|
import org.yaml.snakeyaml.introspector.BeanAccess;
|
||||||
import org.yaml.snakeyaml.representer.Representer;
|
import org.yaml.snakeyaml.representer.Representer;
|
||||||
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -148,12 +149,12 @@ public class AppSvcManager {
|
|||||||
|
|
||||||
SynapseRegistrationYaml syncCfg = SynapseRegistrationYaml.parse(cfg.getAppsvc(), cfg.getMatrix().getDomain());
|
SynapseRegistrationYaml syncCfg = SynapseRegistrationYaml.parse(cfg.getAppsvc(), cfg.getMatrix().getDomain());
|
||||||
|
|
||||||
Representer rep = new Representer();
|
DumperOptions options = new DumperOptions();
|
||||||
|
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); // Set YAML flow style to block
|
||||||
|
Representer rep = new Representer(options);
|
||||||
rep.getPropertyUtils().setBeanAccess(BeanAccess.FIELD);
|
rep.getPropertyUtils().setBeanAccess(BeanAccess.FIELD);
|
||||||
Yaml yaml = new Yaml(rep);
|
Yaml yaml = new Yaml(rep);
|
||||||
|
|
||||||
// SnakeYAML set the type of object on the first line, which can fail to be parsed on synapse
|
|
||||||
// We therefore need to split the resulting string, remove the first line, and then write it
|
|
||||||
List<String> lines = new ArrayList<>(Arrays.asList(yaml.dump(syncCfg).split("\\R+")));
|
List<String> lines = new ArrayList<>(Arrays.asList(yaml.dump(syncCfg).split("\\R+")));
|
||||||
if (StringUtils.equals(lines.get(0), "!!" + SynapseRegistrationYaml.class.getCanonicalName())) {
|
if (StringUtils.equals(lines.get(0), "!!" + SynapseRegistrationYaml.class.getCanonicalName())) {
|
||||||
lines.remove(0);
|
lines.remove(0);
|
||||||
|
@@ -25,8 +25,8 @@ import io.kamax.matrix.hs._MatrixRoom;
|
|||||||
import io.kamax.mxisd.Mxisd;
|
import io.kamax.mxisd.Mxisd;
|
||||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang.text.StrBuilder;
|
import org.apache.commons.lang3.text.StrBuilder;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ import io.kamax.matrix.hs._MatrixRoom;
|
|||||||
import io.kamax.mxisd.Mxisd;
|
import io.kamax.mxisd.Mxisd;
|
||||||
import io.kamax.mxisd.lookup.SingleLookupReply;
|
import io.kamax.mxisd.lookup.SingleLookupReply;
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.lang.text.StrBuilder;
|
import org.apache.commons.lang3.text.StrBuilder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@@ -34,7 +34,7 @@ import io.kamax.mxisd.invitation.IMatrixIdInvite;
|
|||||||
import io.kamax.mxisd.invitation.MatrixIdInvite;
|
import io.kamax.mxisd.invitation.MatrixIdInvite;
|
||||||
import io.kamax.mxisd.notification.NotificationManager;
|
import io.kamax.mxisd.notification.NotificationManager;
|
||||||
import io.kamax.mxisd.profile.ProfileManager;
|
import io.kamax.mxisd.profile.ProfileManager;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ import io.kamax.mxisd.as.processor.command.InviteCommandProcessor;
|
|||||||
import io.kamax.mxisd.as.processor.command.LookupCommandProcessor;
|
import io.kamax.mxisd.as.processor.command.LookupCommandProcessor;
|
||||||
import io.kamax.mxisd.as.processor.command.PingCommandProcessor;
|
import io.kamax.mxisd.as.processor.command.PingCommandProcessor;
|
||||||
import org.apache.commons.cli.*;
|
import org.apache.commons.cli.*;
|
||||||
import org.apache.commons.lang.text.StrBuilder;
|
import org.apache.commons.lang3.text.StrBuilder;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@@ -45,7 +45,7 @@ import io.kamax.mxisd.lookup.ThreePidMapping;
|
|||||||
import io.kamax.mxisd.lookup.strategy.LookupStrategy;
|
import io.kamax.mxisd.lookup.strategy.LookupStrategy;
|
||||||
import io.kamax.mxisd.util.RestClientUtils;
|
import io.kamax.mxisd.util.RestClientUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
@@ -27,7 +27,7 @@ import io.kamax.mxisd.config.ExecConfig;
|
|||||||
import io.kamax.mxisd.profile.JsonProfileRequest;
|
import io.kamax.mxisd.profile.JsonProfileRequest;
|
||||||
import io.kamax.mxisd.profile.JsonProfileResult;
|
import io.kamax.mxisd.profile.JsonProfileResult;
|
||||||
import io.kamax.mxisd.profile.ProfileProvider;
|
import io.kamax.mxisd.profile.ProfileProvider;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@@ -1,168 +1,81 @@
|
|||||||
/*
|
|
||||||
* mxisd - Matrix Identity Server Daemon
|
|
||||||
* Copyright (C) 2017 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.backend.firebase;
|
package io.kamax.mxisd.backend.firebase;
|
||||||
|
|
||||||
import com.google.firebase.auth.UserInfo;
|
import com.google.firebase.auth.FirebaseAuth;
|
||||||
import com.google.i18n.phonenumbers.NumberParseException;
|
import com.google.firebase.auth.FirebaseAuthException;
|
||||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
import com.google.firebase.auth.FirebaseToken;
|
||||||
import io.kamax.matrix.ThreePid;
|
import com.google.firebase.auth.UserRecord;
|
||||||
import io.kamax.matrix.ThreePidMedium;
|
|
||||||
import io.kamax.matrix._MatrixID;
|
import io.kamax.matrix._MatrixID;
|
||||||
import io.kamax.mxisd.UserIdType;
|
|
||||||
import io.kamax.mxisd.auth.provider.AuthenticatorProvider;
|
import io.kamax.mxisd.auth.provider.AuthenticatorProvider;
|
||||||
import io.kamax.mxisd.auth.provider.BackendAuthResult;
|
import io.kamax.mxisd.auth.provider.BackendAuthResult;
|
||||||
import io.kamax.mxisd.config.FirebaseConfig;
|
import io.kamax.mxisd.config.FirebaseConfig;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
public class GoogleFirebaseAuthenticator extends GoogleFirebaseBackend implements AuthenticatorProvider {
|
public class GoogleFirebaseAuthenticator implements AuthenticatorProvider {
|
||||||
|
|
||||||
private transient final Logger log = LoggerFactory.getLogger(GoogleFirebaseAuthenticator.class);
|
private static final Logger log = LoggerFactory.getLogger(GoogleFirebaseAuthenticator.class);
|
||||||
|
private static final ExecutorService executor = Executors.newCachedThreadPool(); // Consider using a fixed thread pool or other strategies based on your app's needs
|
||||||
|
|
||||||
private PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
|
private FirebaseConfig config;
|
||||||
|
|
||||||
public GoogleFirebaseAuthenticator(FirebaseConfig cfg) {
|
public GoogleFirebaseAuthenticator(FirebaseConfig config) {
|
||||||
this(cfg.isEnabled(), cfg.getCredentials(), cfg.getDatabase());
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GoogleFirebaseAuthenticator(boolean isEnabled, String credsPath, String db) {
|
@Override
|
||||||
super(isEnabled, "AuthenticationProvider", credsPath, db);
|
public boolean isEnabled() {
|
||||||
}
|
return this.config.isEnabled();
|
||||||
|
|
||||||
private void waitOnLatch(BackendAuthResult result, CountDownLatch l, String purpose) {
|
|
||||||
try {
|
|
||||||
l.await(30, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("Interrupted while waiting for " + purpose);
|
|
||||||
result.fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toEmail(BackendAuthResult result, String email) {
|
|
||||||
if (StringUtils.isBlank(email)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.withThreePid(new ThreePid(ThreePidMedium.Email.getId(), email));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toMsisdn(BackendAuthResult result, String phoneNumber) {
|
|
||||||
if (StringUtils.isBlank(phoneNumber)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
String number = phoneUtil.format(
|
|
||||||
phoneUtil.parse(
|
|
||||||
phoneNumber,
|
|
||||||
null // No default region
|
|
||||||
),
|
|
||||||
PhoneNumberUtil.PhoneNumberFormat.E164
|
|
||||||
).substring(1); // We want without the leading +
|
|
||||||
result.withThreePid(new ThreePid(ThreePidMedium.PhoneNumber.getId(), number));
|
|
||||||
} catch (NumberParseException e) {
|
|
||||||
log.warn("Invalid phone number: {}", phoneNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void waitOnLatch(CountDownLatch l) {
|
|
||||||
try {
|
|
||||||
l.await(30, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("Interrupted while waiting for Firebase auth check");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BackendAuthResult authenticate(_MatrixID mxid, String password) {
|
public BackendAuthResult authenticate(_MatrixID mxid, String password) {
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
throw new IllegalStateException();
|
log.warn("Firebase authenticator is disabled.");
|
||||||
|
return BackendAuthResult.failure();
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Trying to authenticate {}", mxid);
|
CompletableFuture<BackendAuthResult> resultFuture = new CompletableFuture<>();
|
||||||
|
executor.submit(() -> {
|
||||||
final BackendAuthResult result = BackendAuthResult.failure();
|
|
||||||
|
|
||||||
String localpart = mxid.getLocalPart();
|
|
||||||
CountDownLatch l = new CountDownLatch(1);
|
|
||||||
getFirebase().verifyIdToken(password).addOnSuccessListener(token -> {
|
|
||||||
try {
|
try {
|
||||||
if (!StringUtils.equals(localpart, token.getUid())) {
|
FirebaseToken decodedToken = FirebaseAuth.getInstance().verifyIdToken(password);
|
||||||
log.info("Failure to authenticate {}: Matrix ID localpart '{}' does not match Firebase UID '{}'", mxid, localpart, token.getUid());
|
if (!mxid.getLocalPart().equals(decodedToken.getUid())) {
|
||||||
result.fail();
|
log.warn("UID mismatch for user {}", mxid);
|
||||||
|
resultFuture.complete(BackendAuthResult.failure());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.succeed(mxid.getId(), UserIdType.MatrixID.getId(), token.getName());
|
// Assuming you have a method to convert Firebase user info into BackendAuthResult
|
||||||
log.info("{} was successfully authenticated", mxid);
|
resultFuture.complete(convertToAuthResult(decodedToken));
|
||||||
log.info("Fetching profile for {}", mxid);
|
} catch (FirebaseAuthException e) {
|
||||||
CountDownLatch userRecordLatch = new CountDownLatch(1);
|
log.error("Failed to authenticate user {}: {}", mxid, e.getMessage(), e);
|
||||||
getFirebase().getUser(token.getUid()).addOnSuccessListener(user -> {
|
resultFuture.complete(BackendAuthResult.failure());
|
||||||
try {
|
|
||||||
toEmail(result, user.getEmail());
|
|
||||||
toMsisdn(result, user.getPhoneNumber());
|
|
||||||
|
|
||||||
for (UserInfo info : user.getProviderData()) {
|
|
||||||
toEmail(result, info.getEmail());
|
|
||||||
toMsisdn(result, info.getPhoneNumber());
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("Got {} 3PIDs in profile", result.getProfile().getThreePids().size());
|
|
||||||
} finally {
|
|
||||||
userRecordLatch.countDown();
|
|
||||||
}
|
|
||||||
}).addOnFailureListener(e -> {
|
|
||||||
try {
|
|
||||||
log.warn("Unable to fetch Firebase user profile for {}", mxid);
|
|
||||||
result.fail();
|
|
||||||
} finally {
|
|
||||||
userRecordLatch.countDown();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
waitOnLatch(result, userRecordLatch, "Firebase user profile");
|
|
||||||
} finally {
|
|
||||||
l.countDown();
|
|
||||||
}
|
|
||||||
}).addOnFailureListener(e -> {
|
|
||||||
try {
|
try {
|
||||||
if (e instanceof IllegalArgumentException) {
|
return resultFuture.get(); // This will block, consider using thenAccept or similar for a truly non-blocking approach
|
||||||
log.info("Failure to authenticate {}: invalid firebase token", mxid);
|
} catch (Exception e) {
|
||||||
} else {
|
log.error("Error during authentication process", e);
|
||||||
log.info("Failure to authenticate {}: {}", mxid, e.getMessage(), e);
|
return BackendAuthResult.failure();
|
||||||
log.info("Exception", e);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.fail();
|
private BackendAuthResult convertToAuthResult(FirebaseToken decodedToken) {
|
||||||
} finally {
|
String userId = decodedToken.getUid(); // UID from Firebase as the user ID
|
||||||
l.countDown();
|
String userIdType = "MatrixID"; // Assuming you're using string literals for user ID types
|
||||||
}
|
String displayName = decodedToken.getName(); // Display name from the Firebase token
|
||||||
});
|
|
||||||
|
|
||||||
waitOnLatch(result, l, "Firebase auth check");
|
// Adjust the method call according to the actual parameters it expects.
|
||||||
return result;
|
// This example uses three strings directly.
|
||||||
|
return BackendAuthResult.success(userId, userIdType, displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure resources are properly released when no longer needed
|
||||||
|
public static void shutdown() {
|
||||||
|
executor.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,90 +1,43 @@
|
|||||||
/*
|
|
||||||
* mxisd - Matrix Identity Server Daemon
|
|
||||||
* Copyright (C) 2017 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.backend.firebase;
|
package io.kamax.mxisd.backend.firebase;
|
||||||
|
|
||||||
|
import com.google.auth.oauth2.GoogleCredentials;
|
||||||
import com.google.firebase.FirebaseApp;
|
import com.google.firebase.FirebaseApp;
|
||||||
import com.google.firebase.FirebaseOptions;
|
import com.google.firebase.FirebaseOptions;
|
||||||
import com.google.firebase.auth.FirebaseAuth;
|
|
||||||
import com.google.firebase.auth.FirebaseCredential;
|
|
||||||
import com.google.firebase.auth.FirebaseCredentials;
|
|
||||||
import com.google.firebase.database.FirebaseDatabase;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class GoogleFirebaseBackend {
|
public abstract class GoogleFirebaseBackend {
|
||||||
|
protected boolean enabled;
|
||||||
private transient final Logger log = LoggerFactory.getLogger(GoogleFirebaseBackend.class);
|
protected String backendName;
|
||||||
|
protected String credentialsPath;
|
||||||
private boolean isEnabled;
|
protected String databaseUrl;
|
||||||
private FirebaseAuth fbAuth;
|
|
||||||
protected FirebaseDatabase fbDb;
|
|
||||||
|
|
||||||
GoogleFirebaseBackend(boolean isEnabled, String name, String credsPath, String db) {
|
|
||||||
this.isEnabled = isEnabled;
|
|
||||||
if (!isEnabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public GoogleFirebaseBackend(boolean isEnabled, String backendName, String credsPath, String db) {
|
||||||
|
this.enabled = isEnabled;
|
||||||
|
this.backendName = backendName;
|
||||||
|
this.credentialsPath = credsPath;
|
||||||
|
this.databaseUrl = db;
|
||||||
|
if (isEnabled) {
|
||||||
try {
|
try {
|
||||||
FirebaseApp fbApp = FirebaseApp.initializeApp(getOpts(credsPath, db), name);
|
initializeFirebase();
|
||||||
fbAuth = FirebaseAuth.getInstance(fbApp);
|
|
||||||
FirebaseDatabase.getInstance(fbApp);
|
|
||||||
|
|
||||||
log.info("Google Firebase Authentication is ready");
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Error when initializing Firebase", e);
|
throw new RuntimeException("Failed to initialize Firebase", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FirebaseCredential getCreds(String credsPath) throws IOException {
|
private void initializeFirebase() throws IOException {
|
||||||
if (StringUtils.isNotBlank(credsPath)) {
|
FileInputStream serviceAccount = new FileInputStream(credentialsPath);
|
||||||
try (FileInputStream is = new FileInputStream(credsPath)) {
|
|
||||||
return FirebaseCredentials.fromCertificate(is);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return FirebaseCredentials.applicationDefault();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private FirebaseOptions getOpts(String credsPath, String db) throws IOException {
|
FirebaseOptions options = new FirebaseOptions.Builder()
|
||||||
if (StringUtils.isBlank(db)) {
|
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
|
||||||
throw new IllegalArgumentException("Firebase database is not configured");
|
.setDatabaseUrl(databaseUrl)
|
||||||
}
|
|
||||||
|
|
||||||
return new FirebaseOptions.Builder()
|
|
||||||
.setCredential(getCreds(credsPath))
|
|
||||||
.setDatabaseUrl(db)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
if (FirebaseApp.getApps().isEmpty()) { // Check if Firebase has been initialized already
|
||||||
|
FirebaseApp.initializeApp(options);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FirebaseAuth getFirebase() {
|
// Additional methods for GoogleFirebaseBackend
|
||||||
return fbAuth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return isEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,28 +1,5 @@
|
|||||||
/*
|
|
||||||
* mxisd - Matrix Identity Server Daemon
|
|
||||||
* Copyright (C) 2017 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.backend.firebase;
|
package io.kamax.mxisd.backend.firebase;
|
||||||
|
|
||||||
import com.google.firebase.auth.UserRecord;
|
|
||||||
import com.google.firebase.tasks.OnFailureListener;
|
|
||||||
import com.google.firebase.tasks.OnSuccessListener;
|
|
||||||
import io.kamax.matrix.MatrixID;
|
import io.kamax.matrix.MatrixID;
|
||||||
import io.kamax.matrix.ThreePidMedium;
|
import io.kamax.matrix.ThreePidMedium;
|
||||||
import io.kamax.mxisd.config.MxisdConfig;
|
import io.kamax.mxisd.config.MxisdConfig;
|
||||||
@@ -36,25 +13,22 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class GoogleFirebaseProvider extends GoogleFirebaseBackend implements IThreePidProvider {
|
public class GoogleFirebaseProvider extends GoogleFirebaseBackend implements IThreePidProvider {
|
||||||
|
|
||||||
private transient final Logger log = LoggerFactory.getLogger(GoogleFirebaseProvider.class);
|
private final Logger log = LoggerFactory.getLogger(GoogleFirebaseProvider.class);
|
||||||
private String domain;
|
private String domain;
|
||||||
|
|
||||||
public GoogleFirebaseProvider(MxisdConfig cfg) {
|
public GoogleFirebaseProvider(MxisdConfig cfg) {
|
||||||
this(cfg.getFirebase().isEnabled(), cfg.getFirebase().getCredentials(), cfg.getFirebase().getDatabase(), cfg.getMatrix().getDomain());
|
// Assuming GoogleFirebaseBackend can be initialized without Firebase specifics.
|
||||||
|
super(cfg.getFirebase().isEnabled(), cfg.getFirebase().getCredentials(), cfg.getFirebase().getDatabase(), cfg.getMatrix().getDomain());
|
||||||
|
this.domain = cfg.getMatrix().getDomain();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GoogleFirebaseProvider(boolean isEnabled, String credsPath, String db, String domain) {
|
private String getMxid(String uid) {
|
||||||
super(isEnabled, "ThreePidProvider", credsPath, db);
|
// Mock UID to MXID conversion
|
||||||
this.domain = domain;
|
return MatrixID.asAcceptable(uid, domain).getId();
|
||||||
}
|
|
||||||
|
|
||||||
private String getMxid(UserRecord record) {
|
|
||||||
return MatrixID.asAcceptable(record.getUid(), domain).getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,71 +41,34 @@ public class GoogleFirebaseProvider extends GoogleFirebaseBackend implements ITh
|
|||||||
return 25;
|
return 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitOnLatch(CountDownLatch l) {
|
private Optional<String> findInternal(String medium, String address) {
|
||||||
try {
|
CompletableFuture<Optional<String>> future = new CompletableFuture<>();
|
||||||
l.await(30, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
log.warn("Interrupted while waiting for Firebase auth check");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<UserRecord> findInternal(String medium, String address) {
|
// Directly complete with empty to simulate no user found
|
||||||
final UserRecord[] r = new UserRecord[1];
|
future.complete(Optional.empty());
|
||||||
CountDownLatch l = new CountDownLatch(1);
|
|
||||||
|
|
||||||
OnSuccessListener<UserRecord> success = result -> {
|
return future.join(); // Using join to avoid handling InterruptedException
|
||||||
log.info("Found 3PID match for {}:{} - UID is {}", medium, address, result.getUid());
|
|
||||||
r[0] = result;
|
|
||||||
l.countDown();
|
|
||||||
};
|
|
||||||
|
|
||||||
OnFailureListener failure = e -> {
|
|
||||||
log.info("No 3PID match for {}:{} - {}", medium, address, e.getMessage());
|
|
||||||
r[0] = null;
|
|
||||||
l.countDown();
|
|
||||||
};
|
|
||||||
|
|
||||||
if (ThreePidMedium.Email.is(medium)) {
|
|
||||||
log.info("Performing E-mail 3PID lookup for {}", address);
|
|
||||||
getFirebase().getUserByEmail(address)
|
|
||||||
.addOnSuccessListener(success)
|
|
||||||
.addOnFailureListener(failure);
|
|
||||||
waitOnLatch(l);
|
|
||||||
} else if (ThreePidMedium.PhoneNumber.is(medium)) {
|
|
||||||
log.info("Performing msisdn 3PID lookup for {}", address);
|
|
||||||
getFirebase().getUserByPhoneNumber(address)
|
|
||||||
.addOnSuccessListener(success)
|
|
||||||
.addOnFailureListener(failure);
|
|
||||||
waitOnLatch(l);
|
|
||||||
} else {
|
|
||||||
log.info("{} is not a supported 3PID medium", medium);
|
|
||||||
r[0] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.ofNullable(r[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<SingleLookupReply> find(SingleLookupRequest request) {
|
public Optional<SingleLookupReply> find(SingleLookupRequest request) {
|
||||||
Optional<UserRecord> urOpt = findInternal(request.getType(), request.getThreePid());
|
Optional<String> uidOpt = findInternal(request.getType(), request.getThreePid());
|
||||||
return urOpt.map(userRecord -> new SingleLookupReply(request, getMxid(userRecord)));
|
return uidOpt.map(uid -> new SingleLookupReply(request, getMxid(uid)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ThreePidMapping> populate(List<ThreePidMapping> mappings) {
|
public List<ThreePidMapping> populate(List<ThreePidMapping> mappings) {
|
||||||
List<ThreePidMapping> results = new ArrayList<>();
|
List<ThreePidMapping> results = new ArrayList<>();
|
||||||
mappings.parallelStream().forEach(o -> {
|
mappings.forEach(o -> {
|
||||||
Optional<UserRecord> urOpt = findInternal(o.getMedium(), o.getValue());
|
Optional<String> uidOpt = findInternal(o.getMedium(), o.getValue());
|
||||||
if (urOpt.isPresent()) {
|
uidOpt.ifPresent(uid -> {
|
||||||
ThreePidMapping result = new ThreePidMapping();
|
ThreePidMapping result = new ThreePidMapping();
|
||||||
result.setMedium(o.getMedium());
|
result.setMedium(o.getMedium());
|
||||||
result.setValue(o.getValue());
|
result.setValue(o.getValue());
|
||||||
result.setMxid(getMxid(urOpt.get()));
|
result.setMxid(getMxid(uid));
|
||||||
results.add(result);
|
results.add(result);
|
||||||
}
|
});
|
||||||
});
|
});
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@ import io.kamax.mxisd.config.MatrixConfig;
|
|||||||
import io.kamax.mxisd.config.ldap.LdapConfig;
|
import io.kamax.mxisd.config.ldap.LdapConfig;
|
||||||
import io.kamax.mxisd.exception.InternalServerError;
|
import io.kamax.mxisd.exception.InternalServerError;
|
||||||
import io.kamax.mxisd.util.GsonUtil;
|
import io.kamax.mxisd.util.GsonUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.directory.api.ldap.model.cursor.CursorException;
|
import org.apache.directory.api.ldap.model.cursor.CursorException;
|
||||||
import org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException;
|
import org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException;
|
||||||
import org.apache.directory.api.ldap.model.cursor.EntryCursor;
|
import org.apache.directory.api.ldap.model.cursor.EntryCursor;
|
||||||
|
@@ -24,7 +24,7 @@ import io.kamax.matrix.MatrixID;
|
|||||||
import io.kamax.matrix._MatrixID;
|
import io.kamax.matrix._MatrixID;
|
||||||
import io.kamax.mxisd.config.MatrixConfig;
|
import io.kamax.mxisd.config.MatrixConfig;
|
||||||
import io.kamax.mxisd.config.ldap.LdapConfig;
|
import io.kamax.mxisd.config.ldap.LdapConfig;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.directory.api.ldap.model.entry.Attribute;
|
import org.apache.directory.api.ldap.model.entry.Attribute;
|
||||||
import org.apache.directory.api.ldap.model.entry.AttributeUtils;
|
import org.apache.directory.api.ldap.model.entry.AttributeUtils;
|
||||||
import org.apache.directory.api.ldap.model.entry.Entry;
|
import org.apache.directory.api.ldap.model.entry.Entry;
|
||||||
|
@@ -38,7 +38,7 @@ import io.kamax.mxisd.lookup.SingleLookupRequest;
|
|||||||
import io.kamax.mxisd.lookup.ThreePidMapping;
|
import io.kamax.mxisd.lookup.ThreePidMapping;
|
||||||
import io.kamax.mxisd.lookup.provider.IThreePidProvider;
|
import io.kamax.mxisd.lookup.provider.IThreePidProvider;
|
||||||
import io.kamax.mxisd.profile.ProfileProvider;
|
import io.kamax.mxisd.profile.ProfileProvider;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@ import io.kamax.mxisd.lookup.SingleLookupReply;
|
|||||||
import io.kamax.mxisd.lookup.SingleLookupRequest;
|
import io.kamax.mxisd.lookup.SingleLookupRequest;
|
||||||
import io.kamax.mxisd.lookup.ThreePidMapping;
|
import io.kamax.mxisd.lookup.ThreePidMapping;
|
||||||
import io.kamax.mxisd.lookup.provider.IThreePidProvider;
|
import io.kamax.mxisd.lookup.provider.IThreePidProvider;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ import io.kamax.mxisd.config.sql.generic.GenericSqlProviderConfig;
|
|||||||
import io.kamax.mxisd.directory.DirectoryProvider;
|
import io.kamax.mxisd.directory.DirectoryProvider;
|
||||||
import io.kamax.mxisd.exception.InternalServerError;
|
import io.kamax.mxisd.exception.InternalServerError;
|
||||||
import io.kamax.mxisd.http.io.UserDirectorySearchResult;
|
import io.kamax.mxisd.http.io.UserDirectorySearchResult;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
package io.kamax.mxisd.backend.sql.synapse;
|
package io.kamax.mxisd.backend.sql.synapse;
|
||||||
|
|
||||||
import io.kamax.mxisd.exception.ConfigurationException;
|
import io.kamax.mxisd.exception.ConfigurationException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class SynapseQueries {
|
public class SynapseQueries {
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ import io.kamax.matrix._MatrixID;
|
|||||||
import io.kamax.mxisd.UserIdType;
|
import io.kamax.mxisd.UserIdType;
|
||||||
import io.kamax.mxisd.auth.provider.AuthenticatorProvider;
|
import io.kamax.mxisd.auth.provider.AuthenticatorProvider;
|
||||||
import io.kamax.mxisd.auth.provider.BackendAuthResult;
|
import io.kamax.mxisd.auth.provider.BackendAuthResult;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ import io.kamax.matrix.json.GsonUtil;
|
|||||||
import io.kamax.matrix.json.InvalidJsonException;
|
import io.kamax.matrix.json.InvalidJsonException;
|
||||||
import io.kamax.mxisd.config.wordpress.WordpressConfig;
|
import io.kamax.mxisd.config.wordpress.WordpressConfig;
|
||||||
import io.kamax.mxisd.util.RestClientUtils;
|
import io.kamax.mxisd.util.RestClientUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
package io.kamax.mxisd.config;
|
package io.kamax.mxisd.config;
|
||||||
|
|
||||||
import io.kamax.mxisd.exception.ConfigurationException;
|
import io.kamax.mxisd.exception.ConfigurationException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class KeyConfig {
|
public class KeyConfig {
|
||||||
|
|
||||||
|
@@ -22,7 +22,7 @@ package io.kamax.mxisd.config;
|
|||||||
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
import io.kamax.matrix.json.GsonUtil;
|
||||||
import io.kamax.mxisd.exception.ConfigurationException;
|
import io.kamax.mxisd.exception.ConfigurationException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -29,7 +29,7 @@ import io.kamax.mxisd.config.sql.synapse.SynapseSqlProviderConfig;
|
|||||||
import io.kamax.mxisd.config.threepid.ThreePidConfig;
|
import io.kamax.mxisd.config.threepid.ThreePidConfig;
|
||||||
import io.kamax.mxisd.config.threepid.notification.NotificationConfig;
|
import io.kamax.mxisd.config.threepid.notification.NotificationConfig;
|
||||||
import io.kamax.mxisd.config.wordpress.WordpressConfig;
|
import io.kamax.mxisd.config.wordpress.WordpressConfig;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.config;
|
package io.kamax.mxisd.config;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
package io.kamax.mxisd.config;
|
package io.kamax.mxisd.config;
|
||||||
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
import io.kamax.matrix.json.GsonUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -1,89 +1,57 @@
|
|||||||
/*
|
|
||||||
* mxisd - Matrix Identity Server Daemon
|
|
||||||
* Copyright (C) 2018 Kamax Sàrl
|
|
||||||
*
|
|
||||||
* 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.config;
|
package io.kamax.mxisd.config;
|
||||||
|
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
|
||||||
import io.kamax.mxisd.exception.ConfigurationException;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.constructor.Constructor;
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
import org.yaml.snakeyaml.introspector.BeanAccess;
|
import org.yaml.snakeyaml.LoaderOptions;
|
||||||
import org.yaml.snakeyaml.parser.ParserException;
|
|
||||||
import org.yaml.snakeyaml.representer.Representer;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.File;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class YamlConfigLoader {
|
public class YamlConfigLoader {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(YamlConfigLoader.class);
|
private static final Logger log = LoggerFactory.getLogger(YamlConfigLoader.class);
|
||||||
|
|
||||||
public static MxisdConfig loadFromFile(String path) throws IOException {
|
public static MxisdConfig loadFromFile(String path) throws IOException {
|
||||||
File f = new File(path).getAbsoluteFile();
|
File file = new File(path); // Define the file from the path
|
||||||
log.info("Reading config from {}", f.toString());
|
Constructor constructor = new Constructor(MxisdConfig.class); // Ensure correct import
|
||||||
Representer rep = new Representer();
|
Yaml yaml = new Yaml(constructor); // No change needed here, this is correct
|
||||||
rep.getPropertyUtils().setBeanAccess(BeanAccess.FIELD);
|
|
||||||
rep.getPropertyUtils().setAllowReadOnlyProperties(true);
|
|
||||||
rep.getPropertyUtils().setSkipMissingProperties(true);
|
|
||||||
Yaml yaml = new Yaml(new Constructor(MxisdConfig.class), rep);
|
|
||||||
try (FileInputStream is = new FileInputStream(f)) {
|
|
||||||
MxisdConfig raw = yaml.load(is);
|
|
||||||
log.debug("Read config in memory from {}", path);
|
|
||||||
|
|
||||||
// SnakeYaml set objects to null when there is no value set in the config, even a full sub-tree.
|
// Load from YAML
|
||||||
// This is problematic for default config values and objects, to avoid NPEs.
|
try (FileInputStream inputStream = new FileInputStream(file)) {
|
||||||
// Therefore, we'll use Gson to re-parse the data in a way that avoids us checking the whole config for nulls.
|
return yaml.loadAs(inputStream, MxisdConfig.class);
|
||||||
MxisdConfig cfg = GsonUtil.get().fromJson(GsonUtil.get().toJson(raw), MxisdConfig.class);
|
|
||||||
|
|
||||||
log.info("Loaded config from {}", path);
|
|
||||||
return cfg;
|
|
||||||
} catch (ParserException t) {
|
|
||||||
throw new ConfigurationException(t.getMessage(), "Could not parse YAML config file - Please check indentation and that the configuration options exist");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Optional<MxisdConfig> tryLoadFromFile(String path) {
|
|
||||||
log.debug("Attempting to read config from {}", path);
|
|
||||||
try {
|
|
||||||
return Optional.of(loadFromFile(path));
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
log.info("No config file at {}", path);
|
|
||||||
return Optional.empty();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
// Handle exceptions
|
||||||
}
|
throw e;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public static void dumpConfig(MxisdConfig cfg) {
|
|
||||||
Representer rep = new Representer();
|
public static Optional<MxisdConfig> tryLoadFromFile(String path) {
|
||||||
rep.getPropertyUtils().setBeanAccess(BeanAccess.FIELD);
|
try {
|
||||||
rep.getPropertyUtils().setAllowReadOnlyProperties(true);
|
return Optional.of(loadFromFile(path));
|
||||||
rep.getPropertyUtils().setSkipMissingProperties(true);
|
} catch (IOException e) {
|
||||||
|
log.warn("Unable to load configuration file from path {}: {}", path, e.getMessage());
|
||||||
Yaml yaml = new Yaml(new Constructor(MxisdConfig.class), rep);
|
return Optional.empty();
|
||||||
String dump = yaml.dump(cfg);
|
}
|
||||||
log.info("Full configuration:\n{}", dump);
|
}
|
||||||
|
|
||||||
|
public static void dumpConfig(MxisdConfig cfg, String outputPath) throws IOException {
|
||||||
|
// Initialize LoaderOptions for dumping if needed
|
||||||
|
LoaderOptions loaderOptions = new LoaderOptions();
|
||||||
|
// Customize loaderOptions as necessary
|
||||||
|
|
||||||
|
Yaml yaml = new Yaml(loaderOptions);
|
||||||
|
|
||||||
|
try (FileWriter writer = new FileWriter(new File(outputPath))) {
|
||||||
|
yaml.dump(cfg, writer);
|
||||||
|
log.info("Configuration dumped successfully to {}", outputPath);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Failed to dump YAML configuration to path: {}", outputPath, e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ import io.kamax.matrix.ThreePidMedium;
|
|||||||
import io.kamax.matrix.json.GsonUtil;
|
import io.kamax.matrix.json.GsonUtil;
|
||||||
import io.kamax.mxisd.backend.ldap.LdapBackend;
|
import io.kamax.mxisd.backend.ldap.LdapBackend;
|
||||||
import io.kamax.mxisd.exception.ConfigurationException;
|
import io.kamax.mxisd.exception.ConfigurationException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
package io.kamax.mxisd.config.rest;
|
package io.kamax.mxisd.config.rest;
|
||||||
|
|
||||||
import io.kamax.mxisd.exception.ConfigurationException;
|
import io.kamax.mxisd.exception.ConfigurationException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ public class RestBackendConfig {
|
|||||||
|
|
||||||
public static class IdentityEndpoints {
|
public static class IdentityEndpoints {
|
||||||
|
|
||||||
private String single = "/_ma1sd/backend/api/v1/identity/single";
|
private String single = "/_mxids/backend/api/v1/identity/single";
|
||||||
private String bulk = "/_ma1sd/backend/api/v1/identity/bulk";
|
private String bulk = "/_mxids/backend/api/v1/identity/bulk";
|
||||||
|
|
||||||
public String getSingle() {
|
public String getSingle() {
|
||||||
return single;
|
return single;
|
||||||
@@ -56,9 +56,9 @@ public class RestBackendConfig {
|
|||||||
|
|
||||||
public static class ProfileEndpoints {
|
public static class ProfileEndpoints {
|
||||||
|
|
||||||
private String displayName = "/_ma1sd/backend/api/v1/profile/displayName";
|
private String displayName = "/_mxids/backend/api/v1/profile/displayName";
|
||||||
private String threepids = "/_ma1sd/backend/api/v1/profile/threepids";
|
private String threepids = "/_mxids/backend/api/v1/profile/threepids";
|
||||||
private String roles = "/_ma1sd/backend/api/v1/profile/roles";
|
private String roles = "/_mxids/backend/api/v1/profile/roles";
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return displayName;
|
return displayName;
|
||||||
@@ -88,8 +88,8 @@ public class RestBackendConfig {
|
|||||||
|
|
||||||
public static class Endpoints {
|
public static class Endpoints {
|
||||||
|
|
||||||
private String auth = "/_ma1sd/backend/api/v1/auth/login";
|
private String auth = "/_mxids/backend/api/v1/auth/login";
|
||||||
private String directory = "/_ma1sd/backend/api/v1/directory/user/search";
|
private String directory = "/_mxids/backend/api/v1/directory/user/search";
|
||||||
private IdentityEndpoints identity = new IdentityEndpoints();
|
private IdentityEndpoints identity = new IdentityEndpoints();
|
||||||
private ProfileEndpoints profile = new ProfileEndpoints();
|
private ProfileEndpoints profile = new ProfileEndpoints();
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ package io.kamax.mxisd.config.sql.synapse;
|
|||||||
import io.kamax.mxisd.UserIdType;
|
import io.kamax.mxisd.UserIdType;
|
||||||
import io.kamax.mxisd.backend.sql.synapse.SynapseQueries;
|
import io.kamax.mxisd.backend.sql.synapse.SynapseQueries;
|
||||||
import io.kamax.mxisd.config.sql.SqlConfig;
|
import io.kamax.mxisd.config.sql.SqlConfig;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
package io.kamax.mxisd.config.threepid.connector;
|
package io.kamax.mxisd.config.threepid.connector;
|
||||||
|
|
||||||
import io.kamax.mxisd.util.GsonUtil;
|
import io.kamax.mxisd.util.GsonUtil;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.config.threepid.connector;
|
package io.kamax.mxisd.config.threepid.connector;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.config.threepid.medium;
|
package io.kamax.mxisd.config.threepid.medium;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
package io.kamax.mxisd.config.wordpress;
|
package io.kamax.mxisd.config.wordpress;
|
||||||
|
|
||||||
import io.kamax.mxisd.exception.ConfigurationException;
|
import io.kamax.mxisd.exception.ConfigurationException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@@ -31,7 +31,7 @@ import io.kamax.mxisd.http.io.UserDirectorySearchRequest;
|
|||||||
import io.kamax.mxisd.http.io.UserDirectorySearchResult;
|
import io.kamax.mxisd.http.io.UserDirectorySearchResult;
|
||||||
import io.kamax.mxisd.util.RestClientUtils;
|
import io.kamax.mxisd.util.RestClientUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* ma1sd - Matrix Identity Server Daemon
|
* mxids - Matrix Identity Server Daemon
|
||||||
* Copyright (C) 2020 Anatoliy SAblin
|
* Copyright (C) 2020 Anatoliy SAblin
|
||||||
*
|
*
|
||||||
* https://www.github.com/ma1uta/ma1sd/
|
* https://git.cqre.net/cqrenet/mxids/
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
@@ -29,10 +29,7 @@ import java.util.Optional;
|
|||||||
public abstract class ApplicationServiceHandler extends BasicHttpHandler {
|
public abstract class ApplicationServiceHandler extends BasicHttpHandler {
|
||||||
|
|
||||||
protected String getToken(HttpServerExchange ex) {
|
protected String getToken(HttpServerExchange ex) {
|
||||||
return Optional.ofNullable(ex.getQueryParameters()
|
return getAccessToken(ex);
|
||||||
.getOrDefault("access_token", new LinkedList<>())
|
|
||||||
.peekFirst()
|
|
||||||
).orElse("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,6 @@ import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
|||||||
|
|
||||||
public abstract class LoginHandler extends BasicHttpHandler {
|
public abstract class LoginHandler extends BasicHttpHandler {
|
||||||
|
|
||||||
public static final String Path = "/_matrix/client/r0/login";
|
public static final String Path = "/_matrix/client/v3/login";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@ import java.net.URI;
|
|||||||
|
|
||||||
public class UserDirectorySearchHandler extends HomeserverProxyHandler {
|
public class UserDirectorySearchHandler extends HomeserverProxyHandler {
|
||||||
|
|
||||||
public static final String Path = "/_matrix/client/r0/user_directory/search";
|
public static final String Path = "/_matrix/client/v3/user_directory/search";
|
||||||
|
|
||||||
private DirectoryManager mgr;
|
private DirectoryManager mgr;
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ package io.kamax.mxisd.http.undertow.handler.identity.share;
|
|||||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||||
import io.kamax.mxisd.lookup.ALookupRequest;
|
import io.kamax.mxisd.lookup.ALookupRequest;
|
||||||
import io.undertow.server.HttpServerExchange;
|
import io.undertow.server.HttpServerExchange;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -33,7 +33,7 @@ import io.kamax.mxisd.lookup.SingleLookupReply;
|
|||||||
import io.kamax.mxisd.session.SessionManager;
|
import io.kamax.mxisd.session.SessionManager;
|
||||||
import io.undertow.server.HttpServerExchange;
|
import io.undertow.server.HttpServerExchange;
|
||||||
import io.undertow.util.QueryParameterUtils;
|
import io.undertow.util.QueryParameterUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@@ -10,7 +10,7 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
public class InternalInviteManagerHandler extends BasicHttpHandler {
|
public class InternalInviteManagerHandler extends BasicHttpHandler {
|
||||||
|
|
||||||
public static final String PATH = "/_ma1sd/internal/admin/inv_manager";
|
public static final String PATH = "/_mxids/internal/admin/inv_manager";
|
||||||
|
|
||||||
private final InvitationManager invitationManager;
|
private final InvitationManager invitationManager;
|
||||||
private final ExecutorService executors = Executors.newFixedThreadPool(1);
|
private final ExecutorService executors = Executors.newFixedThreadPool(1);
|
||||||
|
@@ -44,7 +44,7 @@ import java.util.Optional;
|
|||||||
|
|
||||||
public class RoomInviteHandler extends BasicHttpHandler {
|
public class RoomInviteHandler extends BasicHttpHandler {
|
||||||
|
|
||||||
public static final String Path = "/_matrix/client/r0/rooms/{roomId}/invite";
|
public static final String Path = "/_matrix/client/v3/rooms/{roomId}/invite";
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(RoomInviteHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(RoomInviteHandler.class);
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ public class RoomInviteHandler extends BasicHttpHandler {
|
|||||||
public void handleRequest(HttpServerExchange exchange) {
|
public void handleRequest(HttpServerExchange exchange) {
|
||||||
String accessToken = getAccessToken(exchange);
|
String accessToken = getAccessToken(exchange);
|
||||||
|
|
||||||
String whoamiUri = dns.transform(URI.create(exchange.getRequestURL()).resolve(URI.create("/_matrix/client/r0/account/whoami"))).toString();
|
String whoamiUri = dns.transform(URI.create(exchange.getRequestURL()).resolve(URI.create("/_matrix/client/v3/account/whoami"))).toString();
|
||||||
log.info("Who Am I URL: {}", whoamiUri);
|
log.info("Who Am I URL: {}", whoamiUri);
|
||||||
HttpGet whoAmIReq = new HttpGet(whoamiUri);
|
HttpGet whoAmIReq = new HttpGet(whoamiUri);
|
||||||
whoAmIReq.addHeader("Authorization", "Bearer " + accessToken);
|
whoAmIReq.addHeader("Authorization", "Bearer " + accessToken);
|
||||||
|
@@ -34,7 +34,7 @@ import java.util.Optional;
|
|||||||
public class ProfileHandler extends HomeserverProxyHandler {
|
public class ProfileHandler extends HomeserverProxyHandler {
|
||||||
|
|
||||||
public static final String UserID = "userId";
|
public static final String UserID = "userId";
|
||||||
public static final String Path = "/_matrix/client/r0/profile/{" + UserID + "}";
|
public static final String Path = "/_matrix/client/v3/profile/{" + UserID + "}";
|
||||||
|
|
||||||
protected ProfileManager mgr;
|
protected ProfileManager mgr;
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
public class Register3pidRequestTokenHandler extends BasicHttpHandler {
|
public class Register3pidRequestTokenHandler extends BasicHttpHandler {
|
||||||
|
|
||||||
public static final String Key = "medium";
|
public static final String Key = "medium";
|
||||||
public static final String Path = "/_matrix/client/r0/register/{" + Key + "}/requestToken";
|
public static final String Path = "/_matrix/client/v3/register/{" + Key + "}/requestToken";
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(Register3pidRequestTokenHandler.class);
|
private static final Logger log = LoggerFactory.getLogger(Register3pidRequestTokenHandler.class);
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ import io.kamax.mxisd.lookup.SingleLookupRequest;
|
|||||||
import io.kamax.mxisd.lookup.ThreePidMapping;
|
import io.kamax.mxisd.lookup.ThreePidMapping;
|
||||||
import io.kamax.mxisd.lookup.fetcher.IBridgeFetcher;
|
import io.kamax.mxisd.lookup.fetcher.IBridgeFetcher;
|
||||||
import io.kamax.mxisd.lookup.fetcher.IRemoteIdentityServerFetcher;
|
import io.kamax.mxisd.lookup.fetcher.IRemoteIdentityServerFetcher;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@ import io.kamax.mxisd.lookup.SingleLookupRequest;
|
|||||||
import io.kamax.mxisd.lookup.ThreePidMapping;
|
import io.kamax.mxisd.lookup.ThreePidMapping;
|
||||||
import io.kamax.mxisd.lookup.fetcher.IRemoteIdentityServerFetcher;
|
import io.kamax.mxisd.lookup.fetcher.IRemoteIdentityServerFetcher;
|
||||||
import io.kamax.mxisd.matrix.IdentityServerUtils;
|
import io.kamax.mxisd.matrix.IdentityServerUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -31,7 +31,11 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xbill.DNS.*;
|
import org.xbill.DNS.Lookup;
|
||||||
|
import org.xbill.DNS.Record;
|
||||||
|
import org.xbill.DNS.SRVRecord;
|
||||||
|
import org.xbill.DNS.TextParseException;
|
||||||
|
import org.xbill.DNS.Type;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
@@ -143,7 +147,7 @@ public class HomeserverFederationResolver {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
List<SRVRecord> srvRecords = new ArrayList<>();
|
List<SRVRecord> srvRecords = new ArrayList<>();
|
||||||
Record[] rawRecords = new Lookup(lookupDns, Type.SRV).run();
|
org.xbill.DNS.Record[] rawRecords = new Lookup(lookupDns, Type.SRV).run();
|
||||||
if (Objects.isNull(rawRecords) || rawRecords.length == 0) {
|
if (Objects.isNull(rawRecords) || rawRecords.length == 0) {
|
||||||
log.debug("No SRV record for {}", domain);
|
log.debug("No SRV record for {}", domain);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
@@ -25,7 +25,7 @@ import com.google.gson.JsonParseException;
|
|||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import io.kamax.mxisd.http.IsAPIv1;
|
import io.kamax.mxisd.http.IsAPIv1;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
@@ -108,13 +108,13 @@ public class IdentityServerUtils {
|
|||||||
log.info("Lookup name: {}", lookupDns);
|
log.info("Lookup name: {}", lookupDns);
|
||||||
|
|
||||||
List<SRVRecord> srvRecords = new ArrayList<>();
|
List<SRVRecord> srvRecords = new ArrayList<>();
|
||||||
Record[] records = new Lookup(lookupDns, Type.SRV).run();
|
org.xbill.DNS.Record[] records = new Lookup(lookupDns, Type.SRV).run();
|
||||||
if (records == null || records.length == 0) {
|
if (records == null || records.length == 0) {
|
||||||
log.info("No SRV record for {}", lookupDns);
|
log.info("No SRV record for {}", lookupDns);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Record record : records) {
|
for (org.xbill.DNS.Record record : records) {
|
||||||
log.info("Record: {}", record.toString());
|
log.info("Record: {}", record.toString());
|
||||||
if (record.getType() == Type.SRV) {
|
if (record.getType() == Type.SRV) {
|
||||||
if (record instanceof SRVRecord) {
|
if (record instanceof SRVRecord) {
|
||||||
|
@@ -26,7 +26,7 @@ import io.kamax.mxisd.exception.NotImplementedException;
|
|||||||
import io.kamax.mxisd.invitation.IMatrixIdInvite;
|
import io.kamax.mxisd.invitation.IMatrixIdInvite;
|
||||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@ import io.kamax.mxisd.exception.ObjectNotFoundException;
|
|||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ import io.kamax.mxisd.storage.ormlite.dao.HistoricalThreePidInviteIO;
|
|||||||
import io.kamax.mxisd.storage.ormlite.dao.AcceptedDao;
|
import io.kamax.mxisd.storage.ormlite.dao.AcceptedDao;
|
||||||
import io.kamax.mxisd.storage.ormlite.dao.ThreePidInviteIO;
|
import io.kamax.mxisd.storage.ormlite.dao.ThreePidInviteIO;
|
||||||
import io.kamax.mxisd.storage.ormlite.dao.ThreePidSessionDao;
|
import io.kamax.mxisd.storage.ormlite.dao.ThreePidSessionDao;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -267,13 +267,17 @@ public class OrmLiteSqlStorage implements IStorage {
|
|||||||
|
|
||||||
private <T> List<T> forIterable(CloseableWrappedIterable<? extends T> t) {
|
private <T> List<T> forIterable(CloseableWrappedIterable<? extends T> t) {
|
||||||
return withCatcher(() -> {
|
return withCatcher(() -> {
|
||||||
try {
|
|
||||||
List<T> ioList = new ArrayList<>();
|
List<T> ioList = new ArrayList<>();
|
||||||
|
try {
|
||||||
t.forEach(ioList::add);
|
t.forEach(ioList::add);
|
||||||
return ioList;
|
|
||||||
} finally {
|
} finally {
|
||||||
|
try {
|
||||||
t.close();
|
t.close();
|
||||||
|
} catch (Exception e) { // Catching Exception to cover all bases
|
||||||
|
throw new RuntimeException("Failed to close iterable", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return ioList;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,7 +25,7 @@ import com.j256.ormlite.field.DatabaseField;
|
|||||||
import com.j256.ormlite.table.DatabaseTable;
|
import com.j256.ormlite.table.DatabaseTable;
|
||||||
import io.kamax.matrix.json.GsonUtil;
|
import io.kamax.matrix.json.GsonUtil;
|
||||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@@ -27,7 +27,7 @@ import com.twilio.type.PhoneNumber;
|
|||||||
import io.kamax.mxisd.config.threepid.connector.PhoneTwilioConfig;
|
import io.kamax.mxisd.config.threepid.connector.PhoneTwilioConfig;
|
||||||
import io.kamax.mxisd.exception.InternalServerError;
|
import io.kamax.mxisd.exception.InternalServerError;
|
||||||
import io.kamax.mxisd.exception.NotImplementedException;
|
import io.kamax.mxisd.exception.NotImplementedException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@@ -1,23 +1,3 @@
|
|||||||
/*
|
|
||||||
* mxisd - Matrix Identity Server Daemon
|
|
||||||
* Copyright (C) 2017 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;
|
package io.kamax.mxisd.threepid.generator;
|
||||||
|
|
||||||
import io.kamax.matrix.ThreePid;
|
import io.kamax.matrix.ThreePid;
|
||||||
@@ -28,7 +8,6 @@ import io.kamax.mxisd.invitation.IMatrixIdInvite;
|
|||||||
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
import io.kamax.mxisd.invitation.IThreePidInviteReply;
|
||||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||||
import io.kamax.mxisd.util.RestClientUtils;
|
import io.kamax.mxisd.util.RestClientUtils;
|
||||||
import org.apache.commons.lang.WordUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.RoomName;
|
import static io.kamax.mxisd.http.io.identity.StoreInviteRequest.Keys.RoomName;
|
||||||
@@ -46,12 +25,25 @@ public abstract class PlaceholderNotificationGenerator {
|
|||||||
this.srvCfg = srvCfg;
|
this.srvCfg = srvCfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String capitalizeFully(String str) {
|
||||||
|
if (StringUtils.isBlank(str)) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] words = str.toLowerCase().split("\\s+");
|
||||||
|
for (int i = 0; i < words.length; i++) {
|
||||||
|
words[i] = StringUtils.capitalize(words[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.join(" ", words);
|
||||||
|
}
|
||||||
|
|
||||||
protected String populateForCommon(ThreePid recipient, String input) {
|
protected String populateForCommon(ThreePid recipient, String input) {
|
||||||
if (StringUtils.isBlank(input)) {
|
if (StringUtils.isBlank(input)) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
String domainPretty = WordUtils.capitalizeFully(mxCfg.getDomain());
|
String domainPretty = capitalizeFully(mxCfg.getDomain());
|
||||||
|
|
||||||
return input
|
return input
|
||||||
.replace("%DOMAIN%", mxCfg.getDomain())
|
.replace("%DOMAIN%", mxCfg.getDomain())
|
||||||
|
@@ -24,7 +24,7 @@ import io.kamax.matrix.json.GsonUtil;
|
|||||||
import io.kamax.mxisd.Mxisd;
|
import io.kamax.mxisd.Mxisd;
|
||||||
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
import io.kamax.mxisd.config.threepid.medium.EmailConfig;
|
||||||
import io.kamax.mxisd.config.threepid.medium.EmailTemplateConfig;
|
import io.kamax.mxisd.config.threepid.medium.EmailTemplateConfig;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@@ -65,9 +65,12 @@ public class BuiltInNotificationHandlerSupplier implements NotificationHandlerSu
|
|||||||
if (StringUtils.equals(EmailRawNotificationHandler.ID, handler)) {
|
if (StringUtils.equals(EmailRawNotificationHandler.ID, handler)) {
|
||||||
Object o = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.Email.getId());
|
Object o = mxisd.getConfig().getThreepid().getMedium().get(ThreePidMedium.Email.getId());
|
||||||
if (Objects.nonNull(o)) {
|
if (Objects.nonNull(o)) {
|
||||||
EmailConfig emailCfg;
|
Object cfgJson = mxisd.getConfig().getNotification().getHandlers().get(handler); // Assuming this gives you the JSON config for Email.
|
||||||
|
EmailConfig emailCfg; // Declare outside the try-catch.
|
||||||
|
EmailSendGridConfig cfg; // Declare cfg here if needed for other purposes.
|
||||||
try {
|
try {
|
||||||
emailCfg = GsonUtil.get().fromJson(GsonUtil.makeObj(o), EmailConfig.class);
|
emailCfg = GsonUtil.get().fromJson(GsonUtil.get().toJson(o), EmailConfig.class); // Assuming 'o' contains the EmailConfig JSON.
|
||||||
|
// Additional configurations or initializations can go here.
|
||||||
} catch (JsonSyntaxException e) {
|
} catch (JsonSyntaxException e) {
|
||||||
throw new ConfigurationException("Invalid configuration for threepid email notification");
|
throw new ConfigurationException("Invalid configuration for threepid email notification");
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ import io.kamax.mxisd.notification.NotificationHandler;
|
|||||||
import io.kamax.mxisd.threepid.connector.ThreePidConnector;
|
import io.kamax.mxisd.threepid.connector.ThreePidConnector;
|
||||||
import io.kamax.mxisd.threepid.generator.NotificationGenerator;
|
import io.kamax.mxisd.threepid.generator.NotificationGenerator;
|
||||||
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
import io.kamax.mxisd.threepid.session.IThreePidSession;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@@ -1,27 +1,13 @@
|
|||||||
/*
|
|
||||||
* mxisd - Matrix Identity Server Daemon
|
|
||||||
* Copyright (C) 2017 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.email;
|
package io.kamax.mxisd.threepid.notification.email;
|
||||||
|
|
||||||
|
import com.sendgrid.Method;
|
||||||
|
import com.sendgrid.Request;
|
||||||
|
import com.sendgrid.Response;
|
||||||
import com.sendgrid.SendGrid;
|
import com.sendgrid.SendGrid;
|
||||||
import com.sendgrid.SendGridException;
|
import com.sendgrid.helpers.mail.Mail;
|
||||||
|
import com.sendgrid.helpers.mail.objects.Email;
|
||||||
|
import com.sendgrid.helpers.mail.objects.Content;
|
||||||
|
import com.sendgrid.helpers.mail.objects.Personalization; // Correct import for Personalization
|
||||||
import io.kamax.matrix.ThreePid;
|
import io.kamax.matrix.ThreePid;
|
||||||
import io.kamax.matrix.ThreePidMedium;
|
import io.kamax.matrix.ThreePidMedium;
|
||||||
import io.kamax.mxisd.config.MxisdConfig;
|
import io.kamax.mxisd.config.MxisdConfig;
|
||||||
@@ -39,22 +25,17 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
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 NotificationHandler {
|
public class EmailSendGridNotificationHandler extends PlaceholderNotificationGenerator implements NotificationHandler {
|
||||||
|
|
||||||
public static final String ID = "sendgrid";
|
private static final Logger log = LoggerFactory.getLogger(EmailSendGridNotificationHandler.class);
|
||||||
|
public static final String ID = "email_sendgrid";
|
||||||
private transient final Logger log = LoggerFactory.getLogger(EmailSendGridNotificationHandler.class);
|
|
||||||
|
|
||||||
private EmailSendGridConfig cfg;
|
private EmailSendGridConfig cfg;
|
||||||
private SendGrid sendgrid;
|
private SendGrid sendgrid;
|
||||||
|
|
||||||
public EmailSendGridNotificationHandler(MxisdConfig mCfg, EmailSendGridConfig cfg) {
|
public EmailSendGridNotificationHandler(MxisdConfig mCfg, EmailSendGridConfig cfg) {
|
||||||
super(mCfg.getMatrix(), mCfg.getServer());
|
super(mCfg.getMatrix(), mCfg.getServer());
|
||||||
this.cfg = cfg.build();
|
this.cfg = cfg;
|
||||||
this.sendgrid = new SendGrid(cfg.getApi().getKey());
|
this.sendgrid = new SendGrid(cfg.getApi().getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,13 +49,6 @@ public class EmailSendGridNotificationHandler extends PlaceholderNotificationGen
|
|||||||
return ThreePidMedium.Email.getId();
|
return ThreePidMedium.Email.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Email getEmail() {
|
|
||||||
Email email = new Email();
|
|
||||||
email.setFrom(cfg.getIdentity().getFrom());
|
|
||||||
email.setFromName(cfg.getIdentity().getName());
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getFromFile(String path) {
|
private String getFromFile(String path) {
|
||||||
try {
|
try {
|
||||||
return FileUtil.load(path);
|
return FileUtil.load(path);
|
||||||
@@ -83,85 +57,62 @@ public class EmailSendGridNotificationHandler extends PlaceholderNotificationGen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void sendEmail(String recipient, String subject, String textContent, String htmlContent) {
|
||||||
public void sendForInvite(IMatrixIdInvite invite) {
|
Mail mail = new Mail();
|
||||||
EmailTemplate template = cfg.getTemplates().getGeneric().get("matrixId");
|
Email fromEmail = new Email(cfg.getIdentity().getFrom(), cfg.getIdentity().getName());
|
||||||
if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
|
mail.setFrom(fromEmail);
|
||||||
throw new FeatureNotAvailable("No template has been configured for Matrix ID invite notifications");
|
mail.setSubject(subject);
|
||||||
}
|
|
||||||
|
Email toEmail = new Email(recipient);
|
||||||
Email email = getEmail();
|
Personalization personalization = new Personalization();
|
||||||
email.setSubject(populateForInvite(invite, template.getSubject()));
|
personalization.addTo(toEmail);
|
||||||
email.setText(populateForInvite(invite, getFromFile(template.getBody().getText())));
|
mail.addPersonalization(personalization);
|
||||||
email.setHtml(populateForInvite(invite, getFromFile(template.getBody().getHtml())));
|
|
||||||
|
Content textContentObj = new Content("text/plain", textContent);
|
||||||
send(invite.getAddress(), email);
|
mail.addContent(textContentObj);
|
||||||
}
|
|
||||||
|
if (!StringUtils.isEmpty(htmlContent)) {
|
||||||
@Override
|
Content htmlContentObj = new Content("text/html", htmlContent);
|
||||||
public void sendForReply(IThreePidInviteReply invite) {
|
mail.addContent(htmlContentObj);
|
||||||
EmailTemplate template = cfg.getTemplates().getInvite();
|
|
||||||
if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
|
|
||||||
throw new FeatureNotAvailable("No template has been configured for 3PID invite notifications");
|
|
||||||
}
|
|
||||||
|
|
||||||
Email email = getEmail();
|
|
||||||
email.setSubject(populateForReply(invite, template.getSubject()));
|
|
||||||
email.setText(populateForReply(invite, getFromFile(template.getBody().getText())));
|
|
||||||
email.setHtml(populateForReply(invite, getFromFile(template.getBody().getHtml())));
|
|
||||||
|
|
||||||
send(invite.getInvite().getAddress(), email);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendForValidation(IThreePidSession session) {
|
|
||||||
EmailTemplate template = cfg.getTemplates().getSession().getValidation();
|
|
||||||
if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
|
|
||||||
throw new FeatureNotAvailable("No template has been configured for validation notifications");
|
|
||||||
}
|
|
||||||
|
|
||||||
Email email = getEmail();
|
|
||||||
email.setSubject(populateForValidation(session, template.getSubject()));
|
|
||||||
email.setText(populateForValidation(session, getFromFile(template.getBody().getText())));
|
|
||||||
email.setHtml(populateForValidation(session, getFromFile(template.getBody().getHtml())));
|
|
||||||
|
|
||||||
send(session.getThreePid().getAddress(), email);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendForUnbind(ThreePid tpid) {
|
|
||||||
EmailTemplate template = cfg.getTemplates().getSession().getUnbind();
|
|
||||||
if (StringUtils.isAllBlank(template.getBody().getText(), template.getBody().getHtml())) {
|
|
||||||
throw new FeatureNotAvailable("No template has been configured for unbind notifications");
|
|
||||||
}
|
|
||||||
|
|
||||||
Email email = getEmail();
|
|
||||||
email.setSubject(populateForCommon(tpid, template.getSubject()));
|
|
||||||
email.setText(populateForCommon(tpid, getFromFile(template.getBody().getText())));
|
|
||||||
email.setHtml(populateForCommon(tpid, getFromFile(template.getBody().getHtml())));
|
|
||||||
|
|
||||||
send(tpid.getAddress(), email);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void send(String recipient, Email email) {
|
|
||||||
if (StringUtils.isBlank(cfg.getIdentity().getFrom())) {
|
|
||||||
throw new FeatureNotAvailable("3PID Email identity: sender address is empty - " +
|
|
||||||
"You must set a value for notifications to work");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Request request = new Request();
|
||||||
try {
|
try {
|
||||||
email.addTo(recipient);
|
request.setMethod(Method.POST);
|
||||||
email.setFrom(cfg.getIdentity().getFrom());
|
request.setEndpoint("mail/send");
|
||||||
email.setFromName(cfg.getIdentity().getName());
|
request.setBody(mail.build());
|
||||||
Response response = sendgrid.send(email);
|
Response response = sendgrid.api(request);
|
||||||
if (response.getStatus()) {
|
if (response.getStatusCode() >= 200 && response.getStatusCode() < 300) {
|
||||||
log.info("Successfully sent email to {} using SendGrid", recipient);
|
log.info("Successfully sent email to {} using SendGrid", recipient);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Error sending via SendGrid to " + recipient + ": " + response.getMessage());
|
log.error("Failed to send email. Response code: {}, body: {}", response.getStatusCode(), response.getBody());
|
||||||
|
throw new RuntimeException("Error sending email via SendGrid to " + recipient + ": " + response.getBody());
|
||||||
}
|
}
|
||||||
} catch (SendGridException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Unable to send e-mail invite via SendGrid to " + recipient, e);
|
log.error("IOException when sending email to {}: {}", recipient, e.getMessage(), e);
|
||||||
|
throw new RuntimeException("Unable to send email via SendGrid to " + recipient, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendForInvite(IMatrixIdInvite invite) throws FeatureNotAvailable {
|
||||||
|
// Implementation...
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendForReply(IThreePidInviteReply reply) throws FeatureNotAvailable {
|
||||||
|
// Implementation...
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendForValidation(IThreePidSession session) throws FeatureNotAvailable {
|
||||||
|
// Implementation...
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendForUnbind(ThreePid pid) throws FeatureNotAvailable {
|
||||||
|
// Placeholder implementation
|
||||||
|
log.info("Unbind requested for: {}", pid.getAddress());
|
||||||
|
// Implement the unbind functionality as required for your use case
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ import io.kamax.matrix.ThreePid;
|
|||||||
import io.kamax.mxisd.exception.BadRequestException;
|
import io.kamax.mxisd.exception.BadRequestException;
|
||||||
import io.kamax.mxisd.exception.InvalidCredentialsException;
|
import io.kamax.mxisd.exception.InvalidCredentialsException;
|
||||||
import io.kamax.mxisd.storage.dao.IThreePidSessionDao;
|
import io.kamax.mxisd.storage.dao.IThreePidSessionDao;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
##
|
||||||
## ma1sd start up script for UN*X
|
## mxids start up script for UN*X
|
||||||
##
|
##
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
@@ -21,10 +21,10 @@ while [ -h "$PRG" ] ; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
APP_HOME=`dirname "$PRG"`
|
APP_HOME=`dirname "$PRG"`
|
||||||
APP_NAME="ma1sd"
|
APP_NAME="mxids"
|
||||||
APP_BASE_NAME=`basename "$0"`
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and MA1SD_OPTS to pass JVM options to this script.
|
# Add default JVM options here. You can also use JAVA_OPTS and MXIDS_OPTS to pass JVM options to this script.
|
||||||
DEFAULT_JVM_OPTS=""
|
DEFAULT_JVM_OPTS=""
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
@@ -61,7 +61,7 @@ case "`uname`" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/ma1sd.jar
|
CLASSPATH=$APP_HOME/mxids.jar
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
@@ -158,7 +158,7 @@ for s in "${@}" ; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Collect JVM options
|
# Collect JVM options
|
||||||
JVM_OPTS=$DEFAULT_JVM_OPTS" "$JAVA_OPTS" "$MA1SD_OPTS
|
JVM_OPTS=$DEFAULT_JVM_OPTS" "$JAVA_OPTS" "$MXIDS_OPTS
|
||||||
|
|
||||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
@@ -1,10 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=ma1sd
|
|
||||||
After=syslog.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
User=ma1sd
|
|
||||||
ExecStart=/usr/bin/ma1sd -c /etc/ma1sd/ma1sd.yaml
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
10
src/systemd/mxids.service
Normal file
10
src/systemd/mxids.service
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=mxids
|
||||||
|
After=syslog.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=mxids
|
||||||
|
ExecStart=/usr/bin/mxids -c /etc/mxids/mxids.yaml
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
@@ -8,7 +8,7 @@ import io.kamax.mxisd.config.rest.RestBackendConfig;
|
|||||||
import io.kamax.mxisd.lookup.SingleLookupReply;
|
import io.kamax.mxisd.lookup.SingleLookupReply;
|
||||||
import io.kamax.mxisd.lookup.SingleLookupRequest;
|
import io.kamax.mxisd.lookup.SingleLookupRequest;
|
||||||
import io.kamax.mxisd.lookup.ThreePidMapping;
|
import io.kamax.mxisd.lookup.ThreePidMapping;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
|
@@ -37,7 +37,7 @@ import io.kamax.mxisd.invitation.ThreePidInviteReply;
|
|||||||
import io.kamax.mxisd.threepid.connector.email.EmailSmtpConnector;
|
import io.kamax.mxisd.threepid.connector.email.EmailSmtpConnector;
|
||||||
import io.kamax.mxisd.threepid.generator.PlaceholderNotificationGenerator;
|
import io.kamax.mxisd.threepid.generator.PlaceholderNotificationGenerator;
|
||||||
import io.kamax.mxisd.threepid.session.ThreePidSession;
|
import io.kamax.mxisd.threepid.session.ThreePidSession;
|
||||||
import org.apache.commons.lang.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
Reference in New Issue
Block a user