Search in sources :

Example 1 with LDAPPermissionInfo

use of password.pwm.config.LDAPPermissionInfo 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)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 LDAPPermissionInfo (password.pwm.config.LDAPPermissionInfo)1 LdapProfile (password.pwm.config.profile.LdapProfile)1 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)1 FormConfiguration (password.pwm.config.value.data.FormConfiguration)1 UserPermission (password.pwm.config.value.data.UserPermission)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1