Search in sources :

Example 1 with ConfigurationDao

use of org.apache.openmeetings.db.dao.basic.ConfigurationDao in project openmeetings by apache.

the class Admin method checkAdminDetails.

private void checkAdminDetails() throws Exception {
    cfg.setUsername(cmdl.getOptionValue("user"));
    cfg.setEmail(cmdl.getOptionValue("email"));
    cfg.setGroup(cmdl.getOptionValue("group"));
    if (cfg.getUsername() == null || cfg.getUsername().length() < USER_LOGIN_MINIMUM_LENGTH) {
        log("User login was not provided, or too short, should be at least " + USER_LOGIN_MINIMUM_LENGTH + " character long.");
        throw new ExitException();
    }
    if (!MailUtil.isValid(cfg.getEmail())) {
        log(String.format("Please provide non-empty valid email: '%s' is not valid.", cfg.getEmail()));
        throw new ExitException();
    }
    if (Strings.isEmpty(cfg.getGroup())) {
        log(String.format("User group was not provided, or too short, should be at least 1 character long: %s", cfg.getGroup()));
        throw new ExitException();
    }
    if (cmdl.hasOption("password")) {
        cfg.setPassword(cmdl.getOptionValue("password"));
    }
    ConfigurationDao cfgDao = getApplicationContext().getBean(ConfigurationDao.class);
    IValidator<String> passValidator = new StrongPasswordValidator(false, getMinPasswdLength(cfgDao), new User());
    Validatable<String> passVal;
    do {
        passVal = new Validatable<>(cfg.getPassword());
        passValidator.validate(passVal);
        if (!passVal.isValid()) {
            log(String.format("Please enter password for the user '%s':", cfg.getUsername()));
            cfg.setPassword(new BufferedReader(new InputStreamReader(System.in, UTF_8)).readLine());
        }
    } while (!passVal.isValid());
    Map<String, String> tzMap = ImportHelper.getAllTimeZones(TimeZone.getAvailableIDs());
    cfg.setTimeZone(null);
    if (cmdl.hasOption("tz")) {
        String tz = cmdl.getOptionValue("tz");
        cfg.setTimeZone(tzMap.containsKey(tz) ? tz : null);
    }
    if (cfg.getTimeZone() == null) {
        log("Please enter timezone, Possible timezones are:");
        for (Map.Entry<String, String> me : tzMap.entrySet()) {
            log(String.format("%1$-25s%2$s", "\"" + me.getKey() + "\"", me.getValue()));
        }
        throw new ExitException();
    }
}
Also used : ConfigurationDao(org.apache.openmeetings.db.dao.basic.ConfigurationDao) User(org.apache.openmeetings.db.entity.user.User) InputStreamReader(java.io.InputStreamReader) StrongPasswordValidator(org.apache.openmeetings.core.util.StrongPasswordValidator) BufferedReader(java.io.BufferedReader) Map(java.util.Map)

Aggregations

BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Map (java.util.Map)1 StrongPasswordValidator (org.apache.openmeetings.core.util.StrongPasswordValidator)1 ConfigurationDao (org.apache.openmeetings.db.dao.basic.ConfigurationDao)1 User (org.apache.openmeetings.db.entity.user.User)1