Search in sources :

Example 56 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class HelpdeskServletUtil method sendUnlockNoticeEmail.

static void sendUnlockNoticeEmail(final PwmRequest pwmRequest, final HelpdeskProfile helpdeskProfile, final UserIdentity userIdentity, final ChaiUser chaiUser) throws PwmUnrecoverableException, ChaiUnavailableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final Configuration config = pwmRequest.getConfig();
    final Locale locale = pwmRequest.getLocale();
    final EmailItemBean configuredEmailSetting = config.readSettingAsEmail(PwmSetting.EMAIL_HELPDESK_UNLOCK, locale);
    if (configuredEmailSetting == null) {
        LOGGER.debug(pwmRequest, "skipping send helpdesk unlock notice email for '" + userIdentity + "' no email configured");
        return;
    }
    final UserInfo userInfo = UserInfoFactory.newUserInfo(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), pwmRequest.getLocale(), userIdentity, chaiUser.getChaiProvider());
    final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, pwmRequest.getSessionLabel(), userInfo, null);
    pwmApplication.getEmailQueue().submitEmail(configuredEmailSetting, userInfo, macroMachine);
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) EmailItemBean(password.pwm.bean.EmailItemBean) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo)

Example 57 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class ChangePasswordServlet method forwardToChangePage.

private void forwardToChangePage(final PwmRequest pwmRequest) throws ServletException, PwmUnrecoverableException, IOException {
    final String passwordPolicyChangeMessage = pwmRequest.getPwmSession().getUserInfo().getPasswordPolicy().getRuleHelper().getChangeMessage();
    if (passwordPolicyChangeMessage.length() > 1) {
        final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
        macroMachine.expandMacros(passwordPolicyChangeMessage);
        pwmRequest.setAttribute(PwmRequestAttribute.ChangePassword_PasswordPolicyChangeMessage, passwordPolicyChangeMessage);
    }
    pwmRequest.forwardToJsp(JspUrl.PASSWORD_CHANGE);
}
Also used : MacroMachine(password.pwm.util.macro.MacroMachine)

Example 58 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class AccountInformationBean method makePasswordRules.

private static List<String> makePasswordRules(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
    final PwmPasswordPolicy pwmPasswordPolicy = pwmRequest.getPwmSession().getUserInfo().getPasswordPolicy();
    final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
    final List<String> rules = PasswordRequirementsTag.getPasswordRequirementsStrings(pwmPasswordPolicy, pwmRequest.getConfig(), pwmRequest.getLocale(), macroMachine);
    return Collections.unmodifiableList(rules);
}
Also used : PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) MacroMachine(password.pwm.util.macro.MacroMachine)

Example 59 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class UserDebugDataReader method readUserDebugData.

public static UserDebugDataBean readUserDebugData(final PwmApplication pwmApplication, final Locale locale, final SessionLabel sessionLabel, final UserIdentity userIdentity) throws PwmUnrecoverableException {
    final UserInfo userInfo = UserInfoFactory.newUserInfoUsingProxy(pwmApplication, sessionLabel, userIdentity, locale);
    final Map<Permission, String> permissions = UserDebugDataReader.permissionMap(pwmApplication, sessionLabel, userIdentity);
    final Map<ProfileType, String> profiles = UserDebugDataReader.profileMap(pwmApplication, sessionLabel, userIdentity);
    final PwmPasswordPolicy ldapPasswordPolicy = PasswordUtility.readLdapPasswordPolicy(pwmApplication, pwmApplication.getProxiedChaiUser(userIdentity));
    final PwmPasswordPolicy configPasswordPolicy = PasswordUtility.determineConfiguredPolicyProfileForUser(pwmApplication, sessionLabel, userIdentity, locale);
    boolean readablePassword = false;
    try {
        readablePassword = null != LdapOperationsHelper.readLdapPassword(pwmApplication, sessionLabel, userIdentity);
    } catch (ChaiUnavailableException e) {
    /* disregard */
    }
    final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, locale, sessionLabel, userIdentity);
    final UserDebugDataBean userDebugData = UserDebugDataBean.builder().userInfo(userInfo).publicUserInfoBean(PublicUserInfoBean.fromUserInfoBean(userInfo, pwmApplication.getConfig(), locale, macroMachine)).permissions(permissions).profiles(profiles).ldapPasswordPolicy(ldapPasswordPolicy).configuredPasswordPolicy(configPasswordPolicy).passwordReadable(readablePassword).passwordWithinMinimumLifetime(userInfo.isWithinPasswordMinimumLifetime()).build();
    return userDebugData;
}
Also used : ProfileType(password.pwm.config.profile.ProfileType) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) Permission(password.pwm.Permission) UserPermission(password.pwm.config.value.data.UserPermission) MacroMachine(password.pwm.util.macro.MacroMachine) UserInfo(password.pwm.ldap.UserInfo)

Example 60 with MacroMachine

use of password.pwm.util.macro.MacroMachine in project pwm by pwm-project.

