Commit 8e68c40c authored by Matija Obreza's avatar Matija Obreza
Browse files

app-blocks:1.3-SNAPSHOT requires #getDefaultUserRole, #listAvailableRoles

parent 05ec1688
......@@ -32,11 +32,6 @@ import org.springframework.security.core.userdetails.UserDetails;
public interface UserService extends BasicUserService<UserRole, User> {
List<UserRole> listAvailableRoles();
@PreAuthorize("hasRole('ADMINISTRATOR')")
User addUser(User user) throws UserException, PasswordPolicyException;
@PreAuthorize("hasRole('ADMINISTRATOR')")
void removeUserById(long userId) throws UserException;
......
......@@ -80,6 +80,11 @@ public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implem
return availableRoles;
}
@Override
public UserRole getDefaultUserRole() {
return UserRole.USER;
}
@Override
@Transactional
public User createUser(String email, String fullName, String password, AccountType accountType) throws UserException {
......@@ -90,7 +95,7 @@ public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implem
user.setAccountType(accountType);
user.getRoles().add(UserRole.USER);
super.setPassword(user, password);
return addUser(user);
return userRepository.save(user);
}
@Transactional
......@@ -171,31 +176,6 @@ public class UserServiceImpl extends BasicUserServiceImpl<UserRole, User> implem
return userWrapper;
}
/**
* @param user
* @return
* @throws UserException
* @throws PasswordPolicyException
*/
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false, rollbackFor = NotUniqueUserException.class)
public User addUser(User user) throws UserException, PasswordPolicyException {
try {
if (user.getAccountType() == AccountType.LOCAL) {
changePassword(user, user.getPassword());
}
// save user
return userRepository.save(user);
} catch (final DataIntegrityViolationException e) {
throw new NotUniqueUserException(e, user.getEmail());
} catch (final EmptyResultDataAccessException e) {
throw new NoUserFoundException(e, user.getId());
} catch (final RuntimeException e) {
throw new UserException(e);
}
}
protected void updateUser(User user) throws UserException {
try {
userRepository.save(user);
......
......@@ -90,12 +90,6 @@ public class UsersController extends RestController {
return userService.getUserByUuid(id);
}
@RequestMapping(value = "/user", method = RequestMethod.PUT, consumes = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public void saveUser(@RequestBody @Validated User user) throws UserException, PasswordPolicyException {
userService.addUser(user);
}
@RequestMapping(value = "/user/data", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE})
@ResponseBody
public ApiResult updateData(@RequestBody UserChangedDataJson userData) throws PasswordPolicyException, UserException {
......
......@@ -87,6 +87,8 @@ public class SpringDataBaseConfig {
@Bean
public DataSource dataSource() {
System.err.println("Genesys is connecting to " + dbUrl);
final DataSource dataSource = new DataSource();
dataSource.setDefaultReadOnly(false);
dataSource.setUrl(dbUrl);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment