1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.amber.oauth2.client.demo.controller;
23
24 import java.io.IOException;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.amber.oauth2.client.demo.Utils;
28 import org.apache.amber.oauth2.client.demo.model.OAuthRegParams;
29 import org.apache.amber.oauth2.common.exception.OAuthSystemException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.apache.amber.oauth2.client.demo.model.OAuthParams;
33 import org.springframework.stereotype.Controller;
34 import org.springframework.web.bind.annotation.ModelAttribute;
35 import org.springframework.web.bind.annotation.PathVariable;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.servlet.ModelAndView;
38
39
40
41
42
43
44
45 @Controller
46 @RequestMapping("/")
47 public class MainController {
48
49 private Logger logger = LoggerFactory.getLogger(MainController.class);
50
51 @RequestMapping("/index")
52 public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams)
53 throws OAuthSystemException, IOException {
54 return new ModelAndView("index");
55 }
56
57 @RequestMapping("/main/{app}")
58 public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams,
59 @ModelAttribute("oauthRegParams") OAuthRegParams oauthRegParams,
60 @PathVariable("app") String app,
61 HttpServletResponse res)
62 throws OAuthSystemException, IOException {
63
64 boolean selected = false;
65 if (Utils.GENERIC.equals(app)) {
66 selected = true;
67 }else if (Utils.GITHUB.equals(app)) {
68 selected = true;
69 oauthParams.setAuthzEndpoint(Utils.GITHUB_AUTHZ);
70 oauthParams.setTokenEndpoint(Utils.GITHUB_TOKEN);
71
72 } else if (Utils.FACEBOOK.equals(app)) {
73 selected = true;
74 oauthParams.setAuthzEndpoint(Utils.FACEBOOK_AUTHZ);
75 oauthParams.setTokenEndpoint(Utils.FACEBOOK_TOKEN);
76 }else if (Utils.GOOGLE.equals(app)) {
77 selected = true;
78 oauthParams.setAuthzEndpoint(Utils.GOOGLE_AUTHZ);
79 oauthParams.setTokenEndpoint(Utils.GOOGLE_TOKEN);
80 } else if (Utils.GOWALLA.equals(app)) {
81 selected = true;
82 oauthParams.setAuthzEndpoint(Utils.GOWALLA_AUTHZ);
83 oauthParams.setTokenEndpoint(Utils.GOWALLA_TOKEN);
84 } else if (Utils.SMART_GALLERY.equals(app)) {
85 selected = true;
86 oauthRegParams.setAuthzEndpoint(Utils.SMART_GALLERY_AUTHZ);
87 oauthRegParams.setTokenEndpoint(Utils.SMART_GALLERY_TOKEN);
88 oauthRegParams.setRegistrationEndpoint(Utils.SMART_GALLERY_REGISTER);
89 oauthRegParams.setApplication(app);
90 oauthRegParams.setRedirectUri(Utils.REDIRECT_URI);
91 return new ModelAndView("register");
92 }
93 if (selected) {
94 oauthParams.setApplication(app);
95 oauthParams.setRedirectUri(Utils.REDIRECT_URI);
96 return new ModelAndView("get_authz");
97 }
98
99 return new ModelAndView("index");
100 }
101 }