Search in sources :

Example 31 with FormConfiguration

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);
    }
}
Also used : ChaiUser(com.novell.ldapchai.ChaiUser) UserSearchResults(password.pwm.ldap.search.UserSearchResults) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 32 with FormConfiguration

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;
}
Also used : UserIdentity(password.pwm.bean.UserIdentity) FormConfiguration(password.pwm.config.value.data.FormConfiguration) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap)

Example 33 with FormConfiguration

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;
}
Also used : Locale(java.util.Locale) Instant(java.time.Instant) UserSearchEngine(password.pwm.ldap.search.UserSearchEngine) UserSearchResults(password.pwm.ldap.search.UserSearchResults) UserIdentity(password.pwm.bean.UserIdentity) ArrayList(java.util.ArrayList) SearchConfiguration(password.pwm.ldap.search.SearchConfiguration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) FormConfiguration(password.pwm.config.value.data.FormConfiguration) TimeDuration(password.pwm.util.java.TimeDuration) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 34 with FormConfiguration

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;
}
Also used : FormConfiguration(password.pwm.config.value.data.FormConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 35 with FormConfiguration

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);
}
Also used : LdapProfile(password.pwm.config.profile.LdapProfile) TokenDestinationItem(password.pwm.bean.TokenDestinationItem) LinkedHashMap(java.util.LinkedHashMap) TokenType(password.pwm.svc.token.TokenType) FormConfiguration(password.pwm.config.value.data.FormConfiguration) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

FormConfiguration (password.pwm.config.value.data.FormConfiguration)63 LinkedHashMap (java.util.LinkedHashMap)26 ErrorInformation (password.pwm.error.ErrorInformation)23 Map (java.util.Map)19 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)15 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 PwmOperationalException (password.pwm.error.PwmOperationalException)14 List (java.util.List)13 UserIdentity (password.pwm.bean.UserIdentity)13 PwmApplication (password.pwm.PwmApplication)11 UserInfo (password.pwm.ldap.UserInfo)10 ChaiUser (com.novell.ldapchai.ChaiUser)9 Locale (java.util.Locale)9 PwmSession (password.pwm.http.PwmSession)9 SearchConfiguration (password.pwm.ldap.search.SearchConfiguration)9 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)8 Configuration (password.pwm.config.Configuration)7 PwmDataValidationException (password.pwm.error.PwmDataValidationException)7 UserSearchEngine (password.pwm.ldap.search.UserSearchEngine)7