Source code: org/acs/damsel/client/login/LoginAction.java
1 package org.acs.damsel.client.login;
2
3 import javax.servlet.http.*;
4
5 import org.acs.damsel.client.*;
6 import org.acs.damsel.srvr.user.*;
7 import org.acs.damsel.srvr.auth.*;
8 import org.apache.struts.action.*;
9
10 /**
11 * Extracts username and password from the login form, request user object
12 * from the database, and returns errors if login is not successful
13 * otherwise links to the discovery page
14 */
15 public class LoginAction
16 extends Action {
17 public ActionForward execute(ActionMapping actionMapping,
18 ActionForm actionForm,
19 HttpServletRequest httpServletRequest,
20 HttpServletResponse httpServletResponse) {
21
22 LoginForm loginForm = (LoginForm) actionForm;
23
24 String username = loginForm.getUsername();
25 String password = loginForm.getPassword();
26
27 if (username == null || username.trim().length() == 0) {
28 ActionErrors errors = new ActionErrors();
29 errors.add("login", new ActionError("login.username.null"));
30 this.saveErrors(httpServletRequest, errors);
31 if (password == null || password.trim().length() == 0) {
32 errors.add("login", new ActionError("login.password.null"));
33 this.saveErrors(httpServletRequest, errors);
34 }
35 return actionMapping.findForward("failure");
36 }
37 if (password == null || password.trim().length() == 0) {
38 ActionErrors errors = new ActionErrors();
39 errors.add("login", new ActionError("login.password.null"));
40 this.saveErrors(httpServletRequest, errors);
41 return actionMapping.findForward("failure");
42 }
43
44 AuthMgr am = ClientApp.instance().getAuthMgr();
45 User user = am.getUser(username, password);
46
47 if (user == null) {
48 ActionErrors errors = new ActionErrors();
49 errors.add("login", new ActionError("login.invalid"));
50 this.saveErrors(httpServletRequest, errors);
51 return actionMapping.findForward("failure");
52 }
53 else {
54 httpServletRequest.getSession(true).setAttribute("User", user);
55 return actionMapping.findForward("success");
56 }
57 }
58 }