Search in sources :

Example 1 with Wordlist

use of password.pwm.svc.wordlist.Wordlist in project pwm by pwm-project.

the class ConfigManagerWordlistServlet method restReadWordlistData.

void restReadWordlistData(final PwmRequest pwmRequest) throws IOException {
    final LinkedHashMap<WordlistType, WordlistDataBean> outputData = new LinkedHashMap<>();
    final NumberFormat numberFormat = NumberFormat.getInstance(pwmRequest.getLocale());
    for (final WordlistType wordlistType : WordlistType.values()) {
        final Wordlist wordlist = wordlistType.forType(pwmRequest.getPwmApplication());
        final StoredWordlistDataBean storedWordlistDataBean = wordlist.readMetadata();
        final WordlistConfiguration wordlistConfiguration = wordlistType.forType(pwmRequest.getPwmApplication()).getConfiguration();
        final WordlistDataBean wordlistDataBean = new WordlistDataBean();
        {
            final Map<String, String> presentableValues = new LinkedHashMap<>();
            presentableValues.put("Population Status", storedWordlistDataBean.isCompleted() ? "Completed" : "In-Progress");
            presentableValues.put("List Source", storedWordlistDataBean.getSource() == null ? StoredWordlistDataBean.Source.BuiltIn.getLabel() : storedWordlistDataBean.getSource().getLabel());
            if (wordlistConfiguration.getAutoImportUrl() != null) {
                presentableValues.put("Configured Source URL", wordlistConfiguration.getAutoImportUrl());
            }
            if (storedWordlistDataBean.isCompleted()) {
                presentableValues.put("Word Count", numberFormat.format(storedWordlistDataBean.getSize()));
                if (StoredWordlistDataBean.Source.BuiltIn != storedWordlistDataBean.getSource()) {
                    presentableValues.put("Population Timestamp", JavaHelper.toIsoDate(storedWordlistDataBean.getStoreDate()));
                }
                presentableValues.put("SHA1 Checksum Hash", storedWordlistDataBean.getSha1hash());
            }
            if (wordlist.getAutoImportError() != null) {
                presentableValues.put("Error During Import", wordlist.getAutoImportError().getDetailedErrorMsg());
                presentableValues.put("Last Import Attempt", JavaHelper.toIsoDate(wordlist.getAutoImportError().getDate()));
            }
            wordlistDataBean.getPresentableData().putAll(presentableValues);
        }
        if (storedWordlistDataBean.isCompleted()) {
            if (wordlistConfiguration.getAutoImportUrl() == null) {
                wordlistDataBean.setAllowUpload(true);
            }
            if (wordlistConfiguration.getAutoImportUrl() != null || storedWordlistDataBean.getSource() != StoredWordlistDataBean.Source.BuiltIn) {
                wordlistDataBean.setAllowClear(true);
            }
        }
        outputData.put(wordlistType, wordlistDataBean);
    }
    pwmRequest.outputJsonResult(RestResultBean.withData(outputData));
}
Also used : StoredWordlistDataBean(password.pwm.svc.wordlist.StoredWordlistDataBean) WordlistConfiguration(password.pwm.svc.wordlist.WordlistConfiguration) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Wordlist(password.pwm.svc.wordlist.Wordlist) StoredWordlistDataBean(password.pwm.svc.wordlist.StoredWordlistDataBean) WordlistType(password.pwm.svc.wordlist.WordlistType) LinkedHashMap(java.util.LinkedHashMap) NumberFormat(java.text.NumberFormat)

Aggregations

NumberFormat (java.text.NumberFormat)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 StoredWordlistDataBean (password.pwm.svc.wordlist.StoredWordlistDataBean)1 Wordlist (password.pwm.svc.wordlist.Wordlist)1 WordlistConfiguration (password.pwm.svc.wordlist.WordlistConfiguration)1 WordlistType (password.pwm.svc.wordlist.WordlistType)1