Search in sources :

Example 6 with SingleLookupRequest

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);
    }
}
Also used : SingleLookupRequest(io.kamax.mxisd.lookup.SingleLookupRequest) SingleLookupReply(io.kamax.mxisd.lookup.SingleLookupReply) SingeLookupReplyJson(io.kamax.mxisd.http.io.identity.SingeLookupReplyJson) JsonObject(com.google.gson.JsonObject)

Example 7 with SingleLookupRequest

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());
}
Also used : SingleLookupRequest(io.kamax.mxisd.lookup.SingleLookupRequest) SingleLookupReply(io.kamax.mxisd.lookup.SingleLookupReply) ExecIdentityStore(io.kamax.mxisd.backend.exec.ExecIdentityStore) Test(org.junit.Test)

Example 8 with SingleLookupRequest

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);
}
Also used : SingleLookupRequest(io.kamax.mxisd.lookup.SingleLookupRequest) Test(org.junit.Test)

Example 9 with SingleLookupRequest

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);
}
Also used : ThreePidMapping(io.kamax.mxisd.lookup.ThreePidMapping) MatrixConfig(io.kamax.mxisd.config.MatrixConfig) SingleLookupRequest(io.kamax.mxisd.lookup.SingleLookupRequest) RestBackendConfig(io.kamax.mxisd.config.rest.RestBackendConfig) RestThreePidProvider(io.kamax.mxisd.backend.rest.RestThreePidProvider) Before(org.junit.Before)

Example 10 with SingleLookupRequest

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);
}
Also used : SingleLookupRequest(io.kamax.mxisd.lookup.SingleLookupRequest) SingleLookupReply(io.kamax.mxisd.lookup.SingleLookupReply) NotAllowedException(io.kamax.mxisd.exception.NotAllowedException) ThreePidSession(io.kamax.mxisd.threepid.session.ThreePidSession) io.kamax.matrix._MatrixID(io.kamax.matrix._MatrixID)

Aggregations

SingleLookupRequest (io.kamax.mxisd.lookup.SingleLookupRequest)10 SingleLookupReply (io.kamax.mxisd.lookup.SingleLookupReply)7 Test (org.junit.Test)5 MatrixConfig (io.kamax.mxisd.config.MatrixConfig)3 ThreePidMapping (io.kamax.mxisd.lookup.ThreePidMapping)3 io.kamax.matrix._MatrixID (io.kamax.matrix._MatrixID)2 ExecIdentityStore (io.kamax.mxisd.backend.exec.ExecIdentityStore)2 RestBackendConfig (io.kamax.mxisd.config.rest.RestBackendConfig)2 Before (org.junit.Before)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 MatrixID (io.kamax.matrix.MatrixID)1 ThreePid (io.kamax.matrix.ThreePid)1 GsonUtil (io.kamax.matrix.json.GsonUtil)1 UserID (io.kamax.mxisd.UserID)1 UserIdType (io.kamax.mxisd.UserIdType)1 LookupBulkResponseJson (io.kamax.mxisd.backend.rest.LookupBulkResponseJson)1 LookupSingleResponseJson (io.kamax.mxisd.backend.rest.LookupSingleResponseJson)1 RestThreePidProvider (io.kamax.mxisd.backend.rest.RestThreePidProvider)1