use of password.pwm.error.PwmException in project pwm by pwm-project.
the class RestStatusServer method doGetStatusData.
@RestMethodHandler(method = HttpMethod.GET, produces = HttpContentType.json, consumes = HttpContentType.json)
public RestResultBean doGetStatusData(final RestRequest restRequest) throws PwmUnrecoverableException {
final Instant startTime = Instant.now();
final String username = restRequest.readParameterAsString("username");
final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, username);
try {
final ChaiProvider chaiProvider = targetUserIdentity.getChaiProvider();
final UserInfo userInfo = UserInfoFactory.newUserInfo(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), targetUserIdentity.getUserIdentity(), chaiProvider);
final MacroMachine macroMachine = MacroMachine.forUser(restRequest.getPwmApplication(), restRequest.getLocale(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity());
final PublicUserInfoBean publicUserInfoBean = PublicUserInfoBean.fromUserInfoBean(userInfo, restRequest.getPwmApplication().getConfig(), restRequest.getLocale(), macroMachine);
StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_STATUS);
final RestResultBean restResultBean = RestResultBean.withData(publicUserInfoBean);
LOGGER.debug(restRequest.getSessionLabel(), "completed REST status request in " + TimeDuration.compactFromCurrent(startTime) + ", result=" + JsonUtil.serialize(restResultBean));
return restResultBean;
} catch (PwmException e) {
return RestResultBean.fromError(e.getErrorInformation());
} catch (Exception e) {
final String errorMsg = "unexpected error building json response: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
return RestResultBean.fromError(restRequest, errorInformation);
}
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class LdapCertImportFunction method provideFunction.
@Override
public String provideFunction(final PwmRequest pwmRequest, final StoredConfigurationImpl storedConfiguration, final PwmSetting setting, final String profile, final String extraData) throws PwmOperationalException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final StringArrayValue ldapUrlsValue = (StringArrayValue) storedConfiguration.readSetting(PwmSetting.LDAP_SERVER_URLS, profile);
final Set<X509Certificate> resultCertificates = new LinkedHashSet<>();
try {
if (ldapUrlsValue != null && ldapUrlsValue.toNativeObject() != null) {
final List<String> ldapUrlStrings = ldapUrlsValue.toNativeObject();
for (final String ldapUrlString : ldapUrlStrings) {
final URI ldapURI = new URI(ldapUrlString);
final List<X509Certificate> certs = X509Utils.readRemoteCertificates(ldapURI);
if (certs != null) {
resultCertificates.addAll(certs);
}
}
}
} catch (Exception e) {
if (e instanceof PwmException) {
throw new PwmOperationalException(((PwmException) e).getErrorInformation());
}
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error importing certificates: " + e.getMessage());
throw new PwmOperationalException(errorInformation);
}
final UserIdentity userIdentity = pwmSession.isAuthenticated() ? pwmSession.getUserInfo().getUserIdentity() : null;
storedConfiguration.writeSetting(setting, profile, new X509CertificateValue(resultCertificates), userIdentity);
return Message.getLocalizedMessage(pwmSession.getSessionStateBean().getLocale(), Message.Success_Unknown, pwmApplication.getConfig());
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class SyslogCertImportFunction method provideFunction.
@Override
public String provideFunction(final PwmRequest pwmRequest, final StoredConfigurationImpl storedConfiguration, final PwmSetting setting, final String profile, final String extraData) throws PwmOperationalException, PwmUnrecoverableException {
boolean error = false;
Exception exeception = null;
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final Set<X509Certificate> resultCertificates = new LinkedHashSet<>();
final List<String> syslogConfigStrs = (List<String>) storedConfiguration.readSetting(PwmSetting.AUDIT_SYSLOG_SERVERS).toNativeObject();
if (syslogConfigStrs != null && !syslogConfigStrs.isEmpty()) {
for (String entry : syslogConfigStrs) {
if (entry.toUpperCase().startsWith("TLS")) {
final SyslogAuditService.SyslogConfig syslogConfig = SyslogAuditService.SyslogConfig.fromConfigString(entry);
if (syslogConfig != null) {
try {
final List<X509Certificate> certs = X509Utils.readRemoteCertificates(syslogConfig.getHost(), syslogConfig.getPort());
if (certs != null) {
resultCertificates.addAll(certs);
error = false;
}
} catch (Exception e) {
error = true;
exeception = e;
}
}
}
}
}
if (!error) {
final UserIdentity userIdentity = pwmSession.isAuthenticated() ? pwmSession.getUserInfo().getUserIdentity() : null;
storedConfiguration.writeSetting(setting, new X509CertificateValue(resultCertificates), userIdentity);
return Message.getLocalizedMessage(pwmSession.getSessionStateBean().getLocale(), Message.Success_Unknown, pwmApplication.getConfig());
} else {
if (exeception instanceof PwmException) {
throw new PwmOperationalException(((PwmException) exeception).getErrorInformation());
}
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error importing certificates: " + exeception.getMessage());
throw new PwmOperationalException(errorInformation);
}
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class UpdateProfileServlet method nextStep.
protected void nextStep(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final UpdateProfileBean updateProfileBean = getBean(pwmRequest);
final UpdateProfileProfile updateProfileProfile = getProfile(pwmRequest);
final PwmSession pwmSession = pwmRequest.getPwmSession();
{
final String updateProfileAgreementText = updateProfileProfile.readSettingAsLocalizedString(PwmSetting.UPDATE_PROFILE_AGREEMENT_MESSAGE, pwmSession.getSessionStateBean().getLocale());
if (!StringUtil.isEmpty(updateProfileAgreementText)) {
if (!updateProfileBean.isAgreementPassed()) {
final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
final String expandedText = macroMachine.expandMacros(updateProfileAgreementText);
pwmRequest.setAttribute(PwmRequestAttribute.AgreementText, expandedText);
pwmRequest.forwardToJsp(JspUrl.UPDATE_ATTRIBUTES_AGREEMENT);
return;
}
}
}
// make sure there is form data in the bean.
if (!updateProfileBean.isFormLdapLoaded()) {
updateProfileBean.getFormData().clear();
updateProfileBean.getFormData().putAll((UpdateProfileUtil.formDataFromLdap(pwmRequest, updateProfileProfile)));
updateProfileBean.setFormLdapLoaded(true);
UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
return;
}
if (!updateProfileBean.isFormSubmitted()) {
UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
return;
}
// validate the form data.
try {
// verify form meets the form requirements
final List<FormConfiguration> formFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
final Map<FormConfiguration, String> formValues = FormUtility.readFormValuesFromMap(updateProfileBean.getFormData(), formFields, pwmRequest.getLocale());
UpdateProfileUtil.verifyFormAttributes(pwmRequest.getPwmApplication(), pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getLocale(), formValues, true);
} catch (PwmException e) {
LOGGER.error(pwmSession, e.getMessage());
setLastError(pwmRequest, e.getErrorInformation());
UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
return;
}
{
final boolean requireConfirmation = updateProfileProfile.readSettingAsBoolean(PwmSetting.UPDATE_PROFILE_SHOW_CONFIRMATION);
if (requireConfirmation && !updateProfileBean.isConfirmationPassed()) {
UpdateProfileUtil.forwardToConfirmForm(pwmRequest, updateProfileProfile, updateProfileBean);
return;
}
}
if (UpdateProfileUtil.checkForTokenVerificationProgress(pwmRequest, updateProfileBean, updateProfileProfile) == ProcessStatus.Halt) {
return;
}
try {
// write the form values
final ChaiUser theUser = pwmSession.getSessionManager().getActor(pwmApplication);
UpdateProfileUtil.doProfileUpdate(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), pwmRequest.getLocale(), pwmSession.getUserInfo(), pwmSession.getSessionManager().getMacroMachine(pwmApplication), updateProfileProfile, updateProfileBean.getFormData(), theUser);
// re-populate the uiBean because we have changed some values.
pwmSession.reloadUserInfoBean(pwmApplication);
// clear cached read attributes.
pwmRequest.getPwmSession().reloadUserInfoBean(pwmApplication);
// mark the event log
pwmApplication.getAuditManager().submit(AuditEvent.UPDATE_PROFILE, pwmSession.getUserInfo(), pwmSession);
// clear the bean
pwmApplication.getSessionStateService().clearBean(pwmRequest, UpdateProfileBean.class);
pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_UpdateProfile);
return;
} catch (PwmException e) {
LOGGER.error(pwmSession, e.getMessage());
setLastError(pwmRequest, e.getErrorInformation());
} catch (ChaiException e) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UPDATE_ATTRS_FAILURE, e.toString());
LOGGER.error(pwmSession, errorInformation.toDebugStr());
setLastError(pwmRequest, errorInformation);
}
UpdateProfileUtil.forwardToForm(pwmRequest, updateProfileProfile, updateProfileBean);
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class PeopleSearchServlet method restOrgChartData.
@ActionHandler(action = "orgChartData")
private ProcessStatus restOrgChartData(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException, ServletException {
final PeopleSearchConfiguration peopleSearchConfiguration = PeopleSearchConfiguration.fromConfiguration(pwmRequest.getPwmApplication());
if (!peopleSearchConfiguration.isOrgChartEnabled()) {
throw new PwmUnrecoverableException(PwmError.ERROR_SERVICE_NOT_AVAILABLE);
}
final UserIdentity userIdentity;
{
final String userKey = pwmRequest.readParameterAsString(PARAM_USERKEY, PwmHttpRequestWrapper.Flag.BypassValidation);
if (userKey == null || userKey.isEmpty()) {
userIdentity = pwmRequest.getUserInfoIfLoggedIn();
if (userIdentity == null) {
return ProcessStatus.Halt;
}
} else {
userIdentity = UserIdentity.fromObfuscatedKey(userKey, pwmRequest.getPwmApplication());
}
}
final boolean noChildren = pwmRequest.readParameterAsBoolean("noChildren");
try {
final PeopleSearchDataReader peopleSearchDataReader = new PeopleSearchDataReader(pwmRequest);
final OrgChartDataBean orgChartData = peopleSearchDataReader.makeOrgChartData(userIdentity, noChildren);
addExpiresHeadersToResponse(pwmRequest);
pwmRequest.outputJsonResult(RestResultBean.withData(orgChartData));
StatisticsManager.incrementStat(pwmRequest, Statistic.PEOPLESEARCH_ORGCHART);
} catch (PwmException e) {
LOGGER.error(pwmRequest, "error generating user detail object: " + e.getMessage());
pwmRequest.respondWithError(e.getErrorInformation());
}
return ProcessStatus.Halt;
}
Aggregations