Advertisement
Guest User

Untitled

a guest
Mar 24th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <http pattern="/log/**" use-expressions="true" name="restSecurityFilterChain" create-session="stateless">
  2. <http-basic/>
  3. <intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
  4. <csrf disabled="true"/>
  5. </http>
  6.  
  7. <authentication-manager>
  8. <authentication-provider ref="userService">
  9. </authentication-provider>
  10. </authentication-manager>
  11.  
  12. @Override
  13. public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  14. String name = authentication.getName();
  15. String password = authentication.getCredentials().toString();
  16.  
  17. User user = repository.getByNameAndPass(name, password);
  18. if (user == null) {
  19. name = "NotAuthorised";
  20. password = "";
  21. }
  22. List<GrantedAuthority> grantedAuths = new ArrayList<>();
  23. grantedAuths.add(new SimpleGrantedAuthority("ROLE_USER"));
  24. Authentication auth = new UsernamePasswordAuthenticationToken(name, password, grantedAuths);
  25. return auth;
  26. }
  27.  
  28. @Override
  29. public boolean supports(Class<?> authentication) {
  30. return authentication.equals(UsernamePasswordAuthenticationToken.class);
  31. }
  32.  
  33. @RequestMapping(value = "/log", method = RequestMethod.GET)
  34. public ResponseEntity<Map<String,Object>> getAll(@RequestParam(value = "page", required = false) Integer page,
  35. @RequestParam(value = "size", required = false) Integer size) {
  36.  
  37. Map<String, Object> resultMap = new HashMap<>();
  38. String loggedUser = userService.getLoggedUser();
  39. if ("NotAuthorised".equals(loggedUser)) {
  40. LOG.info("authtoriation error");
  41. resultMap.put("message","Access denied");
  42. return new ResponseEntity<>(resultMap, HttpStatus.UNAUTHORIZED);
  43. }
  44.  
  45. LOG.info("getAll for logmessages ");
  46. resultMap.put("logs", logMessageService.getLogMessagesDT(logMessageService.getPage(page == null ? 0 :
  47. page.intValue(), size == null ? 0 : size.intValue())) );
  48.  
  49. return new ResponseEntity<>(resultMap, HttpStatus.OK);
  50. }
  51.  
  52. return new ResponseEntity<>(resultMap, HttpStatus.UNAUTHORIZED);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement