1 package org.oxerr.spring.security.guest.samples.helloworld.web;
2
3 import static org.springframework.web.bind.annotation.RequestMethod.GET;
4
5 import java.io.IOException;
6 import java.security.Principal;
7 import java.util.HashMap;
8 import java.util.Map;
9
10 import javax.annotation.security.RolesAllowed;
11 import javax.servlet.http.HttpServletResponse;
12
13 import org.springframework.security.core.Authentication;
14 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.bind.annotation.RestController;
16
17
18
19
20 @RestController
21 @RolesAllowed("ROLE_GUEST")
22 public class RestDemoController {
23
24 @RequestMapping(method = GET, path = "/", produces = "application/json")
25 public Map<String, String> helloUser(
26 Principal principal,
27 Authentication authentication,
28 HttpServletResponse response
29 ) throws IOException {
30 Map<String, String> result = new HashMap<String, String>();
31 result.put("name", principal.getName());
32 return result;
33 }
34
35 }