KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > actions > LoginAction


1 /*
2  * Copyright (C) 2002 Erik Swenson - eswenson@opensourcesoft.net
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

19
20 package org.efs.openreports.actions;
21
22 import com.opensymphony.xwork.ActionContext;
23 import com.opensymphony.xwork.ActionSupport;
24
25 import org.efs.openreports.ORStatics;
26 import org.efs.openreports.objects.ReportUser;
27 import org.efs.openreports.providers.UserProvider;
28 import org.efs.openreports.providers.UserProviderAware;
29 import org.efs.openreports.util.LocalStrings;
30
31 public class LoginAction extends ActionSupport implements UserProviderAware
32 {
33     private String JavaDoc userName;
34     private String JavaDoc password;
35
36     private UserProvider userProvider;
37
38     public String JavaDoc execute()
39     {
40         if (userName == null || userName.length() < 1 ||
41                 password == null || password.length() < 1)
42         {
43             addActionError(LocalStrings.getString(LocalStrings.ERROR_LOGIN_INCOMPLETE));
44             return INPUT;
45         }
46
47         try
48         {
49             ReportUser user = userProvider.getUser(userName);
50
51             if (user == null || !user.getPassword().equals(password))
52             {
53                 addActionError(LocalStrings.getString(LocalStrings.ERROR_LOGIN_INVALID));
54                 return INPUT;
55             }
56
57             ActionContext.getContext().getSession().put("user", user);
58                         
59             if (user.isDashboardUser()) return ORStatics.DASHBOARD_ACTION;
60             
61             return SUCCESS;
62         }
63         catch (Exception JavaDoc e)
64         {
65             e.printStackTrace();
66             addActionError(e.toString());
67             return INPUT;
68         }
69     }
70
71     public String JavaDoc getPassword()
72     {
73         return password;
74     }
75
76     public String JavaDoc getUserName()
77     {
78         return userName;
79     }
80
81     public void setPassword(String JavaDoc password)
82     {
83         this.password = password;
84     }
85
86     public void setUserName(String JavaDoc userName)
87     {
88         this.userName = userName;
89     }
90
91     public void setUserProvider(UserProvider userProvider)
92     {
93         this.userProvider = userProvider;
94     }
95
96 }
Popular Tags