1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package cz.zcu.mre.controller;
23
24 import cz.zcu.mre.data.account.Account;
25 import cz.zcu.mre.service.account.AccountService;
26 import java.security.Principal;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.http.HttpStatus;
29 import org.springframework.security.access.annotation.Secured;
30 import org.springframework.stereotype.Controller;
31 import org.springframework.util.Assert;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.bind.annotation.RequestMethod;
34 import org.springframework.web.bind.annotation.ResponseBody;
35 import org.springframework.web.bind.annotation.ResponseStatus;
36
37
38
39
40
41 @Controller
42 class AccountController {
43
44 private final AccountService accountService;
45
46 @Autowired
47 public AccountController(AccountService accountService) {
48 this.accountService = accountService;
49 }
50
51 @RequestMapping(value = "account/current", method = RequestMethod.GET)
52 @ResponseStatus(value = HttpStatus.OK)
53 @ResponseBody
54 @Secured({"ROLE_USER", "ROLE_ADMIN"})
55 public Account currentAccount(Principal principal) {
56 Assert.notNull(principal, "Null principal not allowed.");
57 return accountService.findOneByEmail(principal.getName());
58 }
59
60
61
62
63
64
65
66
67 }