Search in sources :

Example 6 with ActionConfiguration

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

the class ActionValue method toDebugJsonObject.

@Override
public Serializable toDebugJsonObject(final Locale locale) {
    final ArrayList<ActionConfiguration> output = new ArrayList<>();
    for (final ActionConfiguration actionConfiguration : values) {
        final ActionConfiguration clone = JsonUtil.cloneUsingJson(actionConfiguration, ActionConfiguration.class);
        if (!StringUtil.isEmpty(clone.getPassword())) {
            clone.setPassword(PwmConstants.LOG_REMOVED_VALUE_REPLACEMENT);
        }
        output.add(clone);
    }
    return output;
}
Also used : ArrayList(java.util.ArrayList) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 7 with ActionConfiguration

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

the class ActionValue method factory.

public static StoredValueFactory factory() {
    return new StoredValueFactory() {

        public ActionValue fromJson(final String input) {
            if (input == null) {
                return new ActionValue(Collections.emptyList());
            } else {
                List<ActionConfiguration> srcList = JsonUtil.deserialize(input, new TypeToken<List<ActionConfiguration>>() {
                });
                srcList = srcList == null ? Collections.emptyList() : srcList;
                while (srcList.contains(null)) {
                    srcList.remove(null);
                }
                return new ActionValue(Collections.unmodifiableList(srcList));
            }
        }

        public ActionValue fromXmlElement(final Element settingElement, final PwmSecurityKey pwmSecurityKey) throws PwmOperationalException {
            final boolean oldType = PwmSettingSyntax.STRING_ARRAY.toString().equals(settingElement.getAttributeValue("syntax"));
            final List valueElements = settingElement.getChildren("value");
            final List<ActionConfiguration> values = new ArrayList<>();
            for (final Object loopValue : valueElements) {
                final Element loopValueElement = (Element) loopValue;
                final String value = loopValueElement.getText();
                if (value != null && value.length() > 0) {
                    if (oldType) {
                        if (loopValueElement.getAttribute("locale") == null) {
                            values.add(ActionConfiguration.parseOldConfigString(value));
                        }
                    } else {
                        final ActionConfiguration parsedAc = JsonUtil.deserialize(value, ActionConfiguration.class);
                        parsedAc.setPassword(decryptPwValue(parsedAc.getPassword(), pwmSecurityKey));
                        values.add(parsedAc);
                    }
                }
            }
            return new ActionValue(values);
        }
    };
}
Also used : PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 8 with ActionConfiguration

use of password.pwm.config.value.data.ActionConfiguration 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 9 with ActionConfiguration

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

the class ActionValue method toInfoMap.

public List<Map<String, Object>> toInfoMap() {
    final String originalJson = JsonUtil.serializeCollection(values);
    final List<Map<String, Object>> tempObj = JsonUtil.deserialize(originalJson, new TypeToken<List<Map<String, Object>>>() {
    });
    for (final Map<String, Object> mapObj : tempObj) {
        final ActionConfiguration actionConfiguration = forName((String) mapObj.get("name"));
        if (actionConfiguration != null && actionConfiguration.getCertificates() != null) {
            final List<Map<String, String>> certificateInfos = new ArrayList<>();
            for (final X509Certificate certificate : actionConfiguration.getCertificates()) {
                certificateInfos.add(X509Utils.makeDebugInfoMap(certificate, X509Utils.DebugInfoFlag.IncludeCertificateDetail));
            }
            mapObj.put("certificateInfos", certificateInfos);
        }
    }
    return tempObj;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) Map(java.util.Map) X509Certificate(java.security.cert.X509Certificate)

Example 10 with ActionConfiguration

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

the class ActionValue method toXmlValues.

public List<Element> toXmlValues(final String valueElementName, final PwmSecurityKey pwmSecurityKey) {
    final List<Element> returnList = new ArrayList<>();
    for (final ActionConfiguration value : values) {
        final Element valueElement = new Element(valueElementName);
        final ActionConfiguration clonedValue = JsonUtil.cloneUsingJson(value, ActionConfiguration.class);
        try {
            clonedValue.setPassword(encryptPwValue(clonedValue.getPassword(), pwmSecurityKey));
        } catch (PwmOperationalException e) {
            LOGGER.warn("error decoding stored pw value: " + e.getMessage());
        }
        valueElement.addContent(JsonUtil.serialize(clonedValue));
        returnList.add(valueElement);
    }
    return returnList;
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)14 ArrayList (java.util.ArrayList)9 List (java.util.List)6 ErrorInformation (password.pwm.error.ErrorInformation)5 PwmOperationalException (password.pwm.error.PwmOperationalException)5 ChaiUser (com.novell.ldapchai.ChaiUser)3 X509Certificate (java.security.cert.X509Certificate)3 ActionValue (password.pwm.config.value.ActionValue)3 FormConfiguration (password.pwm.config.value.data.FormConfiguration)3 PwmSession (password.pwm.http.PwmSession)3 MacroMachine (password.pwm.util.macro.MacroMachine)3 ActionExecutor (password.pwm.util.operations.ActionExecutor)3 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)2 Map (java.util.Map)2 Element (org.jdom2.Element)2 PwmApplication (password.pwm.PwmApplication)2 UserIdentity (password.pwm.bean.UserIdentity)2 Configuration (password.pwm.config.Configuration)2 PwmSetting (password.pwm.config.PwmSetting)2 StoredConfigReference (password.pwm.config.stored.StoredConfigReference)2