use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class ExecDirectoryStore method search.
private UserDirectorySearchResult search(ExecConfig.Process cfg, UserDirectorySearchRequest request) {
if (StringUtils.isEmpty(cfg.getCommand())) {
return UserDirectorySearchResult.empty();
}
Processor<UserDirectorySearchResult> p = new Processor<>(cfg);
p.addJsonInputTemplate(tokens -> new UserDirectorySearchRequest(tokens.getType(), tokens.getQuery()));
p.addInputTemplate(PlainType, tokens -> tokens.getType() + System.lineSeparator() + tokens.getQuery());
p.addTokenMapper(cfg.getToken().getType(), request::getBy);
p.addTokenMapper(cfg.getToken().getQuery(), request::getSearchTerm);
p.addSuccessMapper(JsonType, output -> {
if (StringUtils.isBlank(output)) {
return UserDirectorySearchResult.empty();
}
UserDirectorySearchResult response = GsonUtil.get().fromJson(output, UserDirectorySearchResult.class);
for (UserDirectorySearchResult.Result result : response.getResults()) {
result.setUserId(MatrixID.asAcceptable(result.getUserId(), mxCfg.getDomain()).getId());
}
return response;
});
p.withFailureDefault(output -> new UserDirectorySearchResult());
return p.execute();
}
use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class LdapDirectoryProvider method search.
protected UserDirectorySearchResult search(String query, List<String> attributes) {
UserDirectorySearchResult result = new UserDirectorySearchResult();
result.setLimited(false);
try (LdapConnection conn = getConn()) {
bind(conn);
LdapConfig.Attribute atCfg = getCfg().getAttribute();
attributes = new ArrayList<>(attributes);
attributes.add(getUidAtt());
String[] attArray = new String[attributes.size()];
attributes.toArray(attArray);
String searchQuery = buildOrQueryWithFilter(getCfg().getDirectory().getFilter(), "*" + query + "*", attArray);
log.debug("Query: {}", searchQuery);
log.debug("Attributes: {}", GsonUtil.build().toJson(attArray));
for (String baseDN : getBaseDNs()) {
log.debug("Base DN: {}", baseDN);
try (EntryCursor cursor = conn.search(baseDN, searchQuery, SearchScope.SUBTREE, attArray)) {
while (cursor.next()) {
Entry entry = cursor.get();
log.info("Found possible match, DN: {}", entry.getDn().getName());
getAttribute(entry, getUidAtt()).ifPresent(uid -> {
log.info("DN {} is a valid match", entry.getDn().getName());
try {
UserDirectorySearchResult.Result entryResult = new UserDirectorySearchResult.Result();
entryResult.setUserId(buildMatrixIdFromUid(uid));
getAttribute(entry, atCfg.getName()).ifPresent(entryResult::setDisplayName);
result.addResult(entryResult);
} catch (IllegalArgumentException e) {
log.warn("Bind was found but type {} is not supported", atCfg.getUid().getType());
}
});
}
}
}
} catch (CursorLdapReferralException e) {
log.warn("An entry is only available via referral, skipping");
} catch (IOException | LdapException | CursorException e) {
throw new InternalServerError(e);
}
return result;
}
use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class ExecDirectoryStoreTest method byNameNoCommandDefined.
@Test
public void byNameNoCommandDefined() {
ExecConfig cfg = getCfg();
assertTrue(StringUtils.isEmpty(cfg.getDirectory().getSearch().getByName().getCommand()));
ExecDirectoryStore store = getStore(cfg);
UserDirectorySearchResult result = store.searchByDisplayName("user");
assertFalse(result.isLimited());
assertTrue(result.getResults().isEmpty());
}
use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class ExecDirectoryStoreTest method byNameFailureNoOutput.
@Test
public void byNameFailureNoOutput() {
UserDirectorySearchResult result = getStore(fno).searchByDisplayName("user");
assertFalse(result.isLimited());
assertTrue(result.getResults().isEmpty());
}
use of io.kamax.mxisd.http.io.UserDirectorySearchResult in project mxisd by kamax-io.
the class ExecDirectoryStoreTest method byNameSuccessSingleResult.
@Test
public void byNameSuccessSingleResult() {
UserDirectorySearchResult output = getStore("byNameSuccessSingleResult").searchByDisplayName("user");
assertFalse(output.isLimited());
assertEquals(1, output.getResults().size());
UserDirectorySearchResult.Result result = output.getResults().iterator().next();
assertEquals(MatrixID.from(user1Localpart, domain).acceptable().getId(), result.getUserId());
assertEquals(user1Name, result.getDisplayName());
}
Aggregations