partly working security: registration form, authorization, simple authentification
[proteocache.git] / server / compbio / controllers / MainController.java
1 package compbio.controllers;
2
3 import java.security.Principal;
4 import org.springframework.stereotype.Controller;
5 import org.springframework.ui.ModelMap;
6 import org.springframework.web.bind.annotation.RequestMapping;
7 import org.springframework.web.bind.annotation.RequestMethod;
8
9 @Controller
10 public class MainController {
11
12         @RequestMapping(value = "/index", method = RequestMethod.GET)
13         public String printPublicHome(ModelMap model, Principal principal) {
14                 String name = "";
15                 // if (null != name ) {
16                 // name = principal.getName();
17                 // }
18                 model.addAttribute("username", name);
19                 model.addAttribute("message", "Spring Security Custom Form example");
20                 return "public";
21         }
22
23         @RequestMapping(value = "/login", method = RequestMethod.GET)
24         public String login(ModelMap model) {
25                 return "login";
26         }
27
28         @RequestMapping(value = "/loginfailed", method = RequestMethod.GET)
29         public String loginerror(ModelMap model) {
30                 model.addAttribute("error", "Wrong user name or password");
31                 return "login";
32         }
33
34         @RequestMapping(value = "/logout", method = RequestMethod.GET)
35         public String logout(ModelMap model) {
36                 return "public";
37         }
38
39         @RequestMapping(value = "/denied", method = RequestMethod.GET)
40         public String denied(ModelMap model, Principal principal) {
41                 String name = "unknown";
42                 if (null != principal.getName())
43                         name = principal.getName();
44                 model.put("username", name);
45                 return "support/Denied";
46         }
47
48         @RequestMapping(value = "/home", method = RequestMethod.GET)
49         public String printHome(ModelMap model, Principal principal) {
50                 String name = "unknown";
51                 if (null != name) {
52                         name = principal.getName();
53                 }
54                 model.addAttribute("username", name);
55                 model.addAttribute("message", "Spring Security Custom Form example");
56                 return "home";
57         }
58
59 }