Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. <authentication-manager>
  2. <authentication-provider ref="userService">
  3. </authentication-provider>
  4. </authentication-manager>
  5.  
  6. User user = repository.getByNameAndPass(name, password);
  7. if (user == null) {
  8. name = "NotAuthorised";
  9. password = "";
  10. }
  11. List<GrantedAuthority> grantedAuths = new ArrayList<>();
  12. grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));
  13. Authentication auth = new UsernamePasswordAuthenticationToken(name, password, grantedAuths);
  14. return auth;
  15. }
  16.  
  17. @Override
  18. public boolean supports(Class<?> authentication) {
  19. return authentication.equals(UsernamePasswordAuthenticationToken.class);
  20. }
  21.  
  22. @RequestMapping(value = "/log", method = RequestMethod.GET)
  23. public ResponseEntity<Map<String,Object>> getAll(@RequestParam(value = "page", required = false) Integer page,
  24. @RequestParam(value = "size", required = false) Integer size) {
  25.  
  26. Map<String, Object> resultMap = new HashMap<>();
  27. String loggedUser = userService.getLoggedUser();
  28. if ("NotAuthorised".equals(loggedUser)) {
  29. LOG.info("authtoriation error");
  30. resultMap.put("message","Access denied");
  31. return new ResponseEntity<>(resultMap, HttpStatus.UNAUTHORIZED);
  32. }
  33.  
  34. LOG.info("getAll for logmessages ");
  35. resultMap.put("logs", logMessageService.getLogMessagesDT(logMessageService.getPage(page == null ? 0 :
  36. page.intValue(), size == null ? 0 : size.intValue())) );
  37.  
  38. return new ResponseEntity<>(resultMap, HttpStatus.OK);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement