Search in sources :

Example 16 with MacroMachine

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;
}
Also used : Locale(java.util.Locale) ChangePasswordBean(password.pwm.http.bean.ChangePasswordBean) MacroMachine(password.pwm.util.macro.MacroMachine) TimeDuration(password.pwm.util.java.TimeDuration) PasswordChangeProgressChecker(password.pwm.ldap.PasswordChangeProgressChecker) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmDataValidationException(password.pwm.error.PwmDataValidationException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) IOException(java.io.IOException)

Example 17 with MacroMachine

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) MacroMachine(password.pwm.util.macro.MacroMachine)

Example 18 with MacroMachine

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);
}
Also used : HashMap(java.util.HashMap) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) UpdateProfileProfile(password.pwm.config.profile.UpdateProfileProfile) List(java.util.List) FormConfiguration(password.pwm.config.value.data.FormConfiguration) UserInfo(password.pwm.ldap.UserInfo) FormMap(password.pwm.util.FormMap)

Example 19 with MacroMachine

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);
    }
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) Instant(java.time.Instant) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo) PublicUserInfoBean(password.pwm.bean.pub.PublicUserInfoBean) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) RestResultBean(password.pwm.ws.server.RestResultBean) RestMethodHandler(password.pwm.ws.server.RestMethodHandler)

Example 20 with MacroMachine

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);
}
Also used : MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo) PublicUserInfoBean(password.pwm.bean.pub.PublicUserInfoBean) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

MacroMachine (password.pwm.util.macro.MacroMachine)61 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)22 ErrorInformation (password.pwm.error.ErrorInformation)20 Locale (java.util.Locale)16 PwmOperationalException (password.pwm.error.PwmOperationalException)15 Configuration (password.pwm.config.Configuration)13 UserInfo (password.pwm.ldap.UserInfo)13 ArrayList (java.util.ArrayList)12 LinkedHashMap (java.util.LinkedHashMap)12 PwmApplication (password.pwm.PwmApplication)12 FormConfiguration (password.pwm.config.value.data.FormConfiguration)12 ChaiUser (com.novell.ldapchai.ChaiUser)10 PwmException (password.pwm.error.PwmException)10 List (java.util.List)9 EmailItemBean (password.pwm.bean.EmailItemBean)9 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)8 Map (java.util.Map)8 ActionConfiguration (password.pwm.config.value.data.ActionConfiguration)8 PwmSession (password.pwm.http.PwmSession)8 Instant (java.time.Instant)7