use of io.kamax.mxisd.lookup.SingleLookupRequest in project mxisd by kamax-io.
the class SingleLookupHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) {
String medium = getQueryParameter(exchange, "medium");
String address = getQueryParameter(exchange, "address");
SingleLookupRequest lookupRequest = new SingleLookupRequest();
setRequesterInfo(lookupRequest, exchange);
lookupRequest.setType(medium);
lookupRequest.setThreePid(address);
log.info("Got single lookup request from {} with client {} - Is recursive? {}", lookupRequest.getRequester(), lookupRequest.getUserAgent(), lookupRequest.isRecursive());
Optional<SingleLookupReply> lookupOpt = strategy.find(lookupRequest);
if (!lookupOpt.isPresent()) {
log.info("No mapping was found, return empty JSON object");
respondJson(exchange, "{}");
} else {
SingleLookupReply lookup = lookupOpt.get();
JsonObject obj = GsonUtil.makeObj(new SingeLookupReplyJson(lookup));
signMgr.signMessageGson(cfg.getName(), obj);
respondJson(exchange, obj);
}
}
use of io.kamax.mxisd.lookup.SingleLookupRequest in project mxisd by kamax-io.
the class ExecIdentityStoreTest method singleSuccessNoOutput.
@Test
public void singleSuccessNoOutput() {
ExecIdentityStore store = getStore(sno);
SingleLookupRequest req = new SingleLookupRequest();
req.setType(ThreePidMedium.Email.getId());
req.setThreePid(user1Email);
Optional<SingleLookupReply> lookup = store.find(req);
assertFalse(lookup.isPresent());
}
use of io.kamax.mxisd.lookup.SingleLookupRequest in project mxisd by kamax-io.
the class ExecIdentityStoreTest method singleSuccessEmptyFromInvalidOutput.
@Test(expected = InternalServerError.class)
public void singleSuccessEmptyFromInvalidOutput() {
SingleLookupRequest req = new SingleLookupRequest();
req.setType(ThreePidMedium.Email.getId());
req.setThreePid(user1Email);
getStore("singleSuccessEmptyFromInvalidOutput").find(req);
}
use of io.kamax.mxisd.lookup.SingleLookupRequest 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.SingleLookupRequest in project mxisd by kamax-io.
the class SessionManager method bind.
public SingleLookupReply bind(String sid, String secret, String mxidRaw) {
// We make sure we have an acceptable User ID
if (StringUtils.isEmpty(mxidRaw)) {
throw new IllegalArgumentException("No Matrix User ID provided");
}
// We ensure the session was validated
ThreePidSession session = getSessionIfValidated(sid, secret);
// We parse the Matrix ID as acceptable
_MatrixID mxid = MatrixID.asAcceptable(mxidRaw);
// Only accept binds if the domain matches our own
if (!StringUtils.equalsIgnoreCase(mxCfg.getDomain(), mxid.getDomain())) {
throw new NotAllowedException("Only Matrix IDs from domain " + mxCfg.getDomain() + " can be bound");
}
log.info("Session {}: Binding of {}:{} to Matrix ID {} is accepted", session.getId(), session.getThreePid().getMedium(), session.getThreePid().getAddress(), mxid.getId());
SingleLookupRequest request = new SingleLookupRequest();
request.setType(session.getThreePid().getMedium());
request.setThreePid(session.getThreePid().getAddress());
return new SingleLookupReply(request, mxid);
}
Aggregations