Search in sources :

Example 1 with io.kamax.matrix._ThreePid

use of io.kamax.matrix._ThreePid in project mxisd by kamax-io.

the class ProfileController method getProfile.

@RequestMapping("/{userId:.+}")
public String getProfile(HttpServletRequest req, HttpServletResponse res, @PathVariable String userId) {
    try (CloseableHttpResponse hsResponse = client.execute(new HttpGet(resolveProxyUrl(req)))) {
        res.setStatus(hsResponse.getStatusLine().getStatusCode());
        JsonElement el = parser.parse(EntityUtils.toString(hsResponse.getEntity()));
        List<_ThreePid> list = mgr.getThreepids(MatrixID.asAcceptable(userId));
        if (!list.isEmpty() && el.isJsonObject()) {
            JsonObject obj = el.getAsJsonObject();
            obj.add("threepids", GsonUtil.build().toJsonTree(list));
        }
        return gson.toJson(el);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : JsonElement(com.google.gson.JsonElement) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) JsonObject(com.google.gson.JsonObject) io.kamax.matrix._ThreePid(io.kamax.matrix._ThreePid) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with io.kamax.matrix._ThreePid

use of io.kamax.matrix._ThreePid 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();
}
Also used : BackendAuthResult(io.kamax.mxisd.auth.provider.BackendAuthResult) ThreePidMapping(io.kamax.mxisd.lookup.ThreePidMapping) AuthenticatorProvider(io.kamax.mxisd.auth.provider.AuthenticatorProvider) io.kamax.matrix._ThreePid(io.kamax.matrix._ThreePid) ThreePid(io.kamax.matrix.ThreePid) io.kamax.matrix._ThreePid(io.kamax.matrix._ThreePid) io.kamax.matrix._MatrixID(io.kamax.matrix._MatrixID)

Example 3 with io.kamax.matrix._ThreePid

use of io.kamax.matrix._ThreePid in project mxisd by kamax-io.

the class SqlThreePidProvider method getThreepids.

@Override
public List<_ThreePid> getThreepids(_MatrixID mxid) {
    List<_ThreePid> threepids = new ArrayList<>();
    String stmtSql = cfg.getProfile().getThreepid().getQuery();
    try (Connection conn = pool.get()) {
        PreparedStatement stmt = conn.prepareStatement(stmtSql);
        stmt.setString(1, mxid.getId());
        ResultSet rSet = stmt.executeQuery();
        while (rSet.next()) {
            String medium = rSet.getString("medium");
            String address = rSet.getString("address");
            threepids.add(new ThreePid(medium, address));
        }
        return threepids;
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) io.kamax.matrix._ThreePid(io.kamax.matrix._ThreePid) PreparedStatement(java.sql.PreparedStatement) ThreePid(io.kamax.matrix.ThreePid) io.kamax.matrix._ThreePid(io.kamax.matrix._ThreePid)

Aggregations

io.kamax.matrix._ThreePid (io.kamax.matrix._ThreePid)3 ThreePid (io.kamax.matrix.ThreePid)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 io.kamax.matrix._MatrixID (io.kamax.matrix._MatrixID)1 AuthenticatorProvider (io.kamax.mxisd.auth.provider.AuthenticatorProvider)1 BackendAuthResult (io.kamax.mxisd.auth.provider.BackendAuthResult)1 ThreePidMapping (io.kamax.mxisd.lookup.ThreePidMapping)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1