use of org.apache.openmeetings.db.dto.user.UserDTO 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);
});
}
use of org.apache.openmeetings.db.dto.user.UserDTO in project openmeetings by apache.
the class TestUserService method addUserTest.
@Test
public void addUserTest() {
String[] tzList = TimeZone.getAvailableIDs();
String tz = TimeZone.getTimeZone(tzList[rnd.nextInt(tzList.length)]).getID();
ServiceResult r = login();
UserDTO u = new UserDTO();
String uuid = UUID.randomUUID().toString();
u.setLogin("test" + uuid);
u.setPassword(createPass());
u.setFirstname("testF" + uuid);
u.setLastname("testL" + uuid);
u.setAddress(new Address());
u.getAddress().setEmail(uuid + "@local");
u.getAddress().setCountry(Locale.getDefault().getCountry());
u.setTimeZoneId(tz);
u.setExternalId(uuid);
u.setExternalType(UNIT_TEST_EXT_TYPE);
UserDTO user = getClient(getUserUrl()).path("/").query("sid", r.getMessage()).type(APPLICATION_FORM_URLENCODED).post(new Form().param("user", u.toString()).param("confirm", "" + false), UserDTO.class);
assertNotNull("Valid UserDTO should be returned", user);
assertNotNull("Id should not be NULL", user.getId());
assertEquals("OM Call should be successful", u.getLogin(), user.getLogin());
assertEquals("OM Call should be successful", tz, user.getTimeZoneId());
}
use of org.apache.openmeetings.db.dto.user.UserDTO in project openmeetings by apache.
the class AbstractWebServiceTest method webCreateUser.
public void webCreateUser(User u) {
ServiceResult r = login();
UserDTO dto = new UserDTO(u);
dto.setPassword(createPass());
UserDTO user = getClient(getUserUrl()).path("/").query("sid", r.getMessage()).type(APPLICATION_FORM_URLENCODED).post(new Form().param("user", dto.toString()).param("confirm", "" + false), UserDTO.class);
Assert.assertNotNull(user.getId());
u.setId(user.getId());
}
Aggregations