Ejemplo n.º 1
0
 /**
  * creates a new user.
  *
  * @param username the name of the user.
  * @param password the password.
  * @return the dto object created after registering the user.
  */
 public final User register(final String username, final String password) {
   User user = new User();
   user.setUsername(username);
   user.setPassword(password);
   user = userService.save(user);
   // set the default role for the user
   addToDefaultRole(user);
   return user;
 }
Ejemplo n.º 2
0
 /**
  * adds {@code user} to the default role.
  *
  * @param user the user
  */
 private void addToDefaultRole(final User user) {
   Role defaultRole = new Role();
   defaultRole.setRole(RoleNames.ROLE_USER.ordinal());
   defaultRole.setUser(user);
   roleRepository.save(defaultRole);
   user.setRole(defaultRole);
 }