Search in sources :

Example 71 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class ConfigGuideServlet method restWriteSetting.

@ActionHandler(action = "writeSetting")
private ProcessStatus restWriteSetting(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
    final String profileID = "default";
    final String key = pwmRequest.readParameterAsString("key");
    final String bodyString = pwmRequest.readRequestBodyAsString();
    final PwmSetting setting = PwmSetting.forKey(key);
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
    try {
        final StoredValue storedValue = ValueFactory.fromJson(setting, bodyString);
        final List<String> errorMsgs = storedValue.validateValue(setting);
        if (errorMsgs != null && !errorMsgs.isEmpty()) {
            returnMap.put("errorMessage", setting.getLabel(pwmRequest.getLocale()) + ": " + errorMsgs.get(0));
        }
        if (setting == PwmSetting.CHALLENGE_RANDOM_CHALLENGES) {
            configGuideBean.getFormData().put(ConfigGuideFormField.CHALLENGE_RESPONSE_DATA, JsonUtil.serialize((Serializable) storedValue.toNativeObject()));
        }
    } catch (Exception e) {
        final String errorMsg = "error writing default value for setting " + setting.toString() + ", error: " + e.getMessage();
        LOGGER.error(errorMsg, e);
        throw new IllegalStateException(errorMsg, e);
    }
    returnMap.put("key", key);
    returnMap.put("category", setting.getCategory().toString());
    returnMap.put("syntax", setting.getSyntax().toString());
    returnMap.put("isDefault", storedConfigurationImpl.isDefaultValue(setting, profileID));
    pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
    return ProcessStatus.Halt;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Serializable(java.io.Serializable) StoredValue(password.pwm.config.StoredValue) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 72 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class ConfigManagerServlet method doDownloadConfig.

private void doDownloadConfig(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final PwmResponse resp = pwmRequest.getPwmResponse();
    try {
        final StoredConfigurationImpl storedConfiguration = readCurrentConfiguration(pwmRequest);
        final OutputStream responseWriter = resp.getOutputStream();
        resp.setHeader(HttpHeader.ContentDisposition, "attachment;filename=" + PwmConstants.DEFAULT_CONFIG_FILE_FILENAME);
        resp.setContentType(HttpContentType.xml);
        storedConfiguration.toXml(responseWriter);
        responseWriter.close();
    } catch (Exception e) {
        LOGGER.error(pwmSession, "unable to download configuration: " + e.getMessage());
    }
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmResponse(password.pwm.http.PwmResponse) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) PwmSession(password.pwm.http.PwmSession) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 73 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class ConfigManagerServlet method restLockConfiguration.

private void restLockConfiguration(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    if (PwmConstants.TRIAL_MODE) {
        final String msg = LocaleHelper.getLocalizedMessage(Admin.Notice_TrialRestrictConfig, pwmRequest);
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_TRIAL_VIOLATION, msg);
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo);
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    if (!pwmSession.isAuthenticated()) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_AUTHENTICATION_REQUIRED, "You must be authenticated before restricting the configuration");
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo);
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    if (!pwmSession.getSessionManager().checkPermission(pwmApplication, Permission.PWMADMIN)) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNAUTHORIZED, "You must be authenticated with admin privileges before restricting the configuration");
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo);
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    try {
        final StoredConfigurationImpl storedConfiguration = readCurrentConfiguration(pwmRequest);
        if (!storedConfiguration.hasPassword()) {
            final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "Please set a configuration password before restricting the configuration" });
            final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
            LOGGER.debug(pwmSession, errorInfo);
            pwmRequest.outputJsonResult(restResultBean);
            return;
        }
        storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, "false");
        saveConfiguration(pwmRequest, storedConfiguration);
        final ConfigManagerBean configManagerBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ConfigManagerBean.class);
        configManagerBean.setConfiguration(null);
    } catch (PwmException e) {
        final ErrorInformation errorInfo = e.getErrorInformation();
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo.toDebugStr());
        pwmRequest.outputJsonResult(restResultBean);
        return;
    } catch (Exception e) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo.toDebugStr());
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    final HashMap<String, String> resultData = new HashMap<>();
    LOGGER.info(pwmSession, "Configuration Locked");
    pwmRequest.outputJsonResult(RestResultBean.withData(resultData));
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) PwmApplication(password.pwm.PwmApplication) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PwmSession(password.pwm.http.PwmSession) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 74 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class DebugItemGenerator method outputZipDebugFile.

