KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > common > actions > LoginAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24 package org.infoglue.cms.applications.common.actions;
25
26 import org.infoglue.cms.controllers.usecases.common.LoginUCC;
27 import org.infoglue.cms.controllers.usecases.common.LoginUCCFactory;
28 import org.infoglue.cms.security.AuthenticationModule;
29
30 public class LoginAction extends InfoGlueAbstractAction
31 {
32     private static final long serialVersionUID = 35668814570153876L;
33
34     private String JavaDoc userName = null;
35     private String JavaDoc password = null;
36     private String JavaDoc errorMessage = "";
37     private String JavaDoc referringUrl = null;
38     
39     public void setUserName(String JavaDoc userName)
40     {
41         this.userName = userName;
42     }
43     
44     public String JavaDoc getUserName()
45     {
46         return this.userName;
47     }
48
49     public void setPassword(String JavaDoc password)
50     {
51         this.password = password;
52     }
53     
54     public String JavaDoc getPassword()
55     {
56         return this.password;
57     }
58
59     public String JavaDoc getErrorMessage()
60     {
61         return this.errorMessage;
62     }
63     
64     public String JavaDoc doExecute() throws Exception JavaDoc
65     {
66         if(this.getRequest().getRemoteUser() != null)
67             return "redirect";
68         else
69             return "success";
70     }
71
72     public String JavaDoc doInvalidLogin() throws Exception JavaDoc
73     {
74         if(this.getRequest().getRemoteUser() != null)
75         {
76             return "redirect";
77         }
78         else
79         {
80             return "invalidLogin";
81         }
82     }
83
84     public String JavaDoc doLogonUser() throws Exception JavaDoc
85     {
86         LoginUCC loginController = LoginUCCFactory.newLoginUCC();
87         boolean isAccepted = loginController.authorizeSystemUser(this.userName, this.password);
88         
89         if(isAccepted)
90         {
91             return "userAccepted";
92         }
93         else
94         {
95             errorMessage = "The logon information given was incorrect, please verify and try again.";
96             return "invalidLogin";
97         }
98     }
99     
100     /**
101      * This command invalidates the current session and then calls the authentication module logout method so it can
102      * do it's stuff. Sometimes it involves redirecting the user somewhere and then we returns nothing in this method.
103      */

104
105     public String JavaDoc doLogout() throws Exception JavaDoc
106     {
107         getHttpSession().invalidate();
108         
109         AuthenticationModule authenticationModule = AuthenticationModule.getAuthenticationModule(null, null);
110         boolean redirected = authenticationModule.logoutUser(getRequest(), getResponse());
111         
112         if(redirected)
113             return NONE;
114         else
115             return "logout";
116     }
117     
118     public String JavaDoc getPrincipal()
119     {
120         java.security.Principal JavaDoc principal = getRequest().getUserPrincipal();
121         return "Principal:" + principal.getName();
122     }
123
124     public String JavaDoc getReferringUrl()
125     {
126         return referringUrl;
127     }
128
129     public void setReferringUrl(String JavaDoc string)
130     {
131         referringUrl = string;
132     }
133
134 }
Popular Tags