use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.
the class ChangePasswordServlet method processCompleteAction.
@ActionHandler(action = "complete")
public ProcessStatus processCompleteAction(final PwmRequest pwmRequest) throws ServletException, PwmUnrecoverableException, IOException {
final ChangePasswordBean cpb = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ChangePasswordBean.class);
final PasswordChangeProgressChecker.ProgressTracker progressTracker = cpb.getChangeProgressTracker();
boolean isComplete = true;
if (progressTracker != null) {
final PasswordChangeProgressChecker checker = new PasswordChangeProgressChecker(pwmRequest.getPwmApplication(), pwmRequest.getPwmSession().getUserInfo().getUserIdentity(), pwmRequest.getSessionLabel(), pwmRequest.getLocale());
final PasswordChangeProgressChecker.PasswordChangeProgress passwordChangeProgress = checker.figureProgress(progressTracker);
isComplete = passwordChangeProgress.isComplete();
}
if (isComplete) {
if (progressTracker != null) {
final TimeDuration totalTime = TimeDuration.fromCurrent(progressTracker.getBeginTime());
try {
pwmRequest.getPwmApplication().getStatisticsManager().updateAverageValue(Statistic.AVG_PASSWORD_SYNC_TIME, totalTime.getTotalMilliseconds());
LOGGER.trace(pwmRequest, "password sync process marked completed (" + totalTime.asCompactString() + ")");
} catch (Exception e) {
LOGGER.error(pwmRequest, "unable to update average password sync time statistic: " + e.getMessage());
}
}
cpb.setChangeProgressTracker(null);
final Locale locale = pwmRequest.getLocale();
final String completeMessage = pwmRequest.getConfig().readSettingAsLocalizedString(PwmSetting.PASSWORD_COMPLETE_MESSAGE, locale);
pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, ChangePasswordBean.class);
if (completeMessage != null && !completeMessage.isEmpty()) {
final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
final String expandedText = macroMachine.expandMacros(completeMessage);
pwmRequest.setAttribute(PwmRequestAttribute.CompleteText, expandedText);
pwmRequest.forwardToJsp(JspUrl.PASSWORD_COMPLETE);
} else {
pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_PasswordChange);
}
} else {
forwardToWaitPage(pwmRequest);
}
return ProcessStatus.Halt;
}
use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.
the class ForgottenUsernameServlet method sendSmsViaMethod.
private static ErrorInformation sendSmsViaMethod(final PwmApplication pwmApplication, final SessionLabel sessionLabel, final UserInfo userInfo, final String smsMessage) throws PwmOperationalException, PwmUnrecoverableException {
final String toNumber = userInfo.getUserSmsNumber();
if (toNumber == null || toNumber.length() < 1) {
final String errorMsg = String.format("unable to send new password email for '%s'; no SMS number available in ldap", userInfo.getUserIdentity());
return new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
}
final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, sessionLabel, userInfo, null);
pwmApplication.sendSmsUsingQueue(toNumber, smsMessage, sessionLabel, macroMachine);
return null;
}
use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.
the class RestProfileServer method doPostProfileDataImpl.
private static RestResultBean doPostProfileDataImpl(final RestRequest restRequest, final JsonProfileData jsonInput) throws PwmUnrecoverableException, ChaiUnavailableException, PwmOperationalException {
final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, jsonInput.getUsername());
final String updateProfileID = ProfileUtility.discoverProfileIDforUser(restRequest.getPwmApplication(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), ProfileType.UpdateAttributes);
if (StringUtil.isEmpty(updateProfileID)) {
throw new PwmUnrecoverableException(PwmError.ERROR_NO_PROFILE_ASSIGNED);
}
final UpdateProfileProfile updateProfileProfile = restRequest.getPwmApplication().getConfig().getUpdateAttributesProfile().get(updateProfileID);
{
final List<UserPermission> userPermission = updateProfileProfile.readSettingAsUserPermission(PwmSetting.UPDATE_PROFILE_QUERY_MATCH);
final boolean result = LdapPermissionTester.testUserPermissions(restRequest.getPwmApplication(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), userPermission);
if (!result) {
throw new PwmUnrecoverableException(PwmError.ERROR_UNAUTHORIZED);
}
}
final FormMap inputFormData = new FormMap(jsonInput.profile);
final List<FormConfiguration> profileForm = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
final Map<FormConfiguration, String> profileFormData = new HashMap<>();
for (final FormConfiguration formConfiguration : profileForm) {
if (!formConfiguration.isReadonly() && inputFormData.containsKey(formConfiguration.getName())) {
profileFormData.put(formConfiguration, inputFormData.get(formConfiguration.getName()));
}
}
final UserInfo userInfo = UserInfoFactory.newUserInfo(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), targetUserIdentity.getUserIdentity(), targetUserIdentity.getChaiProvider());
final MacroMachine macroMachine = MacroMachine.forUser(restRequest.getPwmApplication(), restRequest.getLocale(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity());
UpdateProfileUtil.doProfileUpdate(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), userInfo, macroMachine, updateProfileProfile, FormUtility.asStringMap(profileFormData), targetUserIdentity.getChaiUser());
StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_PROFILE);
return RestResultBean.forSuccessMessage(restRequest, Message.Success_UpdateProfile);
}
use of password.pwm.util.macro.MacroMachine 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.util.macro.MacroMachine in project pwm by pwm-project.
the class RestTokenDataClient method invoke.
private TokenDestinationData invoke(final SessionLabel sessionLabel, final TokenDestinationData tokenDestinationData, final UserIdentity userIdentity, final String url, final Locale locale) throws PwmOperationalException, ChaiUnavailableException, PwmUnrecoverableException {
if (tokenDestinationData == null) {
throw new NullPointerException("tokenDestinationData can not be null");
}
final Map<String, Object> sendData = new LinkedHashMap<>();
sendData.put(DATA_KEY_TOKENDATA, tokenDestinationData);
if (userIdentity != null) {
final UserInfo userInfo = UserInfoFactory.newUserInfoUsingProxy(pwmApplication, sessionLabel, userIdentity, locale);
final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, PwmConstants.DEFAULT_LOCALE, SessionLabel.SYSTEM_LABEL, userInfo.getUserIdentity());
final PublicUserInfoBean publicUserInfoBean = PublicUserInfoBean.fromUserInfoBean(userInfo, pwmApplication.getConfig(), PwmConstants.DEFAULT_LOCALE, macroMachine);
sendData.put(RestClient.DATA_KEY_USERINFO, publicUserInfoBean);
}
final String jsonRequestData = JsonUtil.serializeMap(sendData);
final String responseBody = RestClientHelper.makeOutboundRestWSCall(pwmApplication, locale, url, jsonRequestData);
return JsonUtil.deserialize(responseBody, TokenDestinationData.class);
}
Aggregations