Remove 3PID type limitation
This commit is contained in:
@@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* mxisd - Matrix Identity Server Daemon
|
|
||||||
* Copyright (C) 2017 Maxime Dor
|
|
||||||
*
|
|
||||||
* https://max.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.api
|
|
||||||
|
|
||||||
enum ThreePidType {
|
|
||||||
|
|
||||||
email,
|
|
||||||
msisdn,
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.config
|
package io.kamax.mxisd.config
|
||||||
|
|
||||||
import io.kamax.mxisd.api.ThreePidType
|
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.beans.factory.InitializingBean
|
import org.springframework.beans.factory.InitializingBean
|
||||||
@@ -40,7 +39,7 @@ class LdapConfig implements InitializingBean {
|
|||||||
private String attribute
|
private String attribute
|
||||||
private String bindDn
|
private String bindDn
|
||||||
private String bindPassword
|
private String bindPassword
|
||||||
private Map<ThreePidType, String> mappings
|
private Map<String, String> mappings
|
||||||
|
|
||||||
String getHost() {
|
String getHost() {
|
||||||
return host
|
return host
|
||||||
@@ -98,15 +97,15 @@ class LdapConfig implements InitializingBean {
|
|||||||
this.bindPassword = bindPassword
|
this.bindPassword = bindPassword
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<ThreePidType, String> getMappings() {
|
Map<String, String> getMappings() {
|
||||||
return mappings
|
return mappings
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMappings(Map<ThreePidType, String> mappings) {
|
void setMappings(Map<String, String> mappings) {
|
||||||
this.mappings = mappings
|
this.mappings = mappings
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<String> getMapping(ThreePidType type) {
|
Optional<String> getMapping(String type) {
|
||||||
if (mappings == null) {
|
if (mappings == null) {
|
||||||
return Optional.empty()
|
return Optional.empty()
|
||||||
}
|
}
|
||||||
@@ -118,4 +117,5 @@ class LdapConfig implements InitializingBean {
|
|||||||
void afterPropertiesSet() throws Exception {
|
void afterPropertiesSet() throws Exception {
|
||||||
log.info("Matrix ID type: {}", getType())
|
log.info("Matrix ID type: {}", getType())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ package io.kamax.mxisd.controller.v1
|
|||||||
|
|
||||||
import groovy.json.JsonOutput
|
import groovy.json.JsonOutput
|
||||||
import groovy.json.JsonSlurper
|
import groovy.json.JsonSlurper
|
||||||
import io.kamax.mxisd.api.ThreePidType
|
|
||||||
import io.kamax.mxisd.lookup.BulkLookupRequest
|
import io.kamax.mxisd.lookup.BulkLookupRequest
|
||||||
import io.kamax.mxisd.lookup.SingleLookupRequest
|
import io.kamax.mxisd.lookup.SingleLookupRequest
|
||||||
import io.kamax.mxisd.lookup.ThreePidMapping
|
import io.kamax.mxisd.lookup.ThreePidMapping
|
||||||
@@ -58,11 +57,9 @@ class MappingController {
|
|||||||
String remote = StringUtils.defaultIfBlank(request.getHeader("X-FORWARDED-FOR"), request.getRemoteAddr())
|
String remote = StringUtils.defaultIfBlank(request.getHeader("X-FORWARDED-FOR"), request.getRemoteAddr())
|
||||||
log.info("Got request from {}", remote)
|
log.info("Got request from {}", remote)
|
||||||
|
|
||||||
ThreePidType type = ThreePidType.valueOf(medium)
|
|
||||||
|
|
||||||
SingleLookupRequest lookupRequest = new SingleLookupRequest()
|
SingleLookupRequest lookupRequest = new SingleLookupRequest()
|
||||||
lookupRequest.setRequester(remote)
|
lookupRequest.setRequester(remote)
|
||||||
lookupRequest.setType(type)
|
lookupRequest.setType(medium)
|
||||||
lookupRequest.setThreePid(address)
|
lookupRequest.setThreePid(address)
|
||||||
|
|
||||||
Optional<?> lookupOpt = strategy.find(lookupRequest)
|
Optional<?> lookupOpt = strategy.find(lookupRequest)
|
||||||
|
|||||||
@@ -20,18 +20,16 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.lookup
|
package io.kamax.mxisd.lookup
|
||||||
|
|
||||||
import io.kamax.mxisd.api.ThreePidType
|
|
||||||
|
|
||||||
class SingleLookupRequest extends ALookupRequest {
|
class SingleLookupRequest extends ALookupRequest {
|
||||||
|
|
||||||
private ThreePidType type
|
private String type
|
||||||
private String threePid
|
private String threePid
|
||||||
|
|
||||||
ThreePidType getType() {
|
String getType() {
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
void setType(ThreePidType type) {
|
void setType(String type) {
|
||||||
this.type = type
|
this.type = type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,4 +74,5 @@ public class ThreePidMapping {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return JsonOutput.toJson(this);
|
return JsonOutput.toJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.lookup.provider
|
package io.kamax.mxisd.lookup.provider
|
||||||
|
|
||||||
import io.kamax.mxisd.api.ThreePidType
|
|
||||||
import io.kamax.mxisd.config.ServerConfig
|
import io.kamax.mxisd.config.ServerConfig
|
||||||
import io.kamax.mxisd.lookup.SingleLookupRequest
|
import io.kamax.mxisd.lookup.SingleLookupRequest
|
||||||
import io.kamax.mxisd.lookup.ThreePidMapping
|
import io.kamax.mxisd.lookup.ThreePidMapping
|
||||||
@@ -112,12 +111,13 @@ class DnsLookupProvider extends RemoteIdentityServerProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
Optional<?> find(SingleLookupRequest request) {
|
Optional<?> find(SingleLookupRequest request) {
|
||||||
log.info("Performing DNS lookup for {}", request.getThreePid())
|
if (!StringUtils.equals("email", request.getType())) { // TODO use enum
|
||||||
if (ThreePidType.email != request.getType()) {
|
|
||||||
log.info("Skipping unsupported type {} for {}", request.getType(), request.getThreePid())
|
log.info("Skipping unsupported type {} for {}", request.getType(), request.getThreePid())
|
||||||
return Optional.empty()
|
return Optional.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info("Performing DNS lookup for {}", request.getThreePid())
|
||||||
|
|
||||||
String domain = request.getThreePid().substring(request.getThreePid().lastIndexOf("@") + 1)
|
String domain = request.getThreePid().substring(request.getThreePid().lastIndexOf("@") + 1)
|
||||||
log.info("Domain name for {}: {}", request.getThreePid(), domain)
|
log.info("Domain name for {}: {}", request.getThreePid(), domain)
|
||||||
Optional<String> baseUrl = findIdentityServerForDomain(domain)
|
Optional<String> baseUrl = findIdentityServerForDomain(domain)
|
||||||
@@ -134,7 +134,7 @@ class DnsLookupProvider extends RemoteIdentityServerProvider {
|
|||||||
Map<String, List<ThreePidMapping>> domains = new HashMap<>()
|
Map<String, List<ThreePidMapping>> domains = new HashMap<>()
|
||||||
|
|
||||||
for (ThreePidMapping mapping : mappings) {
|
for (ThreePidMapping mapping : mappings) {
|
||||||
if (!StringUtils.equals(mapping.getMedium(), ThreePidType.email.toString())) {
|
if (!StringUtils.equals("email", mapping.getMedium())) {
|
||||||
log.info("Skipping unsupported type {} for {}", mapping.getMedium(), mapping.getValue())
|
log.info("Skipping unsupported type {} for {}", mapping.getMedium(), mapping.getValue())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
package io.kamax.mxisd.lookup.provider
|
package io.kamax.mxisd.lookup.provider
|
||||||
|
|
||||||
import io.kamax.mxisd.api.ThreePidType
|
|
||||||
import io.kamax.mxisd.config.LdapConfig
|
import io.kamax.mxisd.config.LdapConfig
|
||||||
import io.kamax.mxisd.config.ServerConfig
|
import io.kamax.mxisd.config.ServerConfig
|
||||||
import io.kamax.mxisd.lookup.SingleLookupRequest
|
import io.kamax.mxisd.lookup.SingleLookupRequest
|
||||||
@@ -61,7 +60,7 @@ class LdapProvider implements ThreePidProvider {
|
|||||||
return 20
|
return 20
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<String> lookup(LdapConnection conn, ThreePidType medium, String value) {
|
Optional<String> lookup(LdapConnection conn, String medium, String value) {
|
||||||
Optional<String> queryOpt = ldapCfg.getMapping(medium)
|
Optional<String> queryOpt = ldapCfg.getMapping(medium)
|
||||||
if (!queryOpt.isPresent()) {
|
if (!queryOpt.isPresent()) {
|
||||||
log.warn("{} is not a supported 3PID type for LDAP lookup", medium)
|
log.warn("{} is not a supported 3PID type for LDAP lookup", medium)
|
||||||
@@ -142,8 +141,7 @@ class LdapProvider implements ThreePidProvider {
|
|||||||
|
|
||||||
for (ThreePidMapping mapping : mappings) {
|
for (ThreePidMapping mapping : mappings) {
|
||||||
try {
|
try {
|
||||||
ThreePidType type = ThreePidType.valueOf(mapping.getMedium())
|
Optional<String> mxid = lookup(conn, mapping.getMedium(), mapping.getValue())
|
||||||
Optional<String> mxid = lookup(conn, type, mapping.getValue())
|
|
||||||
if (mxid.isPresent()) {
|
if (mxid.isPresent()) {
|
||||||
mapping.setMxid(mxid.get())
|
mapping.setMxid(mxid.get())
|
||||||
mappingsFound.add(mapping)
|
mappingsFound.add(mapping)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ package io.kamax.mxisd.lookup.provider
|
|||||||
import groovy.json.JsonException
|
import groovy.json.JsonException
|
||||||
import groovy.json.JsonOutput
|
import groovy.json.JsonOutput
|
||||||
import groovy.json.JsonSlurper
|
import groovy.json.JsonSlurper
|
||||||
import io.kamax.mxisd.api.ThreePidType
|
|
||||||
import io.kamax.mxisd.controller.v1.ClientBulkLookupRequest
|
import io.kamax.mxisd.controller.v1.ClientBulkLookupRequest
|
||||||
import io.kamax.mxisd.lookup.ThreePidMapping
|
import io.kamax.mxisd.lookup.ThreePidMapping
|
||||||
import org.apache.http.HttpEntity
|
import org.apache.http.HttpEntity
|
||||||
@@ -94,7 +93,7 @@ abstract class RemoteIdentityServerProvider implements ThreePidProvider {
|
|||||||
return Optional.empty()
|
return Optional.empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<?> find(String remote, ThreePidType type, String threePid) {
|
Optional<?> find(String remote, String type, String threePid) {
|
||||||
log.info("Looking up {} 3PID {} using {}", type, threePid, remote)
|
log.info("Looking up {} 3PID {} using {}", type, threePid, remote)
|
||||||
|
|
||||||
HttpURLConnection rootSrvConn = (HttpURLConnection) new URL(
|
HttpURLConnection rootSrvConn = (HttpURLConnection) new URL(
|
||||||
|
|||||||
Reference in New Issue
Block a user