use of io.kamax.mxisd.lookup.ThreePidMapping in project mxisd by kamax-io.
the class ClientBulkLookupRequest method setMappings.
public void setMappings(List<ThreePidMapping> mappings) {
for (ThreePidMapping mapping : mappings) {
List<String> threepid = new ArrayList<>();
threepid.add(mapping.getMedium());
threepid.add(mapping.getValue());
threepids.add(threepid);
}
}
use of io.kamax.mxisd.lookup.ThreePidMapping in project mxisd by kamax-io.
the class LdapThreePidProvider method populate.
@Override
public List<ThreePidMapping> populate(List<ThreePidMapping> mappings) {
log.info("Looking up {} mappings", mappings.size());
List<ThreePidMapping> mappingsFound = new ArrayList<>();
try (LdapConnection conn = getConn()) {
bind(conn);
for (ThreePidMapping mapping : mappings) {
try {
lookup(conn, mapping.getMedium(), mapping.getValue()).ifPresent(id -> {
mapping.setMxid(id);
mappingsFound.add(mapping);
});
} catch (IllegalArgumentException e) {
log.warn("{} is not a supported 3PID type for LDAP lookup", mapping.getMedium());
}
}
} catch (LdapException | IOException e) {
throw new InternalServerError(e);
}
return mappingsFound;
}
use of io.kamax.mxisd.lookup.ThreePidMapping in project mxisd by kamax-io.
the class RestThreePidProvider method populate.
// TODO refactor common code
@Override
public List<ThreePidMapping> populate(List<ThreePidMapping> mappings) {
List<LookupSingleRequestJson> ioListRequest = mappings.stream().map(mapping -> new LookupSingleRequestJson(mapping.getMedium(), mapping.getValue())).collect(Collectors.toList());
HttpUriRequest req = RestClientUtils.post(cfg.getEndpoints().getIdentity().getBulk(), gson, "lookup", ioListRequest);
try (CloseableHttpResponse res = client.execute(req)) {
mappings = new ArrayList<>();
int status = res.getStatusLine().getStatusCode();
if (status < 200 || status >= 300) {
return mappings;
}
LookupBulkResponseJson listIo = parser.parse(res, LookupBulkResponseJson.class);
return listIo.getLookup().stream().map(io -> new ThreePidMapping(io.getMedium(), io.getAddress(), getMxId(io.getId()).getId())).collect(Collectors.toList());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of io.kamax.mxisd.lookup.ThreePidMapping in project mxisd by kamax-io.
the class RestThreePidProviderTest method before.
@Before
public void before() {
MatrixConfig mxCfg = new MatrixConfig();
mxCfg.setDomain("example.org");
mxCfg.build();
RestBackendConfig cfg = new RestBackendConfig();
cfg.setEnabled(true);
cfg.setHost("http://localhost:65000");
cfg.getEndpoints().getIdentity().setSingle(lookupSinglePath);
cfg.getEndpoints().getIdentity().setBulk(lookupBulkPath);
cfg.build();
p = new RestThreePidProvider(cfg, mxCfg);
lookupSingleRequest = new SingleLookupRequest();
lookupSingleRequest.setType(ThreePidMedium.Email.getId());
lookupSingleRequest.setThreePid("john.doe@example.org");
ThreePidMapping m1 = new ThreePidMapping();
m1.setMedium(ThreePidMedium.Email.getId());
m1.setValue("john.doe@example.org");
ThreePidMapping m2 = new ThreePidMapping();
m1.setMedium(ThreePidMedium.PhoneNumber.getId());
m1.setValue("123456789");
lookupBulkList = new ArrayList<>();
lookupBulkList.add(m1);
lookupBulkList.add(m2);
}
use of io.kamax.mxisd.lookup.ThreePidMapping in project mxisd by kamax-io.
the class AuthManager method authenticate.
public UserAuthResult authenticate(String id, String password) {
_MatrixID mxid = MatrixID.asAcceptable(id);
for (AuthenticatorProvider provider : providers) {
if (!provider.isEnabled()) {
continue;
}
BackendAuthResult result = provider.authenticate(mxid, password);
if (result.isSuccess()) {
String mxId;
if (UserIdType.Localpart.is(result.getId().getType())) {
mxId = MatrixID.from(result.getId().getValue(), mxCfg.getDomain()).acceptable().getId();
} else if (UserIdType.MatrixID.is(result.getId().getType())) {
mxId = MatrixID.asAcceptable(result.getId().getValue()).getId();
} else {
log.warn("Unsupported User ID type {} for backend {}", result.getId().getType(), provider.getClass().getSimpleName());
continue;
}
UserAuthResult authResult = new UserAuthResult().success(result.getProfile().getDisplayName());
for (_ThreePid pid : result.getProfile().getThreePids()) {
authResult.withThreePid(pid.getMedium(), pid.getAddress());
}
log.info("{} was authenticated by {}, publishing 3PID mappings, if any", id, provider.getClass().getSimpleName());
for (ThreePid pid : authResult.getThreePids()) {
log.info("Processing {} for {}", pid, id);
invMgr.publishMappingIfInvited(new ThreePidMapping(pid, mxId));
}
invMgr.lookupMappingsForInvites();
return authResult;
}
}
return new UserAuthResult().failure();
}
Aggregations