Search in sources :

Example 1 with ConfigurationDao

use of org.akaza.openclinica.dao.hibernate.ConfigurationDao in project OpenClinica by OpenClinica.

the class ConfigurationDaoTest method testSaveOrUpdate.

public void testSaveOrUpdate() {
    ConfigurationDao configurationDao = (ConfigurationDao) getContext().getBean("configurationDao");
    ConfigurationBean configurationBean = new ConfigurationBean();
    configurationBean.setKey("user.test");
    configurationBean.setValue("test");
    configurationBean.setDescription("Testing attention please");
    configurationBean = configurationDao.saveOrUpdate(configurationBean);
    assertNotNull("Persistant id is null", configurationBean.getId());
}
Also used : ConfigurationDao(org.akaza.openclinica.dao.hibernate.ConfigurationDao) ConfigurationBean(org.akaza.openclinica.domain.technicaladmin.ConfigurationBean)

Example 2 with ConfigurationDao

use of org.akaza.openclinica.dao.hibernate.ConfigurationDao in project OpenClinica by OpenClinica.

the class ConfigurationDaoTest method testfindById.

public void testfindById() {
    ConfigurationDao configurationDao = (ConfigurationDao) getContext().getBean("configurationDao");
    ConfigurationBean configurationBean = configurationDao.findById(-1);
    assertEquals("Key should be test.test", "test.test", configurationBean.getKey());
}
Also used : ConfigurationDao(org.akaza.openclinica.dao.hibernate.ConfigurationDao) ConfigurationBean(org.akaza.openclinica.domain.technicaladmin.ConfigurationBean)

Example 3 with ConfigurationDao

use of org.akaza.openclinica.dao.hibernate.ConfigurationDao in project OpenClinica by OpenClinica.

the class ConfigurePasswordRequirementsServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    ConfigurationDao configurationDao = SpringServletAccess.getApplicationContext(context).getBean(ConfigurationDao.class);
    PasswordRequirementsDao passwordRequirementsDao = new PasswordRequirementsDao(configurationDao);
    if (!fp.isSubmitted()) {
        setPresetValues(new HashMap<String, Object>(passwordRequirementsDao.configs()));
        forwardPage(Page.CONFIGURATION_PASSWORD_REQUIREMENTS);
    } else {
        Validator v = new Validator(request);
        for (String key : passwordRequirementsDao.intConfigKeys()) {
            v.addValidation(key, Validator.IS_AN_INTEGER);
        }
        HashMap<?, ?> errors = v.validate();
        int minChars = fp.getInt("pwd.chars.min");
        int maxChars = fp.getInt("pwd.chars.max");
        if (minChars > 0 && maxChars > 0 && maxChars < minChars) {
            Validator.addError(errors, "pwd.chars.min", resexception.getString("pwd_min_greater_than_max"));
        }
        if (errors.isEmpty()) {
            passwordRequirementsDao.setHasLower(Boolean.valueOf(fp.getString("pwd.chars.case.lower")));
            passwordRequirementsDao.setHasUpper(Boolean.valueOf(fp.getString("pwd.chars.case.upper")));
            passwordRequirementsDao.setHasDigits(Boolean.valueOf(fp.getString("pwd.chars.digits")));
            passwordRequirementsDao.setHasSpecials(Boolean.valueOf(fp.getString("pwd.chars.specials")));
            passwordRequirementsDao.setMinLength(fp.getInt("pwd.chars.min"));
            passwordRequirementsDao.setMaxLength(fp.getInt("pwd.chars.max"));
            passwordRequirementsDao.setExpirationDays(fp.getInt("pwd.expiration.days"));
            passwordRequirementsDao.setChangeRequired(fp.getInt("pwd.change.required"));
            addPageMessage(respage.getString("password_req_changes_have_been_saved"));
            forwardPage(Page.LIST_USER_ACCOUNTS_SERVLET);
        } else {
            setPresetValues(submittedValues(passwordRequirementsDao, fp));
            setInputMessages(errors);
            forwardPage(Page.CONFIGURATION_PASSWORD_REQUIREMENTS);
        }
    }
}
Also used : ConfigurationDao(org.akaza.openclinica.dao.hibernate.ConfigurationDao) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) PasswordRequirementsDao(org.akaza.openclinica.dao.hibernate.PasswordRequirementsDao) Validator(org.akaza.openclinica.control.form.Validator)

Example 4 with ConfigurationDao

use of org.akaza.openclinica.dao.hibernate.ConfigurationDao in project OpenClinica by OpenClinica.

the class ResetPasswordServlet method processRequest.

/**
     * Tasks include:
     * <ol>
     * <li>Validation:
     * <ol>
     * <li>1. old password match database record
     * <li>2. new password is follows requirements
     * <li>4. two times entered passwords are same
     * <li>5. all required fields are filled
     * </ol>
     * <li>Update ub - UserAccountBean - in session and database
     * </ol>
     */
