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