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