@Test void createUser() throws URISyntaxException, UsernameAlreadyExistsException, EmailAlreadyExistsException { when(idGenerator.generateId(SECURE_RANDOM)).thenReturn("3541db68-435b-416b-8c2c-cf2edf6ba435"); accountService.createUser(user, "http: ArgumentCaptor<User> argument = ArgumentCaptor.forClass(User.class); verify(dataService).add(eq(USER), argument.capture()); verify(argument.getValue()).setActive(false); SimpleMailMessage expected = new SimpleMailMessage(); expected.setTo("jan.jansen@activation.nl"); expected.setSubject("User registration for Molgenis title"); expected.setText( "User registration for Molgenis title\n" + "User name: jansenj Full name: Jan Jansen\n" + "\n" + "In order to activate your account go to: http: + "\n" + "and activate your account using the following code: 3541db68-435b-416b-8c2c-cf2edf6ba435" + "\n" + "\n"); verify(mailSender).send(expected); }
@Override @RunAsSystem @Transactional public void createUser(User user, String baseActivationUri) throws UsernameAlreadyExistsException, EmailAlreadyExistsException { if (userService.getUser(user.getUsername()) != null) { throw new UsernameAlreadyExistsException( "Username '" + user.getUsername() + "' already exists."); } if (userService.getUserByEmail(user.getEmail()) != null) { throw new EmailAlreadyExistsException( "Email '" + user.getEmail() + "' is already registered."); } String activationCode = idGenerator.generateId(SECURE_RANDOM); List<String> activationEmailAddresses; if (authenticationSettings.getSignUpModeration()) { activationEmailAddresses = userService.getSuEmailAddresses(); if (activationEmailAddresses == null || activationEmailAddresses.isEmpty()) throw new MolgenisDataException("Administrator account is missing required email address"); } else { String activationEmailAddress = user.getEmail(); if (activationEmailAddress == null || activationEmailAddress.isEmpty()) throw new MolgenisDataException( "User '" + user.getUsername() + "' is missing required email address"); activationEmailAddresses = singletonList(activationEmailAddress); } user.setActivationCode(activationCode); user.setActive(false); dataService.add(USER, user); LOG.debug("created user {}", user.getUsername()); try { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(activationEmailAddresses.toArray(new String[] {})); mailMessage.setSubject("User registration for " + appSettings.getTitle()); mailMessage.setText( createActivationEmailTestWithCode(user, URI.create(baseActivationUri), activationCode)); mailSender.send(mailMessage); } catch (MailException mce) { LOG.error("Could not send signup mail", mce); throw new MolgenisUserException( "An error occurred. Please contact the administrator. You are not signed up!"); } if (LOG.isDebugEnabled()) { LOG.debug( "send activation email for user {} to {}", user.getUsername(), StringUtils.join(activationEmailAddresses, ',')); } }
AccountServiceImpl implements AccountService { @Override @RunAsSystem @Transactional public void createUser(User user, String baseActivationUri) throws UsernameAlreadyExistsException, EmailAlreadyExistsException { if (userService.getUser(user.getUsername()) != null) { throw new UsernameAlreadyExistsException( "Username '" + user.getUsername() + "' already exists."); } if (userService.getUserByEmail(user.getEmail()) != null) { throw new EmailAlreadyExistsException( "Email '" + user.getEmail() + "' is already registered."); } String activationCode = idGenerator.generateId(SECURE_RANDOM); List<String> activationEmailAddresses; if (authenticationSettings.getSignUpModeration()) { activationEmailAddresses = userService.getSuEmailAddresses(); if (activationEmailAddresses == null || activationEmailAddresses.isEmpty()) throw new MolgenisDataException("Administrator account is missing required email address"); } else { String activationEmailAddress = user.getEmail(); if (activationEmailAddress == null || activationEmailAddress.isEmpty()) throw new MolgenisDataException( "User '" + user.getUsername() + "' is missing required email address"); activationEmailAddresses = singletonList(activationEmailAddress); } user.setActivationCode(activationCode); user.setActive(false); dataService.add(USER, user); LOG.debug("created user {}", user.getUsername()); try { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(activationEmailAddresses.toArray(new String[] {})); mailMessage.setSubject("User registration for " + appSettings.getTitle()); mailMessage.setText( createActivationEmailTestWithCode(user, URI.create(baseActivationUri), activationCode)); mailSender.send(mailMessage); } catch (MailException mce) { LOG.error("Could not send signup mail", mce); throw new MolgenisUserException( "An error occurred. Please contact the administrator. You are not signed up!"); } if (LOG.isDebugEnabled()) { LOG.debug( "send activation email for user {} to {}", user.getUsername(), StringUtils.join(activationEmailAddresses, ',')); } } }
AccountServiceImpl implements AccountService { @Override @RunAsSystem @Transactional public void createUser(User user, String baseActivationUri) throws UsernameAlreadyExistsException, EmailAlreadyExistsException { if (userService.getUser(user.getUsername()) != null) { throw new UsernameAlreadyExistsException( "Username '" + user.getUsername() + "' already exists."); } if (userService.getUserByEmail(user.getEmail()) != null) { throw new EmailAlreadyExistsException( "Email '" + user.getEmail() + "' is already registered."); } String activationCode = idGenerator.generateId(SECURE_RANDOM); List<String> activationEmailAddresses; if (authenticationSettings.getSignUpModeration()) { activationEmailAddresses = userService.getSuEmailAddresses(); if (activationEmailAddresses == null || activationEmailAddresses.isEmpty()) throw new MolgenisDataException("Administrator account is missing required email address"); } else { String activationEmailAddress = user.getEmail(); if (activationEmailAddress == null || activationEmailAddress.isEmpty()) throw new MolgenisDataException( "User '" + user.getUsername() + "' is missing required email address"); activationEmailAddresses = singletonList(activationEmailAddress); } user.setActivationCode(activationCode); user.setActive(false); dataService.add(USER, user); LOG.debug("created user {}", user.getUsername()); try { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(activationEmailAddresses.toArray(new String[] {})); mailMessage.setSubject("User registration for " + appSettings.getTitle()); mailMessage.setText( createActivationEmailTestWithCode(user, URI.create(baseActivationUri), activationCode)); mailSender.send(mailMessage); } catch (MailException mce) { LOG.error("Could not send signup mail", mce); throw new MolgenisUserException( "An error occurred. Please contact the administrator. You are not signed up!"); } if (LOG.isDebugEnabled()) { LOG.debug( "send activation email for user {} to {}", user.getUsername(), StringUtils.join(activationEmailAddresses, ',')); } } AccountServiceImpl(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      IdGenerator idGenerator); }
AccountServiceImpl implements AccountService { @Override @RunAsSystem @Transactional public void createUser(User user, String baseActivationUri) throws UsernameAlreadyExistsException, EmailAlreadyExistsException { if (userService.getUser(user.getUsername()) != null) { throw new UsernameAlreadyExistsException( "Username '" + user.getUsername() + "' already exists."); } if (userService.getUserByEmail(user.getEmail()) != null) { throw new EmailAlreadyExistsException( "Email '" + user.getEmail() + "' is already registered."); } String activationCode = idGenerator.generateId(SECURE_RANDOM); List<String> activationEmailAddresses; if (authenticationSettings.getSignUpModeration()) { activationEmailAddresses = userService.getSuEmailAddresses(); if (activationEmailAddresses == null || activationEmailAddresses.isEmpty()) throw new MolgenisDataException("Administrator account is missing required email address"); } else { String activationEmailAddress = user.getEmail(); if (activationEmailAddress == null || activationEmailAddress.isEmpty()) throw new MolgenisDataException( "User '" + user.getUsername() + "' is missing required email address"); activationEmailAddresses = singletonList(activationEmailAddress); } user.setActivationCode(activationCode); user.setActive(false); dataService.add(USER, user); LOG.debug("created user {}", user.getUsername()); try { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(activationEmailAddresses.toArray(new String[] {})); mailMessage.setSubject("User registration for " + appSettings.getTitle()); mailMessage.setText( createActivationEmailTestWithCode(user, URI.create(baseActivationUri), activationCode)); mailSender.send(mailMessage); } catch (MailException mce) { LOG.error("Could not send signup mail", mce); throw new MolgenisUserException( "An error occurred. Please contact the administrator. You are not signed up!"); } if (LOG.isDebugEnabled()) { LOG.debug( "send activation email for user {} to {}", user.getUsername(), StringUtils.join(activationEmailAddresses, ',')); } } AccountServiceImpl(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      IdGenerator idGenerator); @Override @RunAsSystem @Transactional void createUser(User user, String baseActivationUri); @Override @RunAsSystem void activateUser(String activationCode); }
AccountServiceImpl implements AccountService { @Override @RunAsSystem @Transactional public void createUser(User user, String baseActivationUri) throws UsernameAlreadyExistsException, EmailAlreadyExistsException { if (userService.getUser(user.getUsername()) != null) { throw new UsernameAlreadyExistsException( "Username '" + user.getUsername() + "' already exists."); } if (userService.getUserByEmail(user.getEmail()) != null) { throw new EmailAlreadyExistsException( "Email '" + user.getEmail() + "' is already registered."); } String activationCode = idGenerator.generateId(SECURE_RANDOM); List<String> activationEmailAddresses; if (authenticationSettings.getSignUpModeration()) { activationEmailAddresses = userService.getSuEmailAddresses(); if (activationEmailAddresses == null || activationEmailAddresses.isEmpty()) throw new MolgenisDataException("Administrator account is missing required email address"); } else { String activationEmailAddress = user.getEmail(); if (activationEmailAddress == null || activationEmailAddress.isEmpty()) throw new MolgenisDataException( "User '" + user.getUsername() + "' is missing required email address"); activationEmailAddresses = singletonList(activationEmailAddress); } user.setActivationCode(activationCode); user.setActive(false); dataService.add(USER, user); LOG.debug("created user {}", user.getUsername()); try { SimpleMailMessage mailMessage = new SimpleMailMessage(); mailMessage.setTo(activationEmailAddresses.toArray(new String[] {})); mailMessage.setSubject("User registration for " + appSettings.getTitle()); mailMessage.setText( createActivationEmailTestWithCode(user, URI.create(baseActivationUri), activationCode)); mailSender.send(mailMessage); } catch (MailException mce) { LOG.error("Could not send signup mail", mce); throw new MolgenisUserException( "An error occurred. Please contact the administrator. You are not signed up!"); } if (LOG.isDebugEnabled()) { LOG.debug( "send activation email for user {} to {}", user.getUsername(), StringUtils.join(activationEmailAddresses, ',')); } } AccountServiceImpl(
      DataService dataService,
      MailSender mailSender,
      UserService userService,
      AppSettings appSettings,
      AuthenticationSettings authenticationSettings,
      IdGenerator idGenerator); @Override @RunAsSystem @Transactional void createUser(User user, String baseActivationUri); @Override @RunAsSystem void activateUser(String activationCode);  }