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));
}
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));
}
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));
}
Aggregations