Search in sources :

Example 1 with WordlistType

use of password.pwm.svc.wordlist.WordlistType 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)

Example 2 with WordlistType

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

the class ConfigManagerWordlistServlet method restUploadWordlist.

void restUploadWordlist(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final HttpServletRequest req = pwmRequest.getHttpServletRequest();
    final String wordlistTypeParam = pwmRequest.readParameterAsString("wordlist");
    final WordlistType wordlistType = WordlistType.valueOf(wordlistTypeParam);
    if (wordlistType == null) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unknown wordlist type: " + wordlistTypeParam);
        pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
        LOGGER.error(pwmRequest, "error during import: " + errorInformation.toDebugStr());
        return;
    }
    if (!ServletFileUpload.isMultipartContent(req)) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "no file found in upload");
        pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
        LOGGER.error(pwmRequest, "error during import: " + errorInformation.toDebugStr());
        return;
    }
    final InputStream inputStream = pwmRequest.readFileUploadStream(PwmConstants.PARAM_FILE_UPLOAD);
    try {
        wordlistType.forType(pwmApplication).populate(inputStream);
    } catch (PwmUnrecoverableException e) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmRequest, errorInfo.toDebugStr());
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) InputStream(java.io.InputStream) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) WordlistType(password.pwm.svc.wordlist.WordlistType) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 3 with WordlistType

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

the class ConfigManagerWordlistServlet method restClearWordlist.

void restClearWordlist(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final String wordlistTypeParam = pwmRequest.readParameterAsString("wordlist");
    final WordlistType wordlistType = WordlistType.valueOf(wordlistTypeParam);
    if (wordlistType == null) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unknown wordlist type: " + wordlistTypeParam);
        pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
        LOGGER.error(pwmRequest, "error during clear: " + errorInformation.toDebugStr());
        return;
    }
    try {
        wordlistType.forType(pwmRequest.getPwmApplication()).clear();
    } catch (Exception e) {
        LOGGER.error("error clearing wordlist " + wordlistType + ", error: " + e.getMessage());
    }
    pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) WordlistType(password.pwm.svc.wordlist.WordlistType)

Aggregations

WordlistType (password.pwm.svc.wordlist.WordlistType)3 ErrorInformation (password.pwm.error.ErrorInformation)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 NumberFormat (java.text.NumberFormat)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PwmApplication (password.pwm.PwmApplication)1 StoredWordlistDataBean (password.pwm.svc.wordlist.StoredWordlistDataBean)1 Wordlist (password.pwm.svc.wordlist.Wordlist)1 WordlistConfiguration (password.pwm.svc.wordlist.WordlistConfiguration)1 RestResultBean (password.pwm.ws.server.RestResultBean)1