@Override
public void processRequest() throws Exception {
    logger.info("Change expired password");
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    Validator v = new Validator(request);
    errors.clear();
    FormProcessor fp = new FormProcessor(request);
    String mustChangePwd = request.getParameter("mustChangePwd");
    String newPwd = fp.getString("passwd").trim();
    String passwdChallengeQ = fp.getString("passwdChallengeQ");
    String passwdChallengeA = fp.getString("passwdChallengeA");
    if ("yes".equalsIgnoreCase(mustChangePwd)) {
        addPageMessage(respage.getString("your_password_has_expired_must_change"));
    } else {
        addPageMessage(respage.getString("password_expired") + " " + respage.getString("if_you_do_not_want_change_leave_blank"));
    }
    request.setAttribute("mustChangePass", mustChangePwd);
    String oldPwd = fp.getString("oldPasswd").trim();
    // user bean from web
    UserAccountBean ubForm = new UserAccountBean();
    // form
    ubForm.setPasswd(oldPwd);
    ubForm.setPasswdChallengeQuestion(passwdChallengeQ);
    ubForm.setPasswdChallengeAnswer(passwdChallengeA);
    request.setAttribute("userBean1", ubForm);
    SecurityManager sm = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
    if (!sm.isPasswordValid(ub.getPasswd(), oldPwd, getUserDetails())) {
        Validator.addError(errors, "oldPasswd", resexception.getString("wrong_old_password"));
        request.setAttribute("formMessages", errors);
        forwardPage(Page.RESET_PASSWORD);
    } else {
        if (mustChangePwd.equalsIgnoreCase("yes")) {
            v.addValidation("passwd", Validator.NO_BLANKS);
            v.addValidation("passwd1", Validator.NO_BLANKS);
            v.addValidation("passwdChallengeQ", Validator.NO_BLANKS);
            v.addValidation("passwdChallengeA", Validator.NO_BLANKS);
            v.addValidation("passwd", Validator.CHECK_DIFFERENT, "oldPasswd");
        }
        String newDigestPass = sm.encrytPassword(newPwd, getUserDetails());
        List<String> pwdErrors = new ArrayList<String>();
        if (!StringUtils.isEmpty(newPwd)) {
            v.addValidation("passwd", Validator.IS_A_PASSWORD);
            v.addValidation("passwd1", Validator.CHECK_SAME, "passwd");
            ConfigurationDao configurationDao = SpringServletAccess.getApplicationContext(context).getBean(ConfigurationDao.class);
            PasswordRequirementsDao passwordRequirementsDao = new PasswordRequirementsDao(configurationDao);
            Locale locale = LocaleResolver.getLocale(request);
            ResourceBundle resexception = ResourceBundleProvider.getExceptionsBundle(locale);
            pwdErrors = PasswordValidator.validatePassword(passwordRequirementsDao, udao, ub.getId(), newPwd, newDigestPass, resexception);
        }
        errors = v.validate();
        for (String err : pwdErrors) {
            v.addError(errors, "passwd", err);
        }
        if (!errors.isEmpty()) {
            logger.info("ResetPassword page has validation errors");
            request.setAttribute("formMessages", errors);
            forwardPage(Page.RESET_PASSWORD);
        } else {
            logger.info("ResetPassword page has no errors");
            if (!StringUtils.isBlank(newPwd)) {
                ub.setPasswd(newDigestPass);
                ub.setPasswdTimestamp(new Date());
            } else if ("no".equalsIgnoreCase(mustChangePwd)) {
                ub.setPasswdTimestamp(new Date());
            }
            ub.setOwner(ub);
            // when update ub, updator id is required
            ub.setUpdater(ub);
            ub.setPasswdChallengeQuestion(passwdChallengeQ);
            ub.setPasswdChallengeAnswer(passwdChallengeA);
            udao.update(ub);
            ArrayList<String> pageMessages = new ArrayList<String>();
            request.setAttribute(PAGE_MESSAGE, pageMessages);
            addPageMessage(respage.getString("your_expired_password_reset_successfully"));
            ub.incNumVisitsToMainMenu();
            forwardPage(Page.MENU_SERVLET);
        }
    }
}
Also used : Locale(java.util.Locale) ConfigurationDao(org.akaza.openclinica.dao.hibernate.ConfigurationDao) SecurityManager(org.akaza.openclinica.core.SecurityManager) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) ResourceBundle(java.util.ResourceBundle) PasswordRequirementsDao(org.akaza.openclinica.dao.hibernate.PasswordRequirementsDao) Validator(org.akaza.openclinica.control.form.Validator)

Example 5 with ConfigurationDao

use of org.akaza.openclinica.dao.hibernate.ConfigurationDao in project OpenClinica by OpenClinica.

the class ConfigurationDaoTest method testfindByKey.

public void testfindByKey() {
    ConfigurationDao configurationDao = (ConfigurationDao) getContext().getBean("configurationDao");
    ConfigurationBean configurationBean = configurationDao.findByKey("test.test");
    assertEquals("Key should be test.test", "test.test", configurationBean.getKey());
}
Also used : ConfigurationDao(org.akaza.openclinica.dao.hibernate.ConfigurationDao) ConfigurationBean(org.akaza.openclinica.domain.technicaladmin.ConfigurationBean)

Aggregations

ConfigurationDao (org.akaza.openclinica.dao.hibernate.ConfigurationDao)7 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)3 Validator (org.akaza.openclinica.control.form.Validator)3 PasswordRequirementsDao (org.akaza.openclinica.dao.hibernate.PasswordRequirementsDao)3 ConfigurationBean (org.akaza.openclinica.domain.technicaladmin.ConfigurationBean)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Locale (java.util.Locale)2 ResourceBundle (java.util.ResourceBundle)2 File (java.io.File)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)1 SecurityManager (org.akaza.openclinica.core.SecurityManager)1 CoreResources (org.akaza.openclinica.dao.core.CoreResources)1 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)1 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)1