the class ActivateUserUtils method activateUser.

@SuppressFBWarnings("SE_BAD_FIELD")
static void activateUser(final PwmRequest pwmRequest, final UserIdentity userIdentity) throws ChaiUnavailableException, PwmUnrecoverableException, PwmOperationalException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final Configuration config = pwmApplication.getConfig();
    final ChaiUser theUser = pwmApplication.getProxiedChaiUser(userIdentity);
    if (config.readSettingAsBoolean(PwmSetting.ACTIVATE_USER_UNLOCK)) {
        try {
            theUser.unlockPassword();
        } catch (ChaiOperationException e) {
            final String errorMsg = "error unlocking user " + userIdentity + ": " + e.getMessage();
            final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, errorMsg);
            throw new PwmOperationalException(errorInformation);
        }
    }
    try {
        {
            // execute configured actions
            LOGGER.debug(pwmSession.getLabel(), "executing configured pre-actions to user " + theUser.getEntryDN());
            final List<ActionConfiguration> configValues = config.readSettingAsAction(PwmSetting.ACTIVATE_USER_PRE_WRITE_ATTRIBUTES);
            if (configValues != null && !configValues.isEmpty()) {
                final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest, userIdentity);
                final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmApplication, userIdentity).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
                actionExecutor.executeActions(configValues, pwmRequest.getSessionLabel());
            }
        }
        // authenticate the pwm session
        final SessionAuthenticator sessionAuthenticator = new SessionAuthenticator(pwmApplication, pwmSession, PwmAuthenticationSource.USER_ACTIVATION);
        sessionAuthenticator.authUserWithUnknownPassword(userIdentity, AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
        // ensure a change password is triggered
        pwmSession.getLoginInfoBean().setType(AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
        pwmSession.getLoginInfoBean().getAuthFlags().add(AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
        pwmSession.getLoginInfoBean().getLoginFlags().add(LoginInfoBean.LoginFlag.forcePwChange);
        // mark the event log
        pwmApplication.getAuditManager().submit(AuditEvent.ACTIVATE_USER, pwmSession.getUserInfo(), pwmSession);
        // update the stats bean
        pwmApplication.getStatisticsManager().incrementValue(Statistic.ACTIVATED_USERS);
        // send email or sms
        sendPostActivationNotice(pwmRequest);
        // setup post-change attributes
        final PostChangePasswordAction postAction = new PostChangePasswordAction() {

            public String getLabel() {
                return "ActivateUser write attributes";
            }

            public boolean doAction(final PwmSession pwmSession, final String newPassword) throws PwmUnrecoverableException {
                try {
                    {
                        // execute configured actions
                        LOGGER.debug(pwmSession.getLabel(), "executing post-activate configured actions to user " + userIdentity.toDisplayString());
                        final MacroMachine macroMachine = pwmSession.getSessionManager().getMacroMachine(pwmApplication);
                        final List<ActionConfiguration> configValues = pwmApplication.getConfig().readSettingAsAction(PwmSetting.ACTIVATE_USER_POST_WRITE_ATTRIBUTES);
                        final ActionExecutor actionExecutor = new ActionExecutor.ActionExecutorSettings(pwmApplication, userIdentity).setExpandPwmMacros(true).setMacroMachine(macroMachine).createActionExecutor();
                        actionExecutor.executeActions(configValues, pwmRequest.getSessionLabel());
                    }
                } catch (PwmOperationalException e) {
                    final ErrorInformation info = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, e.getErrorInformation().getDetailedErrorMsg(), e.getErrorInformation().getFieldValues());
                    final PwmUnrecoverableException newException = new PwmUnrecoverableException(info);
                    newException.initCause(e);
                    throw newException;
                } catch (ChaiUnavailableException e) {
                    final String errorMsg = "unable to reach ldap server while writing post-activate attributes: " + e.getMessage();
                    final ErrorInformation info = new ErrorInformation(PwmError.ERROR_ACTIVATION_FAILURE, errorMsg);
                    final PwmUnrecoverableException newException = new PwmUnrecoverableException(info);
                    newException.initCause(e);
                    throw newException;
                }
                return true;
            }
        };
        pwmSession.getUserSessionDataCacheBean().addPostChangePasswordActions("activateUserWriteAttributes", postAction);
    } catch (ImpossiblePasswordPolicyException e) {
        final ErrorInformation info = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unexpected ImpossiblePasswordPolicyException error while activating user");
        LOGGER.warn(pwmSession, info, e);
        throw new PwmOperationalException(info);
    }
}
Also used : ActionExecutor(password.pwm.util.operations.ActionExecutor) PwmApplication(password.pwm.PwmApplication) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) SessionAuthenticator(password.pwm.ldap.auth.SessionAuthenticator) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PostChangePasswordAction(password.pwm.util.PostChangePasswordAction) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) List(java.util.List) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) PwmSession(password.pwm.http.PwmSession) ImpossiblePasswordPolicyException(com.novell.ldapchai.exception.ImpossiblePasswordPolicyException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

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