Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Accounting and Billing Portal
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[abportal] Annotation of /src/main/java/eu/smartlm/abs/portal/security/login/LoginController.java
[abportal] / src / main / java / eu / smartlm / abs / portal / security / login / LoginController.java Repository:
ViewVC logotype

Annotation of /src/main/java/eu/smartlm/abs/portal/security/login/LoginController.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : dgarcia 1 package eu.smartlm.abs.portal.security.login;
2 :    
3 :     import javax.portlet.ActionResponse;
4 :    
5 :     import org.springframework.beans.factory.annotation.Autowired;
6 :     import org.springframework.beans.factory.annotation.Qualifier;
7 :     import org.springframework.stereotype.Controller;
8 :     import org.springframework.validation.BindingResult;
9 :     import org.springframework.web.bind.WebDataBinder;
10 :     import org.springframework.web.bind.annotation.InitBinder;
11 :     import org.springframework.web.bind.annotation.ModelAttribute;
12 :     import org.springframework.web.bind.annotation.RequestMapping;
13 :     import org.springframework.web.bind.annotation.SessionAttributes;
14 :     import org.springframework.web.bind.support.SessionStatus;
15 :     import org.springframework.web.portlet.bind.annotation.ActionMapping;
16 :     import org.springframework.web.portlet.bind.annotation.RenderMapping;
17 :    
18 :     import eu.smartlm.abs.portal.security.login.model.User;
19 :     import eu.smartlm.abs.portal.security.login.service.LoginService;
20 :     import eu.smartlm.abs.portal.view.event.LoginEventData;
21 :    
22 :    
23 :     /**
24 :     * Login control that limits the query to the Accounting and Billing Database
25 :     * @author David García Pérez - CESGA
26 :     */
27 :     @Controller(value="loginController")
28 :     @RequestMapping(value = "VIEW")
29 :     @SessionAttributes(types = User.class)
30 :     public class LoginController {
31 :     public static int LOGGED_IN = 100;
32 :     public static int LOGGED_OUT = 200;
33 :     public static String LOGIN_EVENT = "loginEvent";
34 :     private int status = 200;
35 :     private User user;
36 :    
37 :     @Autowired
38 :     @Qualifier("myLoginService")
39 :     private LoginService loginService;
40 :    
41 :     public void setLoginService(LoginService loginService) {
42 :     this.loginService = loginService;
43 :     }
44 :    
45 :     /**
46 :     * Pointer to the default jsp portlet to show
47 :     * @return the name of the jsp portlet
48 :     */
49 :     @RenderMapping
50 :     public String showLoginForm() {
51 :     if(status == LOGGED_OUT)
52 :     return "login";
53 :     else if (status == LOGGED_IN)
54 :     return "logged";
55 :     else
56 :     return "login";
57 :     }
58 :    
59 :     /**
60 :     * Pointer to the jsp page with the logged information
61 :     * @return the name of the jsp page
62 :     */
63 :     @RenderMapping(params = "myaction=loggedIn")
64 :     public String showLoggedInPage() {
65 :     return "logged";
66 :     }
67 :    
68 :     /**
69 :     * User object that it is created to be passed to the jsp page
70 :     * @return a User Object
71 :     */
72 :     @ModelAttribute("user")
73 :     public User getCommandObject() {
74 :     if (user == null) return new User();
75 :     return user;
76 :     }
77 :    
78 :     /**
79 :     * Initicialices the binder that associates fields of the jsp page to the user model
80 :     * @param binder
81 :     */
82 :     @InitBinder("user")
83 :     public void initBinder(WebDataBinder binder) { }
84 :    
85 :    
86 :     /**
87 :     * Action to be processed when a user tries to login
88 :     */
89 :     @ActionMapping(params = "myaction=loginUser")
90 :     public void loginUser(@ModelAttribute User user, BindingResult bindingResult, ActionResponse response, SessionStatus sessionStatus) {
91 :    
92 :     if(loginService.isValidLogin(user)) {
93 :     status = LOGGED_IN;
94 :     this.user = loginService.getUser(user.getUsername());
95 :     response.setEvent(LOGIN_EVENT, new LoginEventData(status, this.user));
96 :     response.setRenderParameter("myaction", "loggedIn");
97 :     } else {
98 :     status = LOGGED_OUT;
99 :     }
100 :     }
101 :    
102 :     /**
103 :     * Action to be processed when a user logs out
104 :     */
105 :     @ActionMapping(params = "myaction=logoutUser")
106 :     public void loggoutUser(ActionResponse response, SessionStatus sessionStatus) {
107 :     status = LOGGED_OUT;
108 :     user = null;
109 :     response.setEvent(LOGIN_EVENT, new LoginEventData(status, user));
110 :     response.setRenderParameter("myaction" , "login");
111 :     sessionStatus.setComplete();
112 :     }
113 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge