Search in sources :

Example 41 with PasswordData

use of password.pwm.util.PasswordData in project pwm by pwm-project.

the class ChangePasswordServlet method processRandomPasswordAction.

@ActionHandler(action = "randomPassword")
private ProcessStatus processRandomPasswordAction(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException, ChaiUnavailableException {
    final PasswordData passwordData = RandomPasswordGenerator.createRandomPassword(pwmRequest.getPwmSession(), pwmRequest.getPwmApplication());
    final RestRandomPasswordServer.JsonOutput jsonOutput = new RestRandomPasswordServer.JsonOutput();
    jsonOutput.setPassword(passwordData.getStringValue());
    final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : PasswordData(password.pwm.util.PasswordData) RestRandomPasswordServer(password.pwm.ws.server.rest.RestRandomPasswordServer) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 42 with PasswordData

use of password.pwm.util.PasswordData in project pwm by pwm-project.

the class ChangePasswordServlet method processChangeAction.

@ActionHandler(action = "change")
ProcessStatus processChangeAction(final PwmRequest pwmRequest) throws ServletException, PwmUnrecoverableException, IOException, ChaiUnavailableException {
    final ChangePasswordBean changePasswordBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ChangePasswordBean.class);
    final UserInfo userInfo = pwmRequest.getPwmSession().getUserInfo();
    if (!changePasswordBean.isAllChecksPassed()) {
        return ProcessStatus.Continue;
    }
    final PasswordData password1 = pwmRequest.readParameterAsPassword("password1");
    final PasswordData password2 = pwmRequest.readParameterAsPassword("password2");
    // check the password meets the requirements
    try {
        final ChaiUser theUser = pwmRequest.getPwmSession().getSessionManager().getActor(pwmRequest.getPwmApplication());
        final PwmPasswordRuleValidator pwmPasswordRuleValidator = new PwmPasswordRuleValidator(pwmRequest.getPwmApplication(), userInfo.getPasswordPolicy());
        final PasswordData oldPassword = pwmRequest.getPwmSession().getLoginInfoBean().getUserCurrentPassword();
        pwmPasswordRuleValidator.testPassword(password1, oldPassword, userInfo, theUser);
    } catch (PwmDataValidationException e) {
        setLastError(pwmRequest, e.getErrorInformation());
        LOGGER.debug(pwmRequest, "failed password validation check: " + e.getErrorInformation().toDebugStr());
        return ProcessStatus.Continue;
    }
    // make sure the two passwords match
    final boolean caseSensitive = userInfo.getPasswordPolicy().getRuleHelper().readBooleanValue(PwmPasswordRule.CaseSensitive);
    if (PasswordUtility.PasswordCheckInfo.MatchStatus.MATCH != PasswordUtility.figureMatchStatus(caseSensitive, password1, password2)) {
        setLastError(pwmRequest, PwmError.PASSWORD_DOESNOTMATCH.toInfo());
        forwardToChangePage(pwmRequest);
        return ProcessStatus.Continue;
    }
    try {
        ChangePasswordServletUtil.executeChangePassword(pwmRequest, password1);
    } catch (PwmOperationalException e) {
        LOGGER.debug(e.getErrorInformation().toDebugStr());
        setLastError(pwmRequest, e.getErrorInformation());
    }
    return ProcessStatus.Continue;
}
Also used : ChangePasswordBean(password.pwm.http.bean.ChangePasswordBean) PwmPasswordRuleValidator(password.pwm.util.PwmPasswordRuleValidator) PwmDataValidationException(password.pwm.error.PwmDataValidationException) ChaiUser(com.novell.ldapchai.ChaiUser) PasswordData(password.pwm.util.PasswordData) UserInfo(password.pwm.ldap.UserInfo) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 43 with PasswordData

use of password.pwm.util.PasswordData in project pwm by pwm-project.

the class ChangePasswordServletUtil method determineIfCurrentPasswordRequired.

static boolean determineIfCurrentPasswordRequired(final PwmApplication pwmApplication, final PwmSession pwmSession) throws PwmUnrecoverableException {
    final RequireCurrentPasswordMode currentSetting = pwmApplication.getConfig().readSettingAsEnum(PwmSetting.PASSWORD_REQUIRE_CURRENT, RequireCurrentPasswordMode.class);
    if (currentSetting == RequireCurrentPasswordMode.FALSE) {
        return false;
    }
    if (pwmSession.getLoginInfoBean().getType() == AuthenticationType.AUTH_FROM_PUBLIC_MODULE) {
        LOGGER.debug(pwmSession, "skipping user current password requirement, authentication type is " + AuthenticationType.AUTH_FROM_PUBLIC_MODULE);
        return false;
    }
    {
        final PasswordData currentPassword = pwmSession.getLoginInfoBean().getUserCurrentPassword();
        if (currentPassword == null) {
            LOGGER.debug(pwmSession, "skipping user current password requirement, current password is not known to application");
            return false;
        }
    }
    if (currentSetting == RequireCurrentPasswordMode.TRUE) {
        return true;
    }
    final PasswordStatus passwordStatus = pwmSession.getUserInfo().getPasswordStatus();
    return currentSetting == RequireCurrentPasswordMode.NOTEXPIRED && !passwordStatus.isExpired() && !passwordStatus.isPreExpired() && !passwordStatus.isViolatesPolicy() && !pwmSession.getUserInfo().isRequiresNewPassword();
}
Also used : PasswordData(password.pwm.util.PasswordData) RequireCurrentPasswordMode(password.pwm.config.option.RequireCurrentPasswordMode) PasswordStatus(password.pwm.bean.PasswordStatus)

Example 44 with PasswordData

use of password.pwm.util.PasswordData in project pwm by pwm-project.

the class ConfigEditorServlet method doUploadFile.

@ActionHandler(action = "uploadFile")
private ProcessStatus doUploadFile(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final String key = pwmRequest.readParameterAsString("key");
    final PwmSetting setting = PwmSetting.forKey(key);
    final int maxFileSize = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.CONFIG_MAX_JDBC_JAR_SIZE));
    if (setting == PwmSetting.HTTPS_CERT) {
        try {
            final PasswordData passwordData = pwmRequest.readParameterAsPassword("password");
            final String alias = pwmRequest.readParameterAsString("alias");
            final HttpsServerCertificateManager.KeyStoreFormat keyStoreFormat;
            try {
                keyStoreFormat = HttpsServerCertificateManager.KeyStoreFormat.valueOf(pwmRequest.readParameterAsString("format"));
            } catch (IllegalArgumentException e) {
                throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_PARAMETER, "unknown format type: " + e.getMessage(), new String[] { "format" }));
            }
            final Map<String, PwmRequest.FileUploadItem> fileUploads = pwmRequest.readFileUploads(maxFileSize, 1);
            final ByteArrayInputStream fileIs = new ByteArrayInputStream(fileUploads.get(PwmConstants.PARAM_FILE_UPLOAD).getContent().getBytes());
            HttpsServerCertificateManager.importKey(configManagerBean.getStoredConfiguration(), keyStoreFormat, fileIs, passwordData, alias);
            pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
            return ProcessStatus.Halt;
        } catch (PwmException e) {
            LOGGER.error(pwmRequest, "error during https certificate upload: " + e.getMessage());
            pwmRequest.respondWithError(e.getErrorInformation(), false);
            return ProcessStatus.Halt;
        }
    }
    final FileValue fileValue = ConfigEditorServletUtils.readFileUploadToSettingValue(pwmRequest, maxFileSize);
    if (fileValue != null) {
        final UserIdentity userIdentity = pwmRequest.isAuthenticated() ? pwmRequest.getPwmSession().getUserInfo().getUserIdentity() : null;
        configManagerBean.getStoredConfiguration().writeSetting(setting, fileValue, userIdentity);
        pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
    }
    return ProcessStatus.Halt;
}
Also used : FileValue(password.pwm.config.value.FileValue) UserIdentity(password.pwm.bean.UserIdentity) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) HttpsServerCertificateManager(password.pwm.util.secure.HttpsServerCertificateManager) PwmSetting(password.pwm.config.PwmSetting) PwmException(password.pwm.error.PwmException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ErrorInformation(password.pwm.error.ErrorInformation) PasswordData(password.pwm.util.PasswordData) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

PasswordData (password.pwm.util.PasswordData)44 ErrorInformation (password.pwm.error.ErrorInformation)20 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)17 PwmOperationalException (password.pwm.error.PwmOperationalException)12 ChaiUser (com.novell.ldapchai.ChaiUser)10 UserInfo (password.pwm.ldap.UserInfo)10 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)8 ArrayList (java.util.ArrayList)8 UserIdentity (password.pwm.bean.UserIdentity)7 PwmException (password.pwm.error.PwmException)7 PwmPasswordPolicy (password.pwm.config.profile.PwmPasswordPolicy)6 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)5 LinkedHashMap (java.util.LinkedHashMap)5 ChaiException (com.novell.ldapchai.exception.ChaiException)4 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)4 Locale (java.util.Locale)4 Map (java.util.Map)4 FormConfiguration (password.pwm.config.value.data.FormConfiguration)4 RandomPasswordGenerator (password.pwm.util.RandomPasswordGenerator)4 PwmSecurityKey (password.pwm.util.secure.PwmSecurityKey)4