Search in sources :

Example 1 with ActionValue

use of password.pwm.config.value.ActionValue in project pwm by pwm-project.

the class ActionCertImportFunction method getUri.

@Override
String getUri(final StoredConfigurationImpl storedConfiguration, final PwmSetting pwmSetting, final String profile, final String extraData) throws PwmOperationalException {
    final ActionValue actionValue = (ActionValue) storedConfiguration.readSetting(pwmSetting, profile);
    final String actionName = actionNameFromExtraData(extraData);
    final ActionConfiguration action = actionValue.forName(actionName);
    final String uriString = action.getUrl();
    if (uriString == null || uriString.isEmpty()) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "Setting " + pwmSetting.toMenuLocationDebug(profile, null) + " action " + actionName + " must first be configured");
        throw new PwmOperationalException(errorInformation);
    }
    try {
        URI.create(uriString);
    } catch (IllegalArgumentException e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, "Setting " + pwmSetting.toMenuLocationDebug(profile, null) + " action " + actionName + " has an invalid URL syntax");
        throw new PwmOperationalException(errorInformation);
    }
    return uriString;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ActionValue(password.pwm.config.value.ActionValue) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 2 with ActionValue

use of password.pwm.config.value.ActionValue in project pwm by pwm-project.

the class CertificateChecker method doActionHealthCheck.

private static List<HealthRecord> doActionHealthCheck(final Configuration configuration) throws PwmUnrecoverableException {
    final StoredConfigurationImpl storedConfiguration = configuration.getStoredConfiguration();
    final List<HealthRecord> returnList = new ArrayList<>();
    final List<StoredConfigReference> modifiedReferences = StoredConfigurationUtil.modifiedSettings(storedConfiguration);
    for (final StoredConfigReference storedConfigReference : modifiedReferences) {
        if (storedConfigReference.getRecordType() == StoredConfigReference.RecordType.SETTING) {
            final PwmSetting pwmSetting = PwmSetting.forKey(storedConfigReference.getRecordID());
            if (pwmSetting != null && pwmSetting.getSyntax() == PwmSettingSyntax.ACTION) {
                final ActionValue value = (ActionValue) storedConfiguration.readSetting(pwmSetting, storedConfigReference.getProfileID());
                for (final ActionConfiguration actionConfiguration : value.toNativeObject()) {
                    final List<X509Certificate> certificates = actionConfiguration.getCertificates();
                    returnList.addAll(doHealthCheck(configuration, pwmSetting, storedConfigReference.getProfileID(), certificates));
                }
            }
        }
    }
    return Collections.unmodifiableList(returnList);
}
Also used : StoredConfigReference(password.pwm.config.stored.StoredConfigReference) PwmSetting(password.pwm.config.PwmSetting) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) ActionValue(password.pwm.config.value.ActionValue) ArrayList(java.util.ArrayList) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) X509Certificate(java.security.cert.X509Certificate)

Example 3 with ActionValue

use of password.pwm.config.value.ActionValue in project pwm by pwm-project.

the class ActionCertImportFunction method store.

void store(final List<X509Certificate> certs, final StoredConfigurationImpl storedConfiguration, final PwmSetting pwmSetting, final String profile, final String extraData, final UserIdentity userIdentity) throws PwmOperationalException, PwmUnrecoverableException {
    final ActionValue actionValue = (ActionValue) storedConfiguration.readSetting(pwmSetting, profile);
    final String actionName = actionNameFromExtraData(extraData);
    final List<ActionConfiguration> newList = new ArrayList<>();
    for (final ActionConfiguration loopConfiguration : actionValue.toNativeObject()) {
        if (actionName.equals(loopConfiguration.getName())) {
            final ActionConfiguration newConfig = loopConfiguration.copyWithNewCertificate(certs);
            newList.add(newConfig);
        } else {
            newList.add(JsonUtil.cloneUsingJson(loopConfiguration, ActionConfiguration.class));
        }
    }
    final ActionValue newActionValue = new ActionValue(newList);
    storedConfiguration.writeSetting(pwmSetting, profile, newActionValue, userIdentity);
}
Also used : ActionValue(password.pwm.config.value.ActionValue) ArrayList(java.util.ArrayList) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 4 with ActionValue

use of password.pwm.config.value.ActionValue in project pwm by pwm-project.

the class ConfigEditorServlet method restReadSetting.

@ActionHandler(action = "readSetting")
private ProcessStatus restReadSetting(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfig = configManagerBean.getStoredConfiguration();
    final String key = pwmRequest.readParameterAsString("key");
    final Object returnValue;
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
    final PwmSetting theSetting = PwmSetting.forKey(key);
    if (key.startsWith("localeBundle")) {
        final StringTokenizer st = new StringTokenizer(key, "-");
        st.nextToken();
        final PwmLocaleBundle bundleName = PwmLocaleBundle.valueOf(st.nextToken());
        final String keyName = st.nextToken();
        final Map<String, String> bundleMap = storedConfig.readLocaleBundleMap(bundleName.getTheClass().getName(), keyName);
        if (bundleMap == null || bundleMap.isEmpty()) {
            final Map<String, String> defaultValueMap = new LinkedHashMap<>();
            final String defaultLocaleValue = ResourceBundle.getBundle(bundleName.getTheClass().getName(), PwmConstants.DEFAULT_LOCALE).getString(keyName);
            for (final Locale locale : pwmRequest.getConfig().getKnownLocales()) {
                final ResourceBundle localeBundle = ResourceBundle.getBundle(bundleName.getTheClass().getName(), locale);
                if (locale.toString().equalsIgnoreCase(PwmConstants.DEFAULT_LOCALE.toString())) {
                    defaultValueMap.put("", defaultLocaleValue);
                } else {
                    final String valueStr = localeBundle.getString(keyName);
                    if (!defaultLocaleValue.equals(valueStr)) {
                        final String localeStr = locale.toString();
                        defaultValueMap.put(localeStr, localeBundle.getString(keyName));
                    }
                }
            }
            returnValue = defaultValueMap;
            returnMap.put("isDefault", true);
        } else {
            returnValue = bundleMap;
            returnMap.put("isDefault", false);
        }
        returnMap.put("key", key);
    } else if (theSetting == null) {
        final String errorStr = "readSettingAsString request for unknown key: " + key;
        LOGGER.warn(errorStr);
        pwmRequest.outputJsonResult(RestResultBean.fromError(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorStr)));
        return ProcessStatus.Halt;
    } else {
        final String profile = theSetting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
        switch(theSetting.getSyntax()) {
            case PASSWORD:
                returnValue = Collections.singletonMap("isDefault", storedConfig.isDefaultValue(theSetting, profile));
                break;
            case X509CERT:
                returnValue = ((X509CertificateValue) storedConfig.readSetting(theSetting, profile)).toInfoMap(true);
                break;
            case PRIVATE_KEY:
                returnValue = ((PrivateKeyValue) storedConfig.readSetting(theSetting, profile)).toInfoMap(true);
                break;
            case ACTION:
                returnValue = ((ActionValue) storedConfig.readSetting(theSetting, profile)).toInfoMap();
                break;
            case REMOTE_WEB_SERVICE:
                returnValue = ((RemoteWebServiceValue) storedConfig.readSetting(theSetting, profile)).toInfoMap();
                break;
            case FILE:
                returnValue = ((FileValue) storedConfig.readSetting(theSetting, profile)).toInfoMap();
                break;
            default:
                returnValue = storedConfig.readSetting(theSetting, profile).toNativeObject();
        }
        returnMap.put("isDefault", storedConfig.isDefaultValue(theSetting, profile));
        if (theSetting.getSyntax() == PwmSettingSyntax.SELECT) {
            returnMap.put("options", theSetting.getOptions());
        }
        {
            final ValueMetaData settingMetaData = storedConfig.readSettingMetadata(theSetting, profile);
            if (settingMetaData != null) {
                if (settingMetaData.getModifyDate() != null) {
                    returnMap.put("modifyTime", settingMetaData.getModifyDate());
                }
                if (settingMetaData.getUserIdentity() != null) {
                    returnMap.put("modifyUser", settingMetaData.getUserIdentity());
                }
            }
        }
        returnMap.put("key", key);
        returnMap.put("category", theSetting.getCategory().toString());
        returnMap.put("syntax", theSetting.getSyntax().toString());
    }
    returnMap.put("value", returnValue);
    pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) PrivateKeyValue(password.pwm.config.value.PrivateKeyValue) FileValue(password.pwm.config.value.FileValue) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) LinkedHashMap(java.util.LinkedHashMap) X509CertificateValue(password.pwm.config.value.X509CertificateValue) PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ErrorInformation(password.pwm.error.ErrorInformation) StringTokenizer(java.util.StringTokenizer) ActionValue(password.pwm.config.value.ActionValue) RemoteWebServiceValue(password.pwm.config.value.RemoteWebServiceValue) ValueMetaData(password.pwm.config.stored.ValueMetaData) ResourceBundle(java.util.ResourceBundle)

Aggregations

ActionValue (password.pwm.config.value.ActionValue)4 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)3 ArrayList (java.util.ArrayList)2 PwmSetting (password.pwm.config.PwmSetting)2 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)2 ErrorInformation (password.pwm.error.ErrorInformation)2 X509Certificate (java.security.cert.X509Certificate)1 LinkedHashMap (java.util.LinkedHashMap)1 Locale (java.util.Locale)1 ResourceBundle (java.util.ResourceBundle)1 StringTokenizer (java.util.StringTokenizer)1 StoredConfigReference (password.pwm.config.stored.StoredConfigReference)1 ValueMetaData (password.pwm.config.stored.ValueMetaData)1 FileValue (password.pwm.config.value.FileValue)1 PrivateKeyValue (password.pwm.config.value.PrivateKeyValue)1 RemoteWebServiceValue (password.pwm.config.value.RemoteWebServiceValue)1 X509CertificateValue (password.pwm.config.value.X509CertificateValue)1 PwmOperationalException (password.pwm.error.PwmOperationalException)1 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)1 PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)1