use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class PeopleSearchDataReader method doDetailLookup.
private UserSearchResults doDetailLookup(final UserIdentity userIdentity) throws PwmUnrecoverableException {
final List<FormConfiguration> detailFormConfig = pwmRequest.getConfig().readSettingAsForm(PwmSetting.PEOPLE_SEARCH_DETAIL_FORM);
final Map<String, String> attributeHeaderMap = UserSearchResults.fromFormConfiguration(detailFormConfig, pwmRequest.getLocale());
if (peopleSearchConfiguration.isOrgChartEnabled()) {
final String orgChartParentAttr = peopleSearchConfiguration.getOrgChartParentAttr();
if (!attributeHeaderMap.containsKey(orgChartParentAttr)) {
attributeHeaderMap.put(orgChartParentAttr, orgChartParentAttr);
}
final String orgChartChildAttr = peopleSearchConfiguration.getOrgChartParentAttr();
if (!attributeHeaderMap.containsKey(orgChartChildAttr)) {
attributeHeaderMap.put(orgChartChildAttr, orgChartChildAttr);
}
}
try {
final ChaiUser theUser = getChaiUser(userIdentity);
final Map<String, String> values = theUser.readStringAttributes(attributeHeaderMap.keySet());
return new UserSearchResults(attributeHeaderMap, Collections.singletonMap(userIdentity, values), false);
} catch (ChaiException e) {
LOGGER.error("unexpected error during detail lookup of '" + userIdentity + "', error: " + e.getMessage());
throw PwmUnrecoverableException.fromChaiException(e);
}
}
use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class PeopleSearchDataReader method convertResultMapToBeans.
private Map<String, AttributeDetailBean> convertResultMapToBeans(final PwmRequest pwmRequest, final UserIdentity userIdentity, final List<FormConfiguration> detailForm, final Map<String, String> searchResults) throws ChaiUnavailableException, PwmUnrecoverableException {
final Set<String> searchAttributes = getSearchAttributes(pwmRequest.getConfig());
final Map<String, AttributeDetailBean> returnObj = new LinkedHashMap<>();
for (final FormConfiguration formConfiguration : detailForm) {
if (formConfiguration.isRequired() || searchResults.containsKey(formConfiguration.getName())) {
final AttributeDetailBean bean = new AttributeDetailBean();
bean.setName(formConfiguration.getName());
bean.setLabel(formConfiguration.getLabel(pwmRequest.getLocale()));
bean.setType(formConfiguration.getType());
if (searchAttributes.contains(formConfiguration.getName())) {
if (formConfiguration.getType() != FormConfiguration.Type.userDN) {
bean.setSearchable(true);
}
}
if (formConfiguration.getType() == FormConfiguration.Type.userDN) {
if (searchResults.containsKey(formConfiguration.getName())) {
final List<UserIdentity> identityValues = readUserDNAttributeValues(userIdentity, formConfiguration.getName());
final TreeMap<String, UserReferenceBean> userReferences = new TreeMap<>();
for (final UserIdentity loopIdentity : identityValues) {
final String displayValue = figureDisplaynameValue(pwmRequest, loopIdentity);
final UserReferenceBean userReference = new UserReferenceBean();
userReference.setUserKey(loopIdentity.toObfuscatedKey(pwmRequest.getPwmApplication()));
userReference.setDisplayName(displayValue);
userReferences.put(displayValue, userReference);
}
bean.setUserReferences(userReferences.values());
}
} else {
if (formConfiguration.isMultivalue()) {
bean.setValues(readUserMultiAttributeValues(pwmRequest, userIdentity, formConfiguration.getName()));
} else {
if (searchResults.containsKey(formConfiguration.getName())) {
bean.setValues(Collections.singletonList(searchResults.get(formConfiguration.getName())));
} else {
bean.setValues(Collections.<String>emptyList());
}
}
}
returnObj.put(formConfiguration.getName(), bean);
}
}
return returnObj;
}
use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class PeopleSearchDataReader method makeSearchResultsImpl.
private SearchResultBean makeSearchResultsImpl(final PwmRequest pwmRequest, final String username, final boolean includeDisplayName) throws ChaiUnavailableException, PwmUnrecoverableException {
final Instant startTime = Instant.now();
if (username == null || username.length() < 1) {
return new SearchResultBean();
}
final boolean useProxy = useProxy();
final UserSearchEngine userSearchEngine = pwmRequest.getPwmApplication().getUserSearchEngine();
final SearchConfiguration searchConfiguration;
{
final SearchConfiguration.SearchConfigurationBuilder builder = SearchConfiguration.builder();
builder.contexts(pwmRequest.getConfig().readSettingAsStringArray(PwmSetting.PEOPLE_SEARCH_SEARCH_BASE));
builder.enableContextValidation(false);
builder.username(username);
builder.enableValueEscaping(false);
builder.filter(getSearchFilter(pwmRequest.getConfig()));
builder.enableSplitWhitespace(true);
if (!useProxy) {
builder.ldapProfile(pwmRequest.getPwmSession().getUserInfo().getUserIdentity().getLdapProfileID());
builder.chaiProvider(pwmRequest.getPwmSession().getSessionManager().getChaiProvider());
}
searchConfiguration = builder.build();
}
final UserSearchResults results;
final boolean sizeExceeded;
try {
final List<FormConfiguration> searchForm = pwmRequest.getConfig().readSettingAsForm(PwmSetting.PEOPLE_SEARCH_RESULT_FORM);
final int maxResults = (int) pwmRequest.getConfig().readSettingAsLong(PwmSetting.PEOPLE_SEARCH_RESULT_LIMIT);
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.getSessionLabel(), errorInformation.toDebugStr());
throw new PwmUnrecoverableException(errorInformation);
}
final List<Map<String, Object>> resultOutput = new ArrayList<>(results.resultsAsJsonOutput(pwmRequest.getPwmApplication(), null));
if (includeDisplayName) {
for (final Map<String, Object> map : resultOutput) {
final String userKey = (String) map.get("userKey");
if (userKey != null) {
final UserIdentity userIdentity = UserIdentity.fromKey(userKey, pwmRequest.getPwmApplication());
final String displayValue = figureDisplaynameValue(pwmRequest, userIdentity);
map.put("_displayName", displayValue);
}
}
}
final TimeDuration searchDuration = TimeDuration.fromCurrent(startTime);
LOGGER.trace(pwmRequest.getPwmSession(), "finished rest peoplesearch search in " + searchDuration.asCompactString() + " not using cache, size=" + results.getResults().size());
final SearchResultBean searchResultBean = new SearchResultBean();
searchResultBean.setSearchResults(resultOutput);
searchResultBean.setSizeExceeded(sizeExceeded);
final String aboutMessage = LocaleHelper.getLocalizedMessage(pwmRequest.getLocale(), Display.Display_SearchResultsInfo.getKey(), pwmRequest.getConfig(), Display.class, new String[] { String.valueOf(results.getResults().size()), searchDuration.asLongString(pwmRequest.getLocale()) });
searchResultBean.setAboutResultMessage(aboutMessage);
return searchResultBean;
}
use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class UpdateProfileUtil method formMapFromBean.
static Map<FormConfiguration, String> formMapFromBean(final UpdateProfileProfile updateProfileProfile, final UpdateProfileBean updateProfileBean) throws PwmUnrecoverableException {
final List<FormConfiguration> form = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
final Map<FormConfiguration, String> formValueMap = new LinkedHashMap<>();
for (final FormConfiguration formConfiguration : form) {
formValueMap.put(formConfiguration, updateProfileBean.getFormData().keySet().contains(formConfiguration.getName()) ? updateProfileBean.getFormData().get(formConfiguration.getName()) : "");
}
return formValueMap;
}
use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.
the class UpdateProfileUtil method determineTokenValidationsRequired.
static Map<String, TokenDestinationItem.Type> determineTokenValidationsRequired(final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean, final UpdateProfileProfile updateProfileProfile) throws PwmUnrecoverableException {
final List<FormConfiguration> formFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
final LdapProfile ldapProfile = pwmRequest.getUserInfoIfLoggedIn().getLdapProfile(pwmRequest.getConfig());
final Map<String, TokenDestinationItem.Type> workingMap = new LinkedHashMap<>(FormUtility.identifyFormItemsNeedingPotentialTokenValidation(ldapProfile, formFields));
final Set<TokenDestinationItem.Type> interestedTypes = new HashSet<>();
if (updateProfileProfile.readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_EMAIL_VERIFICATION)) {
interestedTypes.add(TokenDestinationItem.Type.email);
}
if (updateProfileProfile.readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_SMS_VERIFICATION)) {
interestedTypes.add(TokenDestinationItem.Type.sms);
}
if (!JavaHelper.isEmpty(workingMap)) {
final Map<String, String> ldapData = formDataFromLdap(pwmRequest, updateProfileProfile);
final Map<String, String> updateData = updateProfileBean.getFormData();
for (final Iterator<Map.Entry<String, TokenDestinationItem.Type>> iter = workingMap.entrySet().iterator(); iter.hasNext(); ) {
final Map.Entry<String, TokenDestinationItem.Type> entry = iter.next();
final String attrName = entry.getKey();
final TokenDestinationItem.Type type = entry.getValue();
if (!interestedTypes.contains(type)) {
iter.remove();
} else if (updateData.containsKey(attrName)) {
final String updateValue = updateData.get(attrName);
final String ldapValue = ldapData.get(attrName);
if (StringUtil.nullSafeEqualsIgnoreCase(updateValue, ldapValue)) {
iter.remove();
}
}
}
}
return Collections.unmodifiableMap(workingMap);
}
Aggregations