use of password.pwm.ldap.search.UserSearchEngine in project pwm by pwm-project.
the class LdapOperationsHelper method readAllUsersFromLdap.
public static Iterator<UserIdentity> readAllUsersFromLdap(final PwmApplication pwmApplication, final SessionLabel sessionLabel, final String searchFilter, final int maxResults) throws ChaiUnavailableException, ChaiOperationException, PwmUnrecoverableException, PwmOperationalException {
final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
final SearchConfiguration searchConfiguration;
{
final SearchConfiguration.SearchConfigurationBuilder builder = SearchConfiguration.builder();
builder.enableValueEscaping(false);
builder.searchTimeout(Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.REPORTING_LDAP_SEARCH_TIMEOUT)));
if (searchFilter == null) {
builder.username("*");
} else {
builder.filter(searchFilter);
}
searchConfiguration = builder.build();
}
LOGGER.debug(sessionLabel, "beginning user search using parameters: " + (JsonUtil.serialize(searchConfiguration)));
final Map<UserIdentity, Map<String, String>> searchResults = userSearchEngine.performMultiUserSearch(searchConfiguration, maxResults, Collections.emptyList(), sessionLabel);
LOGGER.debug(sessionLabel, "user search found " + searchResults.size() + " users");
final Queue<UserIdentity> tempQueue = new LinkedList<>(searchResults.keySet());
return new Iterator<UserIdentity>() {
@Override
public boolean hasNext() {
return tempQueue.peek() != null;
}
@Override
public UserIdentity next() {
return tempQueue.poll();
}
};
}
use of password.pwm.ldap.search.UserSearchEngine in project pwm by pwm-project.
the class SessionAuthenticator method authUserWithUnknownPassword.
public void authUserWithUnknownPassword(final String username, final AuthenticationType requestedAuthType) throws ImpossiblePasswordPolicyException, PwmUnrecoverableException, PwmOperationalException {
pwmApplication.getIntruderManager().check(RecordType.USERNAME, username);
UserIdentity userIdentity = null;
try {
final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
userIdentity = userSearchEngine.resolveUsername(username, null, null, sessionLabel);
final AuthenticationRequest authEngine = LDAPAuthenticationRequest.createLDAPAuthenticationRequest(pwmApplication, sessionLabel, userIdentity, requestedAuthType, authenticationSource);
final AuthenticationResult authResult = authEngine.authUsingUnknownPw();
postAuthenticationSequence(userIdentity, authResult);
} catch (ChaiUnavailableException e) {
throw PwmUnrecoverableException.fromChaiException(e);
} catch (PwmOperationalException e) {
postFailureSequence(e, username, userIdentity);
throw e;
}
}
use of password.pwm.ldap.search.UserSearchEngine in project pwm by pwm-project.
the class SessionAuthenticator method searchAndAuthenticateUser.
public void searchAndAuthenticateUser(final String username, final PasswordData password, final String context, final String ldapProfile) throws ChaiUnavailableException, PwmUnrecoverableException, PwmOperationalException {
pwmApplication.getIntruderManager().check(RecordType.USERNAME, username);
UserIdentity userIdentity = null;
try {
final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
userIdentity = userSearchEngine.resolveUsername(username, context, ldapProfile, sessionLabel);
final AuthenticationRequest authEngine = LDAPAuthenticationRequest.createLDAPAuthenticationRequest(pwmApplication, sessionLabel, userIdentity, AuthenticationType.AUTHENTICATED, authenticationSource);
final AuthenticationResult authResult = authEngine.authenticateUser(password);
postAuthenticationSequence(userIdentity, authResult);
} catch (PwmOperationalException e) {
postFailureSequence(e, username, userIdentity);
if (readHiddenErrorTypes().contains(e.getError())) {
if (pwmApplication.determineIfDetailErrorMsgShown()) {
LOGGER.debug(pwmSession, "allowing error " + e.getError() + " to be returned though it is configured as a hidden type; " + "app is currently permitting detailed error messages");
} else {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_WRONGPASSWORD);
LOGGER.debug(pwmSession, "converting error from ldap " + e.getError() + " to " + PwmError.ERROR_WRONGPASSWORD + " due to app property " + AppProperty.SECURITY_LOGIN_HIDDEN_ERROR_TYPES.getKey());
throw new PwmOperationalException(errorInformation);
}
}
throw e;
}
}
use of password.pwm.ldap.search.UserSearchEngine in project pwm by pwm-project.
the class ResponseStatsCommand method readAllUsersFromLdap.
private static List<UserIdentity> readAllUsersFromLdap(final PwmApplication pwmApplication) throws ChaiUnavailableException, ChaiOperationException, PwmUnrecoverableException, PwmOperationalException {
final List<UserIdentity> returnList = new ArrayList<>();
for (final LdapProfile ldapProfile : pwmApplication.getConfig().getLdapProfiles().values()) {
final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
final SearchConfiguration searchConfiguration = SearchConfiguration.builder().enableValueEscaping(false).searchTimeout(Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.REPORTING_LDAP_SEARCH_TIMEOUT))).username("*").enableValueEscaping(false).filter(ldapProfile.readSettingAsString(PwmSetting.LDAP_USERNAME_SEARCH_FILTER)).ldapProfile(ldapProfile.getIdentifier()).build();
final Map<UserIdentity, Map<String, String>> searchResults = userSearchEngine.performMultiUserSearch(searchConfiguration, Integer.MAX_VALUE, Collections.emptyList(), SessionLabel.SYSTEM_LABEL);
returnList.addAll(searchResults.keySet());
}
return returnList;
}
use of password.pwm.ldap.search.UserSearchEngine in project pwm by pwm-project.
the class HelpdeskServlet method restSearchRequest.
@ActionHandler(action = "search")
private ProcessStatus restSearchRequest(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
final HelpdeskProfile helpdeskProfile = getHelpdeskProfile(pwmRequest);
final Map<String, String> valueMap = pwmRequest.readBodyAsJsonStringMap();
final String username = valueMap.get("username");
final boolean useProxy = helpdeskProfile.readSettingAsBoolean(PwmSetting.HELPDESK_USE_PROXY);
final List<FormConfiguration> searchForm = helpdeskProfile.readSettingAsForm(PwmSetting.HELPDESK_SEARCH_FORM);
final int maxResults = (int) helpdeskProfile.readSettingAsLong(PwmSetting.HELPDESK_RESULT_LIMIT);
if (username == null || username.isEmpty()) {
final HelpdeskSearchResultsBean emptyResults = new HelpdeskSearchResultsBean();
emptyResults.setSearchResults(new ArrayList<>());
emptyResults.setSizeExceeded(false);
final RestResultBean restResultBean = RestResultBean.withData(emptyResults);
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
final UserSearchEngine userSearchEngine = pwmRequest.getPwmApplication().getUserSearchEngine();
final SearchConfiguration searchConfiguration;
{
final SearchConfiguration.SearchConfigurationBuilder builder = SearchConfiguration.builder();
builder.contexts(helpdeskProfile.readSettingAsStringArray(PwmSetting.HELPDESK_SEARCH_BASE));
builder.enableContextValidation(false);
builder.username(username);
builder.enableValueEscaping(false);
builder.filter(HelpdeskServletUtil.getSearchFilter(pwmRequest.getConfig(), helpdeskProfile));
builder.enableSplitWhitespace(true);
if (!useProxy) {
final UserIdentity loggedInUser = pwmRequest.getPwmSession().getUserInfo().getUserIdentity();
builder.ldapProfile(loggedInUser.getLdapProfileID());
builder.chaiProvider(getChaiUser(pwmRequest, helpdeskProfile, loggedInUser).getChaiProvider());
}
searchConfiguration = builder.build();
}
final UserSearchResults results;
final boolean sizeExceeded;
try {
final Locale locale = pwmRequest.getLocale();
results = userSearchEngine.performMultiUserSearchFromForm(locale, searchConfiguration, maxResults, searchForm, pwmRequest.getSessionLabel());
sizeExceeded = results.isSizeExceeded();
} catch (PwmOperationalException e) {
final ErrorInformation errorInformation = e.getErrorInformation();
LOGGER.error(pwmRequest, errorInformation);
final RestResultBean restResultBean = RestResultBean.fromError(errorInformation, pwmRequest);
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
final HelpdeskSearchResultsBean outputData = new HelpdeskSearchResultsBean();
outputData.setSearchResults(results.resultsAsJsonOutput(pwmRequest.getPwmApplication(), pwmRequest.getUserInfoIfLoggedIn()));
outputData.setSizeExceeded(sizeExceeded);
final RestResultBean restResultBean = RestResultBean.withData(outputData);
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
Aggregations