Search in sources :

Example 11 with UserDirectorySearchResult

use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.

the class RestDirectoryProviderTest method byNameNotFound.

@Test
public void byNameNotFound() {
    stubFor(post(urlEqualTo(endpoint)).willReturn(aResponse().withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType()).withBody(byNameEmptyResponse)));
    UserDirectorySearchResult result = p.searchByDisplayName(byNameSearch);
    assertTrue(!result.isLimited());
    assertTrue(result.getResults().isEmpty());
    verify(postRequestedFor(urlMatching(endpoint)).withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType())).withRequestBody(equalTo(byNameRequest)));
}
Also used : UserDirectorySearchResult(io.kamax.mxisd.http.io.UserDirectorySearchResult) Test(org.junit.Test)

Example 12 with UserDirectorySearchResult

use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.

the class ExecDirectoryStoreTest method byNameSuccessEmptyResult.

@Test
public void byNameSuccessEmptyResult() {
    UserDirectorySearchResult output = getStore("byNameSuccessEmptyResult").searchByDisplayName("user");
    assertFalse(output.isLimited());
    assertTrue(output.getResults().isEmpty());
}
Also used : UserDirectorySearchResult(io.kamax.mxisd.http.io.UserDirectorySearchResult) Test(org.junit.Test)

Example 13 with UserDirectorySearchResult

use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.

the class RestDirectoryProviderTest method byThreepidNotFound.

@Test
public void byThreepidNotFound() {
    stubFor(post(urlEqualTo(endpoint)).willReturn(aResponse().withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType()).withBody(byThreepidEmptyResponse)));
    UserDirectorySearchResult result = p.searchBy3pid(byThreepidSearch);
    assertTrue(!result.isLimited());
    assertTrue(result.getResults().isEmpty());
    verify(postRequestedFor(urlMatching(endpoint)).withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType())).withRequestBody(equalTo(byThreepidRequest)));
}
Also used : UserDirectorySearchResult(io.kamax.mxisd.http.io.UserDirectorySearchResult) Test(org.junit.Test)

Example 14 with UserDirectorySearchResult

use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.

the class RestDirectoryProvider method search.

private UserDirectorySearchResult search(String by, String query) {
    UserDirectorySearchRequest request = new UserDirectorySearchRequest(query);
    request.setBy(by);
    try (CloseableHttpResponse httpResponse = client.execute(RestClientUtils.post(cfg.getEndpoints().getDirectory(), request))) {
        int status = httpResponse.getStatusLine().getStatusCode();
        if (status < 200 || status >= 300) {
            throw new InternalServerError("REST backend: Error: " + IOUtils.toString(httpResponse.getEntity().getContent(), StandardCharsets.UTF_8));
        }
        UserDirectorySearchResult response = parser.parse(httpResponse, UserDirectorySearchResult.class);
        for (UserDirectorySearchResult.Result result : response.getResults()) {
            result.setUserId(MatrixID.asAcceptable(result.getUserId(), mxCfg.getDomain()).getId());
        }
        return response;
    } catch (IOException e) {
        throw new InternalServerError("REST backend: I/O error: " + e.getMessage());
    }
}
Also used : UserDirectorySearchRequest(io.kamax.mxisd.http.io.UserDirectorySearchRequest) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) InternalServerError(io.kamax.mxisd.exception.InternalServerError) UserDirectorySearchResult(io.kamax.mxisd.http.io.UserDirectorySearchResult)

Example 15 with UserDirectorySearchResult

use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.

the class MemoryIdentityStore method search.

private UserDirectorySearchResult search(Predicate<MemoryIdentityConfig> predicate, Function<MemoryIdentityConfig, UserDirectorySearchResult.Result> mapper) {
    UserDirectorySearchResult search = new UserDirectorySearchResult();
    cfg.getIdentities().stream().filter(predicate).map(mapper).forEach(search::addResult);
    return search;
}
Also used : UserDirectorySearchResult(io.kamax.mxisd.http.io.UserDirectorySearchResult)

Aggregations

UserDirectorySearchResult (io.kamax.mxisd.http.io.UserDirectorySearchResult)17 Test (org.junit.Test)9 InternalServerError (io.kamax.mxisd.exception.InternalServerError)5 UserDirectorySearchRequest (io.kamax.mxisd.http.io.UserDirectorySearchRequest)4 IOException (java.io.IOException)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 MatrixErrorInfo (io.kamax.matrix.MatrixErrorInfo)1 ExecDirectoryStore (io.kamax.mxisd.backend.exec.ExecDirectoryStore)1 ExecConfig (io.kamax.mxisd.config.ExecConfig)1 LdapConfig (io.kamax.mxisd.config.ldap.LdapConfig)1 HttpMatrixException (io.kamax.mxisd.exception.HttpMatrixException)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 CursorLdapReferralException (org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException)1