Guest User

Untitled

a guest
Oct 17th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. import org.springframework.beans.factory.annotation.Autowired;
  2. import org.springframework.security.access.annotation.Secured;
  3. import org.springframework.web.bind.annotation.RequestMapping;
  4. import org.springframework.web.bind.annotation.RestController;
  5.  
  6. import java.util.List;
  7.  
  8. @RestController
  9. @RequestMapping("/register")
  10. public class RegisterController {
  11. @Autowired
  12. private RegisterService registerService;
  13.  
  14. @Autowired
  15. private UserDao userDao;
  16.  
  17. private void setRegisterService(RegisterService registerService) {
  18. this.registerService = registerService;
  19. }
  20.  
  21. @RequestMapping("/add/user")
  22. public void register(String username, String password) {
  23. if (username == null || username == "") {
  24. System.err.println("Input is invalid!");
  25. return;
  26. }
  27. if (password == null || password == "") {
  28. System.err.println("Input is invalid!");
  29. return;
  30. }
  31. List<User> list = registerService.getUsers();
  32. synchronized (list) {
  33. for (int i = 0; i < list.size(); i++) {
  34. if (list.get(i).username == username) {
  35. System.err.println("Input is invalid!");
  36. return;
  37. }
  38. }
  39. }
  40. System.out.println("Registering user...");
  41. synchronized (registerService) {
  42. registerService.register(username, password);
  43. }
  44. }
  45.  
  46. @Secured({"DELETE_USERS"})
  47. @RequestMapping("/delete")
  48. public void delete(String username, String password) {
  49. if (username == null || username == "") {
  50. System.err.println("Username is invalid!");
  51. return;
  52. }
  53. userDao.delete(userDao.findById(username));
  54. }
  55.  
  56. @Secured({"allow-user-listing"})
  57. @RequestMapping("/")
  58. public List rootPathMapping() {
  59. return registerService.getUsers();
  60. }
  61. }
Add Comment
Please, Sign In to add comment