Search in sources :

Example 1 with StrongPasswordValidator

use of org.apache.openmeetings.core.util.StrongPasswordValidator in project openmeetings by apache.

the class ChangePasswordDialog method onInitialize.

@Override
protected void onInitialize() {
    getTitle().setObject(getString("327"));
    update = new DialogButton("update", Model.of(getString("327"))) {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isIndicating() {
            return true;
        }
    };
    cancel = new DialogButton("cancel", Model.of(getString("lbl.cancel")));
    passValidator = new StrongPasswordValidator(getMinPasswdLength(cfgDao), userDao.get(getUserId()));
    add(form.add(current.setLabel(Model.of(getString("current.password"))).setRequired(true), pass.setLabel(Model.of(getString("328"))).add(passValidator), pass2.setLabel(Model.of(getString("116"))), feedback.setOutputMarkupId(true)));
    super.onInitialize();
}
Also used : DialogButton(com.googlecode.wicket.jquery.ui.widget.dialog.DialogButton) StrongPasswordValidator(org.apache.openmeetings.core.util.StrongPasswordValidator)

Example 2 with StrongPasswordValidator

use of org.apache.openmeetings.core.util.StrongPasswordValidator in project openmeetings by apache.

the class UserForm method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    add(password.setResetPassword(false).setLabel(Model.of(getString("110"))).setRequired(false).add(passValidator = new StrongPasswordValidator(getMinPasswdLength(cfgDao), getModelObject())));
    login.setLabel(Model.of(getString("108")));
    add(login.add(minimumLength(getMinLoginLength(cfgDao))));
    add(new DropDownChoice<>("type", Arrays.asList(Type.values())).add(new OnChangeAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateDomain(target);
        }
    }));
    update(null);
    add(domain.add(domainId).setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true));
    add(new Label("ownerId"));
    add(new DateLabel("inserted"));
    add(new DateLabel("updated"));
    add(new CheckBox("forceTimeZoneCheck"));
    add(new Select2MultiChoice<>("rights", null, new RestrictiveChoiceProvider<Right>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getDisplayValue(Right choice) {
            return choice.name();
        }

        @Override
        public String toId(Right choice) {
            return choice.name();
        }

        @Override
        public void query(String term, int page, Response<Right> response) {
            boolean isGroupAdmin = hasGroupAdminLevel(getRights());
            for (Right r : Right.values()) {
                if (Right.GroupAdmin == r) {
                    continue;
                }
                if (isGroupAdmin && (Right.Admin == r || Right.Soap == r)) {
                    continue;
                }
                if (Strings.isEmpty(term) || r.name().contains(term)) {
                    response.add(r);
                }
            }
        }

        @Override
        public Right fromId(String id) {
            return Right.valueOf(id);
        }
    }));
    add(new ComunityUserForm("comunity", getModel()));
    // attach an ajax validation behavior to all form component's keydown
    // event and throttle it down to once per second
    add(new AjaxFormValidatingBehavior("keydown", Duration.ONE_SECOND));
    add(adminPass);
}
Also used : RestrictiveChoiceProvider(org.apache.openmeetings.web.util.RestrictiveChoiceProvider) Label(org.apache.wicket.markup.html.basic.Label) DateLabel(org.apache.openmeetings.web.util.DateLabel) Right(org.apache.openmeetings.db.entity.user.User.Right) AjaxFormValidatingBehavior(org.apache.wicket.ajax.form.AjaxFormValidatingBehavior) StrongPasswordValidator(org.apache.openmeetings.core.util.StrongPasswordValidator) OnChangeAjaxBehavior(org.apache.wicket.ajax.form.OnChangeAjaxBehavior) DateLabel(org.apache.openmeetings.web.util.DateLabel) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Response(org.wicketstuff.select2.Response) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) CheckBox(org.apache.wicket.markup.html.form.CheckBox) ComunityUserForm(org.apache.openmeetings.web.common.ComunityUserForm)

Example 3 with StrongPasswordValidator

use of org.apache.openmeetings.core.util.StrongPasswordValidator 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)

Example 4 with StrongPasswordValidator

use of org.apache.openmeetings.core.util.StrongPasswordValidator in project openmeetings by apache.

the class UserWebService method add.

/**
 * Adds a new User like through the Frontend, but also does activates the
 * Account To do SSO see the methods to create a hash and use those ones!
 *
 * @param sid
 *            The SID from getSession
 * @param user
 *            user object
 * @param confirm
 *            whatever or not to send email, leave empty for auto-send
 *
 * @return - id of the user added or error code
 */
@WebMethod
@POST
@Path("/")
public UserDTO add(@WebParam(name = "sid") @QueryParam("sid") String sid, @WebParam(name = "user") @FormParam("user") UserDTO user, @WebParam(name = "confirm") @FormParam("confirm") Boolean confirm) {
    return performCall(sid, User.Right.Soap, sd -> {
        User testUser = userDao.getExternalUser(user.getExternalId(), user.getExternalType());
        if (testUser != null) {
            throw new ServiceException("User does already exist!");
        }
        String tz = user.getTimeZoneId();
        if (Strings.isEmpty(tz)) {
            tz = getDefaultTimezone();
        }
        if (user.getAddress() == null) {
            user.setAddress(new Address());
            user.getAddress().setCountry(Locale.getDefault().getCountry());
        }
        if (user.getLanguageId() == null) {
            user.setLanguageId(1L);
        }
        IValidator<String> passValidator = new StrongPasswordValidator(true, getMinPasswdLength(cfgDao), user.get(userDao));
        Validatable<String> passVal = new Validatable<>(user.getPassword());
        passValidator.validate(passVal);
        if (!passVal.isValid()) {
            StringBuilder sb = new StringBuilder();
            for (IValidationError err : passVal.getErrors()) {
                sb.append(((ValidationError) err).getMessage()).append(System.lineSeparator());
            }
            log.debug("addNewUser::weak password '{}', msg: {}", user.getPassword(), sb);
            throw new ServiceException(sb.toString());
        }
        Object _user = userManager.registerUser(user.getLogin(), user.getPassword(), user.getLastname(), user.getFirstname(), user.getAddress().getEmail(), new Date(), user.getAddress().getStreet(), user.getAddress().getAdditionalname(), user.getAddress().getFax(), user.getAddress().getZip(), user.getAddress().getCountry(), user.getAddress().getTown(), user.getLanguageId(), // generate SIP Data if the config is enabled
        "", // generate SIP Data if the config is enabled
        false, // generate SIP Data if the config is enabled
        true, tz, confirm);
        if (_user == null) {
            throw new ServiceException(UNKNOWN.getMessage());
        } else if (_user instanceof String) {
            throw new ServiceException((String) _user);
        }
        User u = (User) _user;
        u.getRights().add(Right.Room);
        if (Strings.isEmpty(user.getExternalId()) && Strings.isEmpty(user.getExternalType())) {
            // activate the User
            u.getRights().add(Right.Login);
            u.getRights().add(Right.Dashboard);
        } else {
            u.setType(User.Type.external);
            u.setExternalId(user.getExternalId());
            u.setExternalType(user.getExternalType());
        }
        u = userDao.update(u, sd.getUserId());
        return new UserDTO(u);
    });
}
Also used : User(org.apache.openmeetings.db.entity.user.User) Address(org.apache.openmeetings.db.entity.user.Address) UserDTO(org.apache.openmeetings.db.dto.user.UserDTO) ExternalUserDTO(org.apache.openmeetings.db.dto.user.ExternalUserDTO) IValidationError(org.apache.wicket.validation.IValidationError) StrongPasswordValidator(org.apache.openmeetings.core.util.StrongPasswordValidator) Validatable(org.apache.wicket.validation.Validatable) Date(java.util.Date) ServiceException(org.apache.openmeetings.webservice.error.ServiceException) RemoteSessionObject(org.apache.openmeetings.db.entity.server.RemoteSessionObject) ValidationError(org.apache.wicket.validation.ValidationError) IValidationError(org.apache.wicket.validation.IValidationError) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

StrongPasswordValidator (org.apache.openmeetings.core.util.StrongPasswordValidator)4 User (org.apache.openmeetings.db.entity.user.User)2 DialogButton (com.googlecode.wicket.jquery.ui.widget.dialog.DialogButton)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Date (java.util.Date)1 Map (java.util.Map)1 WebMethod (javax.jws.WebMethod)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 ConfigurationDao (org.apache.openmeetings.db.dao.basic.ConfigurationDao)1 ExternalUserDTO (org.apache.openmeetings.db.dto.user.ExternalUserDTO)1 UserDTO (org.apache.openmeetings.db.dto.user.UserDTO)1 RemoteSessionObject (org.apache.openmeetings.db.entity.server.RemoteSessionObject)1 Address (org.apache.openmeetings.db.entity.user.Address)1 Right (org.apache.openmeetings.db.entity.user.User.Right)1 ComunityUserForm (org.apache.openmeetings.web.common.ComunityUserForm)1 DateLabel (org.apache.openmeetings.web.util.DateLabel)1 RestrictiveChoiceProvider (org.apache.openmeetings.web.util.RestrictiveChoiceProvider)1 ServiceException (org.apache.openmeetings.webservice.error.ServiceException)1