static void outputZipDebugFile(final PwmRequest pwmRequest, final ZipOutputStream zipOutput, final String pathPrefix) throws IOException, PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final String debugFileName = "zipDebugGeneration.csv";
    final ByteArrayOutputStream debugGeneratorLogBaos = new ByteArrayOutputStream();
    final CSVPrinter debugGeneratorLogFile = JavaHelper.makeCsvPrinter(debugGeneratorLogBaos);
    for (final Class<? extends DebugItemGenerator.Generator> serviceClass : DEBUG_ZIP_ITEM_GENERATORS) {
        try {
            final Instant startTime = Instant.now();
            LOGGER.trace(pwmRequest, "beginning output of item " + serviceClass.getSimpleName());
            final Object newInstance = serviceClass.newInstance();
            final DebugItemGenerator.Generator newGeneratorItem = (DebugItemGenerator.Generator) newInstance;
            zipOutput.putNextEntry(new ZipEntry(pathPrefix + newGeneratorItem.getFilename()));
            newGeneratorItem.outputItem(pwmApplication, pwmRequest, zipOutput);
            zipOutput.closeEntry();
            zipOutput.flush();
            final String finishMsg = "completed output of " + newGeneratorItem.getFilename() + " in " + TimeDuration.fromCurrent(startTime).asCompactString();
            LOGGER.trace(pwmRequest, finishMsg);
            debugGeneratorLogFile.printRecord(JavaHelper.toIsoDate(Instant.now()), finishMsg);
        } catch (Throwable e) {
            final String errorMsg = "unexpected error executing debug item output class '" + serviceClass.getName() + "', error: " + e.toString();
            LOGGER.error(pwmRequest, errorMsg);
            debugGeneratorLogFile.printRecord(JavaHelper.toIsoDate(Instant.now()), errorMsg);
            final Writer stackTraceOutput = new StringWriter();
            e.printStackTrace(new PrintWriter(stackTraceOutput));
            debugGeneratorLogFile.printRecord(stackTraceOutput);
        }
    }
    try {
        zipOutput.putNextEntry(new ZipEntry(pathPrefix + debugFileName));
        debugGeneratorLogFile.flush();
        zipOutput.write(debugGeneratorLogBaos.toByteArray());
        zipOutput.closeEntry();
    } catch (Exception e) {
        LOGGER.error("error generating " + debugFileName + ": " + e.getMessage());
    }
    zipOutput.flush();
}
Also used : PwmApplication(password.pwm.PwmApplication) Instant(java.time.Instant) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) IOException(java.io.IOException) CSVPrinter(org.apache.commons.csv.CSVPrinter) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) LdapDebugDataGenerator(password.pwm.ldap.LdapDebugDataGenerator) PrintWriter(java.io.PrintWriter)

Example 75 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class ForgottenPasswordServlet method processEnterCode.

@ActionHandler(action = "enterCode")
private ProcessStatus processEnterCode(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
    final ForgottenPasswordBean forgottenPasswordBean = forgottenPasswordBean(pwmRequest);
    final String userEnteredCode = pwmRequest.readParameterAsString(PwmConstants.PARAM_TOKEN);
    ErrorInformation errorInformation = null;
    try {
        final TokenPayload tokenPayload = TokenUtil.checkEnteredCode(pwmRequest, userEnteredCode, forgottenPasswordBean.getProgress().getTokenDestination(), null, TokenType.FORGOTTEN_PW, TokenService.TokenEntryType.unauthenticated);
        // token correct
        if (forgottenPasswordBean.getUserIdentity() == null) {
            // clean session, user supplied token (clicked email, etc) and this is first request
            ForgottenPasswordUtil.initForgottenPasswordBean(pwmRequest, tokenPayload.getUserIdentity(), forgottenPasswordBean);
        }
        forgottenPasswordBean.getProgress().getSatisfiedMethods().add(IdentityVerificationMethod.TOKEN);
        StatisticsManager.incrementStat(pwmRequest.getPwmApplication(), Statistic.RECOVERY_TOKENS_PASSED);
        if (pwmRequest.getConfig().readSettingAsBoolean(PwmSetting.DISPLAY_TOKEN_SUCCESS_BUTTON)) {
            pwmRequest.setAttribute(PwmRequestAttribute.TokenDestItems, tokenPayload.getDestination());
            pwmRequest.forwardToJsp(JspUrl.RECOVER_PASSWORD_TOKEN_SUCCESS);
            return ProcessStatus.Halt;
        }
    } catch (PwmUnrecoverableException e) {
        LOGGER.debug(pwmRequest, "error while checking entered token: ");
        errorInformation = e.getErrorInformation();
    } catch (PwmOperationalException e) {
        final String errorMsg = "token incorrect: " + e.getMessage();
        errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT, errorMsg);
    }
    if (!forgottenPasswordBean.getProgress().getSatisfiedMethods().contains(IdentityVerificationMethod.TOKEN)) {
        if (errorInformation == null) {
            errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT);
        }
        handleUserVerificationBadAttempt(pwmRequest, forgottenPasswordBean, errorInformation);
    }
    return ProcessStatus.Continue;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ForgottenPasswordBean(password.pwm.http.bean.ForgottenPasswordBean) TokenPayload(password.pwm.svc.token.TokenPayload) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)282 ErrorInformation (password.pwm.error.ErrorInformation)201 PwmOperationalException (password.pwm.error.PwmOperationalException)85 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)75 IOException (java.io.IOException)72 PwmException (password.pwm.error.PwmException)69 PwmApplication (password.pwm.PwmApplication)48 UserIdentity (password.pwm.bean.UserIdentity)48 Configuration (password.pwm.config.Configuration)43 ServletException (javax.servlet.ServletException)38 LinkedHashMap (java.util.LinkedHashMap)37 Instant (java.time.Instant)35 ArrayList (java.util.ArrayList)31 PwmSession (password.pwm.http.PwmSession)30 Map (java.util.Map)28 ChaiUser (com.novell.ldapchai.ChaiUser)26 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)25 FormConfiguration (password.pwm.config.value.data.FormConfiguration)24 HashMap (java.util.HashMap)23 ChaiException (com.novell.ldapchai.exception.ChaiException)22