View Javadoc

1   /*
2    *  $Id: Login.java,v 1.8 2004/08/03 08:33:53 roku Exp $ 
3    *
4    *  Copyright 2004 University of Hannover
5    *
6    *  Licensed under the Apache License, Version 2.0 (the "License");
7    *  you may not use this file except in compliance with the License.
8    *  You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package olr.presentation;
20  
21  import org.apache.log4j.Logger;
22  
23  import olr.om.RdfUser;
24  import olr.om.RdfUserPeer;
25  
26  import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
27  import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
28  
29  public class Login extends ExtendedHttpPresentation {
30  
31      public boolean loggedInUserRequired()
32      {
33          return false;
34      }
35  
36      public String handleDefault()
37          throws HttpPresentationException
38      {
39          if(getUser() != null)
40              throw new ClientPageRedirectException("Welcome1.po");
41          else
42              return showPage();
43      }
44  
45      public String handleLogout() throws HttpPresentationException
46      {
47          if(getUser() != null)
48              try 
49              {
50                  getSessionData().clearLock();
51                  clearSession();
52              }
53              catch(Exception e) 
54              {
55                  throw new HttpPresentationException(e);
56              }        
57              
58          return showPage();
59      }
60  
61      public String handleLogin()
62          throws HttpPresentationException
63      {
64          String login = getComms().request.getParameter(LOGIN_NAME);
65          String password = getComms().request.getParameter(PASSWORD_NAME);
66          RdfUser user = null;
67          try
68          {
69              try
70              {
71                  user = RdfUserPeer.getUser(login, password);
72              }
73              catch(Exception e)
74              {
75                  String s1 = showPage(e.getMessage());
76                  return s1;
77              }
78              if(user == null)
79              {
80                  String s = showPage("Incorrect username/password combination!");
81                  return s;
82              } else
83              {
84                  setUser(user);
85                  throw new ClientPageRedirectException("Welcome1.po");
86              }
87          }
88          catch(Exception ex)
89          {
90              Logger.getLogger(getClass()).debug("System error finding user: ".concat(String.valueOf(String.valueOf(ex.getMessage()))));
91              throw new HttpPresentationException("System error finding user", ex);
92          }
93      }
94  
95      public String showPage()
96      {
97          return showPage(null);
98      }
99  
100     public String showPage(String errorMsg)
101     {
102         LoginHTML page = new LoginHTML();
103         if(errorMsg != null)
104             page.setTextErrorText(errorMsg);
105         return page.toDocument();
106     }
107 
108     private static String LOGIN_NAME = "login";
109     private static String PASSWORD_NAME = "password";
110 
111 }