use of password.pwm.error.PwmException in project pwm by pwm-project.
the class RestRandomPasswordServer method doPostRandomPasswordForm.
@RestMethodHandler(method = HttpMethod.POST, consumes = HttpContentType.form, produces = HttpContentType.json)
public RestResultBean doPostRandomPasswordForm(final RestRequest restRequest) throws PwmUnrecoverableException {
final JsonInput jsonInput = new JsonInput();
jsonInput.username = restRequest.readParameterAsString("username", PwmHttpRequestWrapper.Flag.BypassValidation);
jsonInput.strength = restRequest.readParameterAsInt("strength", 0);
jsonInput.maxLength = restRequest.readParameterAsInt("maxLength", 0);
jsonInput.minLength = restRequest.readParameterAsInt("minLength", 0);
jsonInput.chars = restRequest.readParameterAsString("chars", PwmHttpRequestWrapper.Flag.BypassValidation);
jsonInput.noUser = restRequest.readParameterAsBoolean("noUser");
try {
final JsonOutput jsonOutput = doOperation(restRequest, jsonInput);
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
return restResultBean;
} catch (PwmException e) {
LOGGER.error(restRequest.getSessionLabel(), "error executing rest-json random password request: " + e.getMessage(), e);
return RestResultBean.fromError(restRequest, e.getErrorInformation());
} catch (Exception e) {
final String errorMessage = "unexpected error executing web service: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
return RestResultBean.fromError(restRequest, errorInformation);
}
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class RestSetPasswordServer method doSetPassword.
private static RestResultBean doSetPassword(final RestRequest restRequest, final JsonInputData jsonInputData) {
final String password = jsonInputData.getPassword();
final boolean random = jsonInputData.isRandom();
if ((password == null || password.length() < 1) && !random) {
final String errorMessage = "field '" + FIELD_PASSWORD + "' must have a value or field '" + FIELD_RANDOM + "' must be set to true";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_PARAMETER, errorMessage, new String[] { FIELD_PASSWORD });
return RestResultBean.fromError(restRequest, errorInformation);
}
if ((password != null && password.length() > 0) && random) {
final String errorMessage = "field '" + FIELD_PASSWORD + "' cannot have a value or field '" + FIELD_RANDOM + "' must be set to true";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_PARAMETER, errorMessage, new String[] { FIELD_PASSWORD });
return RestResultBean.fromError(restRequest, errorInformation);
}
try {
final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, jsonInputData.username);
final PasswordData newPassword;
if (random) {
final PwmPasswordPolicy passwordPolicy = PasswordUtility.readPasswordPolicyForUser(restRequest.getPwmApplication(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), targetUserIdentity.getChaiUser(), restRequest.getLocale());
newPassword = RandomPasswordGenerator.createRandomPassword(restRequest.getSessionLabel(), passwordPolicy, restRequest.getPwmApplication());
} else {
newPassword = new PasswordData(password);
}
final PasswordData oldPassword;
if (targetUserIdentity.isSelf()) {
final BasicAuthInfo basicAuthInfo = BasicAuthInfo.parseAuthHeader(restRequest.getPwmApplication(), restRequest.getHttpServletRequest());
oldPassword = basicAuthInfo == null ? null : basicAuthInfo.getPassword();
} else {
oldPassword = null;
}
final UserInfo userInfo = UserInfoFactory.newUserInfoUsingProxy(restRequest.getPwmApplication(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), restRequest.getLocale());
PasswordUtility.setPassword(restRequest.getPwmApplication(), restRequest.getSessionLabel(), targetUserIdentity.getChaiProvider(), userInfo, oldPassword, newPassword);
StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_SETPASSWORD);
final JsonInputData jsonResultData = new JsonInputData(targetUserIdentity.getUserIdentity().toDelimitedKey(), null, random);
return RestResultBean.forSuccessMessage(jsonResultData, restRequest, Message.Success_PasswordChange);
} catch (PwmException e) {
LOGGER.error("error during set password REST operation: " + e.getMessage());
return RestResultBean.fromError(restRequest, e.getErrorInformation());
} catch (Exception e) {
final String errorMessage = "unexpected error executing web service: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
LOGGER.error("error during set password REST operation: " + e.getMessage(), e);
return RestResultBean.fromError(restRequest, errorInformation);
}
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class ContextManager method handleStartupError.
private void handleStartupError(final String msgPrefix, final Throwable throwable) {
final String errorMsg;
if (throwable instanceof OutOfMemoryError) {
errorMsg = "JAVA OUT OF MEMORY ERROR!, please allocate more memory for java: " + throwable.getMessage();
startupErrorInformation = new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, errorMsg);
} else if (throwable instanceof PwmException) {
startupErrorInformation = ((PwmException) throwable).getErrorInformation().wrapWithNewErrorCode(PwmError.ERROR_STARTUP_ERROR);
} else {
errorMsg = throwable.getMessage();
startupErrorInformation = new ErrorInformation(PwmError.ERROR_APP_UNAVAILABLE, msgPrefix + errorMsg);
throwable.printStackTrace();
}
try {
LOGGER.fatal(startupErrorInformation.getDetailedErrorMsg());
} catch (Exception e2) {
// noop
}
outputError(startupErrorInformation.getDetailedErrorMsg());
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class ConfigurationChecker method doHealthCheck.
public List<HealthRecord> doHealthCheck(final Configuration config, final Locale locale) {
final List<HealthRecord> records = new ArrayList<>();
if (config.readSettingAsBoolean(PwmSetting.HIDE_CONFIGURATION_HEALTH_WARNINGS)) {
return records;
}
records.addAll(allChecks(config, locale));
final String siteUrl = config.readSettingAsString(PwmSetting.PWM_SITE_URL);
final String separator = LocaleHelper.getLocalizedMessage(locale, Config.Display_SettingNavigationSeparator, null);
try {
if (siteUrl == null || siteUrl.isEmpty() || siteUrl.equals(PwmSetting.PWM_SITE_URL.getDefaultValue(config.getTemplate()).toNativeObject())) {
records.add(HealthRecord.forMessage(HealthMessage.Config_NoSiteURL, PwmSetting.PWM_SITE_URL.toMenuLocationDebug(null, locale)));
}
} catch (PwmException e) {
LOGGER.error(SessionLabel.HEALTH_SESSION_LABEL, "error while inspecting site URL setting: " + e.getMessage());
}
if (config.readSettingAsBoolean(PwmSetting.LDAP_ENABLE_WIRE_TRACE)) {
records.add(HealthRecord.forMessage(HealthMessage.Config_LDAPWireTrace, PwmSetting.LDAP_ENABLE_WIRE_TRACE.toMenuLocationDebug(null, locale)));
}
if (Boolean.parseBoolean(config.readAppProperty(AppProperty.LDAP_PROMISCUOUS_ENABLE))) {
final String appPropertyKey = "AppProperty" + separator + AppProperty.LDAP_PROMISCUOUS_ENABLE.getKey();
records.add(HealthRecord.forMessage(HealthMessage.Config_PromiscuousLDAP, appPropertyKey));
}
if (config.readSettingAsBoolean(PwmSetting.DISPLAY_SHOW_DETAILED_ERRORS)) {
records.add(HealthRecord.forMessage(HealthMessage.Config_ShowDetailedErrors, PwmSetting.DISPLAY_SHOW_DETAILED_ERRORS.toMenuLocationDebug(null, locale)));
}
for (final LdapProfile ldapProfile : config.getLdapProfiles().values()) {
final String testUserDN = ldapProfile.readSettingAsString(PwmSetting.LDAP_TEST_USER_DN);
if (testUserDN == null || testUserDN.length() < 1) {
records.add(HealthRecord.forMessage(HealthMessage.Config_AddTestUser, PwmSetting.LDAP_TEST_USER_DN.toMenuLocationDebug(ldapProfile.getIdentifier(), locale)));
}
}
for (final LdapProfile ldapProfile : config.getLdapProfiles().values()) {
final List<String> ldapServerURLs = ldapProfile.readSettingAsStringArray(PwmSetting.LDAP_SERVER_URLS);
if (ldapServerURLs != null && !ldapServerURLs.isEmpty()) {
for (final String urlStringValue : ldapServerURLs) {
try {
final URI url = new URI(urlStringValue);
final boolean secure = "ldaps".equalsIgnoreCase(url.getScheme());
if (!secure) {
records.add(HealthRecord.forMessage(HealthMessage.Config_LDAPUnsecure, PwmSetting.LDAP_SERVER_URLS.toMenuLocationDebug(ldapProfile.getIdentifier(), locale)));
}
} catch (URISyntaxException e) {
records.add(HealthRecord.forMessage(HealthMessage.Config_ParseError, e.getMessage(), PwmSetting.LDAP_SERVER_URLS.toMenuLocationDebug(ldapProfile.getIdentifier(), locale), urlStringValue));
}
}
}
}
records.addAll(passwordStrengthChecks(config, locale));
return records;
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class PwmApplication method postInitTasks.
private void postInitTasks() {
final Instant startTime = Instant.now();
LOGGER.debug("loaded configuration: " + pwmEnvironment.getConfig().toDebugString());
// detect if config has been modified since previous startup
try {
final String previousHash = readAppAttribute(AppAttribute.CONFIG_HASH, String.class);
final String currentHash = pwmEnvironment.getConfig().configurationHash();
if (previousHash == null || !previousHash.equals(currentHash)) {
writeAppAttribute(AppAttribute.CONFIG_HASH, currentHash);
LOGGER.warn("configuration checksum does not match previously seen checksum, configuration has been modified since last startup");
if (this.getAuditManager() != null) {
final String modifyMessage = "configuration was modified directly (not using ConfigEditor UI)";
this.getAuditManager().submit(new AuditRecordFactory(this).createUserAuditRecord(AuditEvent.MODIFY_CONFIGURATION, null, null, modifyMessage));
}
}
} catch (Exception e) {
LOGGER.debug("unable to detect if configuration has been modified since previous startup: " + e.getMessage());
}
if (this.getConfig() != null) {
final Map<AppProperty, String> nonDefaultProperties = getConfig().readAllNonDefaultAppProperties();
if (nonDefaultProperties != null && !nonDefaultProperties.isEmpty()) {
final Map<String, String> tempMap = new LinkedHashMap<>();
for (final Map.Entry<AppProperty, String> entry : nonDefaultProperties.entrySet()) {
tempMap.put(entry.getKey().getKey(), entry.getValue());
}
LOGGER.trace("non-default app properties read from configuration: " + JsonUtil.serializeMap(tempMap));
} else {
LOGGER.trace("no non-default app properties in configuration");
}
}
// send system audit event
try {
final SystemAuditRecord auditRecord = new AuditRecordFactory(this).createSystemAuditRecord(AuditEvent.STARTUP, null);
getAuditManager().submit(auditRecord);
} catch (PwmException e) {
LOGGER.warn("unable to submit start alert event " + e.getMessage());
}
try {
final Map<PwmAboutProperty, String> infoMap = PwmAboutProperty.makeInfoBean(this);
LOGGER.trace("application info: " + JsonUtil.serializeMap(infoMap));
} catch (Exception e) {
LOGGER.error("error generating about application bean: " + e.getMessage(), e);
}
try {
this.getIntruderManager().clear(RecordType.USERNAME, PwmConstants.CONFIGMANAGER_INTRUDER_USERNAME);
} catch (Exception e) {
LOGGER.warn("error while clearing configmanager-intruder-username from intruder table: " + e.getMessage());
}
if (!pwmEnvironment.isInternalRuntimeInstance()) {
try {
outputKeystore(this);
} catch (Exception e) {
LOGGER.debug("error while generating keystore output: " + e.getMessage());
}
try {
outputTomcatConf(this);
} catch (Exception e) {
LOGGER.debug("error while generating tomcat conf output: " + e.getMessage());
}
}
LOGGER.trace("completed post init tasks in " + TimeDuration.fromCurrent(startTime).asCompactString());
}
Aggregations