/** * 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; }
/** * 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); }