Search in sources :

Example 1 with ErrorInformation

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

the class ContextManager method getContextManager.

public static ContextManager getContextManager(final ServletContext theContext) throws PwmUnrecoverableException {
    // context manager is initialized at servlet context startup.
    final Object theManager = theContext.getAttribute(PwmConstants.CONTEXT_ATTR_CONTEXT_MANAGER);
    if (theManager == null) {
        final String errorMsg = "unable to load the context manager from servlet context";
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_APP_UNAVAILABLE, errorMsg);
        throw new PwmUnrecoverableException(errorInformation);
    }
    return (ContextManager) theManager;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 2 with ErrorInformation

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

the class ContextManager method initialize.

public void initialize() {
    try {
        Locale.setDefault(PwmConstants.DEFAULT_LOCALE);
    } catch (Exception e) {
        outputError("unable to set default locale as Java machine default locale: " + e.getMessage());
    }
    Configuration configuration = null;
    PwmApplicationMode mode = PwmApplicationMode.ERROR;
    final ParameterReader parameterReader = new ParameterReader(servletContext);
    final File applicationPath;
    {
        final String applicationPathStr = parameterReader.readApplicationPath();
        if (applicationPathStr == null || applicationPathStr.isEmpty()) {
            startupErrorInformation = new ErrorInformation(PwmError.ERROR_ENVIRONMENT_ERROR, "application path is not specified");
            return;
        } else {
            applicationPath = new File(applicationPathStr);
        }
    }
    File configurationFile = null;
    try {
        configurationFile = locateConfigurationFile(applicationPath);
        configReader = new ConfigurationReader(configurationFile);
        configReader.getStoredConfiguration().lock();
        configuration = configReader.getConfiguration();
        mode = startupErrorInformation == null ? configReader.getConfigMode() : PwmApplicationMode.ERROR;
        if (startupErrorInformation == null) {
            startupErrorInformation = configReader.getConfigFileError();
        }
        if (PwmApplicationMode.ERROR == mode) {
            outputError("Startup Error: " + (startupErrorInformation == null ? "un-specified error" : startupErrorInformation.toDebugStr()));
        }
    } catch (Throwable e) {
        handleStartupError("unable to initialize application due to configuration related error: ", e);
    }
    LOGGER.debug("configuration file was loaded from " + (configurationFile == null ? "null" : configurationFile.getAbsoluteFile()));
    final Collection<PwmEnvironment.ApplicationFlag> applicationFlags = parameterReader.readApplicationFlags();
    final Map<PwmEnvironment.ApplicationParameter, String> applicationParams = parameterReader.readApplicationParams();
    try {
        final PwmEnvironment pwmEnvironment = new PwmEnvironment.Builder(configuration, applicationPath).setApplicationMode(mode).setConfigurationFile(configurationFile).setContextManager(this).setFlags(applicationFlags).setParams(applicationParams).createPwmEnvironment();
        pwmApplication = new PwmApplication(pwmEnvironment);
    } catch (Exception e) {
        handleStartupError("unable to initialize application: ", e);
    }
    final String threadName = JavaHelper.makeThreadName(pwmApplication, this.getClass()) + " timer";
    taskMaster = new Timer(threadName, true);
    taskMaster.schedule(new RestartFlagWatcher(), 1031, 1031);
    boolean reloadOnChange = true;
    long fileScanFrequencyMs = 5000;
    {
        if (pwmApplication != null) {
            reloadOnChange = Boolean.parseBoolean(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_RELOAD_ON_CHANGE));
            fileScanFrequencyMs = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_FILE_SCAN_FREQUENCY));
        }
        if (reloadOnChange) {
            taskMaster.schedule(new ConfigFileWatcher(), fileScanFrequencyMs, fileScanFrequencyMs);
        }
        checkConfigForSaveOnRestart(configReader, pwmApplication);
    }
}
Also used : PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) PwmEnvironment(password.pwm.PwmEnvironment) PwmApplicationMode(password.pwm.PwmApplicationMode) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) Timer(java.util.Timer) File(java.io.File) ConfigurationReader(password.pwm.config.stored.ConfigurationReader)

Example 3 with ErrorInformation

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

the class StoredConfigurationImpl method setPassword.

public void setPassword(final String password) throws PwmOperationalException {
    if (password == null || password.isEmpty()) {
        throw new PwmOperationalException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "can not set blank password" }));
    }
    final String trimmedPassword = password.trim();
    if (trimmedPassword.length() < 1) {
        throw new PwmOperationalException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "can not set blank password" }));
    }
    final String passwordHash = BCrypt.hashPassword(password);
    this.writeConfigProperty(ConfigurationProperty.PASSWORD_HASH, passwordHash);
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 4 with ErrorInformation

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

the class StoredConfigurationImpl method fromXml.

public static StoredConfigurationImpl fromXml(final InputStream xmlData) throws PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    // validateXmlSchema(xmlData);
    final Document inputDocument = XmlUtil.parseXml(xmlData);
    final StoredConfigurationImpl newConfiguration = StoredConfigurationImpl.newStoredConfiguration();
    try {
        newConfiguration.document = inputDocument;
        // verify create time;
        newConfiguration.createTime();
        ConfigurationCleaner.cleanup(newConfiguration);
    } catch (Exception e) {
        final String errorMsg = "error reading configuration file format, error=" + e.getMessage();
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { errorMsg });
        throw new PwmUnrecoverableException(errorInfo);
    }
    checkIfXmlRequiresUpdate(newConfiguration);
    LOGGER.debug("successfully loaded configuration (" + TimeDuration.compactFromCurrent(startTime) + ")");
    return newConfiguration;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) Instant(java.time.Instant) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) Document(org.jdom2.Document) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 5 with ErrorInformation

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

the class AbstractValue method encryptPwValue.

static String encryptPwValue(final String input, final PwmSecurityKey pwmSecurityKey) throws PwmOperationalException {
    if (input == null) {
        return "";
    }
    if (!input.startsWith(ENC_PW_PREFIX)) {
        try {
            final String salt = PwmRandom.getInstance().alphaNumericString(32);
            final StoredPwData storedPwData = new StoredPwData(salt, input);
            final String jsonData = JsonUtil.serialize(storedPwData);
            final String encryptedValue = SecureEngine.encryptToString(jsonData, pwmSecurityKey, PwmBlockAlgorithm.CONFIG);
            return ENC_PW_PREFIX + encryptedValue;
        } catch (Exception e) {
            final String errorMsg = "unable to encrypt password value for setting: " + e.getMessage();
            final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, errorMsg);
            throw new PwmOperationalException(errorInfo);
        }
    }
    return input;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmOperationalException(password.pwm.error.PwmOperationalException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Aggregations

ErrorInformation (password.pwm.error.ErrorInformation)325 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)216 PwmOperationalException (password.pwm.error.PwmOperationalException)125 PwmException (password.pwm.error.PwmException)67 UserIdentity (password.pwm.bean.UserIdentity)62 IOException (java.io.IOException)58 PwmApplication (password.pwm.PwmApplication)54 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)53 ChaiUser (com.novell.ldapchai.ChaiUser)38 PwmSession (password.pwm.http.PwmSession)38 LinkedHashMap (java.util.LinkedHashMap)35 Configuration (password.pwm.config.Configuration)33 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)32 Map (java.util.Map)32 Instant (java.time.Instant)30 ArrayList (java.util.ArrayList)30 FormConfiguration (password.pwm.config.value.data.FormConfiguration)29 ServletException (javax.servlet.ServletException)28 RestResultBean (password.pwm.ws.server.RestResultBean)26 UserInfo (password.pwm.ldap.UserInfo)23