Search in sources :

Example 41 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.

the class LDAPPermissionCalculator method figureRecord.

private Collection<PermissionRecord> figureRecord(final PwmSetting pwmSetting, final String profile) throws PwmUnrecoverableException {
    final List<PermissionRecord> permissionRecords = new ArrayList<>();
    final Collection<LDAPPermissionInfo> permissionInfos = figurePermissionInfos(pwmSetting, profile);
    if (permissionInfos == null) {
        return Collections.emptyList();
    }
    for (final LDAPPermissionInfo permissionInfo : permissionInfos) {
        switch(pwmSetting.getSyntax()) {
            case STRING:
                {
                    final String attrName = (String) storedConfiguration.readSetting(pwmSetting, profile).toNativeObject();
                    if (attrName != null && !attrName.trim().isEmpty()) {
                        permissionRecords.add(new PermissionRecord(attrName, pwmSetting, profile, permissionInfo.getAccess(), permissionInfo.getActor()));
                    }
                }
                break;
            case FORM:
                {
                    final List<FormConfiguration> formItems = (List<FormConfiguration>) storedConfiguration.readSetting(pwmSetting, profile).toNativeObject();
                    if (formItems != null) {
                        for (final FormConfiguration formConfiguration : formItems) {
                            final String attrName = formConfiguration.getName();
                            if (attrName != null && !attrName.trim().isEmpty()) {
                                permissionRecords.add(new PermissionRecord(attrName, pwmSetting, profile, permissionInfo.getAccess(), permissionInfo.getActor()));
                            }
                        }
                    }
                }
                break;
            case ACTION:
                {
                    final List<ActionConfiguration> actionItems = (List<ActionConfiguration>) storedConfiguration.readSetting(pwmSetting, profile).toNativeObject();
                    if (actionItems != null) {
                        for (final ActionConfiguration actionConfiguration : actionItems) {
                            if (actionConfiguration.getType() == ActionConfiguration.Type.ldap) {
                                final String attrName = actionConfiguration.getAttributeName();
                                if (attrName != null && !attrName.trim().isEmpty()) {
                                    permissionRecords.add(new PermissionRecord(attrName, pwmSetting, profile, permissionInfo.getAccess(), permissionInfo.getActor()));
                                }
                            }
                        }
                    }
                }
                break;
            case STRING_ARRAY:
                {
                    final List<String> strings = (List<String>) storedConfiguration.readSetting(pwmSetting, profile).toNativeObject();
                    for (final String attrName : strings) {
                        if (attrName != null && !attrName.trim().isEmpty()) {
                            permissionRecords.add(new PermissionRecord(attrName, pwmSetting, profile, permissionInfo.getAccess(), permissionInfo.getActor()));
                        }
                    }
                }
                break;
            case USER_PERMISSION:
                {
                    final List<UserPermission> userPermissions = (List<UserPermission>) storedConfiguration.readSetting(pwmSetting, profile).toNativeObject();
                    if (configuration.getLdapProfiles() != null && !configuration.getLdapProfiles().isEmpty()) {
                        for (final LdapProfile ldapProfile : configuration.getLdapProfiles().values()) {
                            final String groupAttribute = ldapProfile.readSettingAsString(PwmSetting.LDAP_USER_GROUP_ATTRIBUTE);
                            if (groupAttribute != null && !groupAttribute.trim().isEmpty()) {
                                for (final UserPermission userPermission : userPermissions) {
                                    if (userPermission.getType() == UserPermission.Type.ldapGroup) {
                                        permissionRecords.add(new PermissionRecord(groupAttribute, pwmSetting, profile, permissionInfo.getAccess(), permissionInfo.getActor()));
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            default:
                throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, "no ldap permission record reader handler for setting " + pwmSetting.getKey()));
        }
    }
    return permissionRecords;
}
Also used : ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) LdapProfile(password.pwm.config.profile.LdapProfile) ErrorInformation(password.pwm.error.ErrorInformation) LDAPPermissionInfo(password.pwm.config.LDAPPermissionInfo) ArrayList(java.util.ArrayList) List(java.util.List) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) UserPermission(password.pwm.config.value.data.UserPermission)

Example 42 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.

the class UpdateProfileUtil method updateBeanFormData.

static Map<FormConfiguration, String> updateBeanFormData(final List<FormConfiguration> formFields, final Map<FormConfiguration, String> formValueMap, final UpdateProfileBean updateProfileBean) {
    final LinkedHashMap<FormConfiguration, String> newFormValueMap = new LinkedHashMap<>();
    for (final FormConfiguration formConfiguration : formFields) {
        if (formConfiguration.isReadonly()) {
            final String existingValue = updateProfileBean.getFormData().get(formConfiguration.getName());
            newFormValueMap.put(formConfiguration, existingValue);
        } else {
            newFormValueMap.put(formConfiguration, formValueMap.get(formConfiguration));
        }
    }
    updateProfileBean.getFormData().clear();
    updateProfileBean.getFormData().putAll(FormUtility.asStringMap(newFormValueMap));
    return newFormValueMap;
}
Also used : FormConfiguration(password.pwm.config.value.data.FormConfiguration) LinkedHashMap(java.util.LinkedHashMap)

Example 43 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.

the class PeopleSearchDataReader method makeUserDetailRequest.

UserDetailBean makeUserDetailRequest(final String userKey) throws PwmUnrecoverableException, PwmOperationalException, ChaiUnavailableException {
    final Instant startTime = Instant.now();
    final UserIdentity userIdentity = UserIdentity.fromKey(userKey, pwmRequest.getPwmApplication());
    final CacheKey cacheKey = makeCacheKey(UserDetailBean.class.getSimpleName(), userIdentity.toDelimitedKey());
    {
        final String cachedOutput = pwmRequest.getPwmApplication().getCacheService().get(cacheKey);
        if (cachedOutput != null) {
            StatisticsManager.incrementStat(pwmRequest, Statistic.PEOPLESEARCH_CACHE_HITS);
            return JsonUtil.deserialize(cachedOutput, UserDetailBean.class);
        } else {
            StatisticsManager.incrementStat(pwmRequest, Statistic.PEOPLESEARCH_CACHE_MISSES);
        }
    }
    try {
        checkIfUserIdentityViewable(userIdentity);
    } catch (PwmOperationalException e) {
        LOGGER.error(pwmRequest.getPwmSession(), "error during detail results request while checking if requested userIdentity is within search scope: " + e.getMessage());
        throw e;
    }
    final UserSearchResults detailResults = doDetailLookup(userIdentity);
    final Map<String, String> searchResults = detailResults.getResults().get(userIdentity);
    final UserDetailBean userDetailBean = new UserDetailBean();
    userDetailBean.setUserKey(userKey);
    final List<FormConfiguration> detailFormConfig = pwmRequest.getConfig().readSettingAsForm(PwmSetting.PEOPLE_SEARCH_DETAIL_FORM);
    final Map<String, AttributeDetailBean> attributeBeans = convertResultMapToBeans(pwmRequest, userIdentity, detailFormConfig, searchResults);
    userDetailBean.setDetail(attributeBeans);
    final String photoURL = figurePhotoURL(pwmRequest, userIdentity);
    if (photoURL != null) {
        userDetailBean.setPhotoURL(photoURL);
    }
    final List<String> displayName = figureDisplaynames(pwmRequest, userIdentity);
    if (displayName != null) {
        userDetailBean.setDisplayNames(displayName);
    }
    userDetailBean.setLinks(makeUserDetailLinks(userIdentity));
    LOGGER.trace(pwmRequest.getPwmSession(), "finished building userDetail result in " + TimeDuration.fromCurrent(startTime).asCompactString());
    storeDataInCache(pwmRequest.getPwmApplication(), cacheKey, userDetailBean);
    return userDetailBean;
}
Also used : Instant(java.time.Instant) UserIdentity(password.pwm.bean.UserIdentity) UserSearchResults(password.pwm.ldap.search.UserSearchResults) PwmOperationalException(password.pwm.error.PwmOperationalException) FormConfiguration(password.pwm.config.value.data.FormConfiguration) CacheKey(password.pwm.svc.cache.CacheKey)

Example 44 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.

the class UserSearchEngine method figureSearchFilterForParams.

private static String figureSearchFilterForParams(final Map<FormConfiguration, String> formValues, final String searchFilter, final boolean enableValueEscaping) {
    String newSearchFilter = searchFilter;
    for (final Map.Entry<FormConfiguration, String> entry : formValues.entrySet()) {
        final FormConfiguration formItem = entry.getKey();
        final String attrName = "%" + formItem.getName() + "%";
        String value = entry.getValue();
        if (enableValueEscaping) {
            value = StringUtil.escapeLdapFilter(value);
        }
        newSearchFilter = newSearchFilter.replace(attrName, value);
    }
    return newSearchFilter;
}
Also used : FormConfiguration(password.pwm.config.value.data.FormConfiguration) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap)

Example 45 with FormConfiguration

use of password.pwm.config.value.data.FormConfiguration in project pwm by pwm-project.

the class FormUtility method asFormConfigurationMap.

public static Map<FormConfiguration, String> asFormConfigurationMap(final List<FormConfiguration> formConfigurations, final Map<String, String> values) {
    final Map<FormConfiguration, String> returnMap = new LinkedHashMap<>();
    for (final FormConfiguration formConfiguration : formConfigurations) {
        final String name = formConfiguration.getName();
        final String value = values.get(name);
        returnMap.put(formConfiguration, value);
    }
    return returnMap;
}
Also used : FormConfiguration(password.pwm.config.value.data.FormConfiguration) LinkedHashMap(java.util.LinkedHashMap)

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