コード例 #1
0
 @Secured({"ROLE_USER", "ROLE_ADMIN"})
 @RequestMapping(value = "/api/login", method = RequestMethod.GET, produces = "application/json")
 public Role login() {
   Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
   Role role = new Role();
   role.setName(authentication.getAuthorities().iterator().next().toString());
   return role;
 }
コード例 #2
0
 @RequestMapping(value = "/isconnected", method = RequestMethod.GET, produces = "application/json")
 public ResponseEntity<Role> isConnected() {
   Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
   String email = authentication.getName();
   User user = userBean.findByEmail(email);
   Role role = new Role();
   role.setName(authentication.getAuthorities().iterator().next().toString());
   System.out.println("now is connected: " + user + " " + email + " " + role);
   if (user == null) return new ResponseEntity(role, HttpStatus.FORBIDDEN);
   return new ResponseEntity(role, HttpStatus.ACCEPTED);
 }