KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scioworks > imap > presentation > loginAction


1 /* -----------------------------------------------------------------------------
2  * Copyright (c) 2001, Low Kin Onn
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *
8  * Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * Neither name of the Scioworks Pte. Ltd. nor the names of its contributors
16  * may beused to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * -----------------------------------------------------------------------------
31  */

32
33 package scioworks.imap.presentation;
34
35 import com.lutris.appserver.server.httpPresentation.*;
36
37 import org.w3c.dom.*;
38 import org.w3c.dom.html.*;
39
40 import scioworks.imap.presentation.imapWeb.*;
41 import scioworks.imap.presentation.base.BasePO;
42 import scioworks.imap.presentation.security.*;
43
44
45
46 import javax.mail.*;
47 import javax.mail.internet.*;
48 import javax.activation.*;
49
50
51 public class loginAction extends BasePO {
52
53   // Override login requirement
54
protected boolean isLoginRequired() {
55     return false;
56   }
57
58   private String JavaDoc login(String JavaDoc username, String JavaDoc password)
59       throws HttpPresentationException {
60
61
62   DefaultEmailLogin login = new DefaultEmailLogin(username,password);
63   
64     try {
65  //We need to allow imapWeb_pres to be functional , so if the requested url is imapWeb_pres we dont try to connect to server
66
//to see default HTML pages
67
String JavaDoc uri = m_comms.request.getRequestURI();
68          boolean is= uri.startsWith("/imapWeb_pres");
69           
70            if(is)
71      super.getImapWebSessionData().setImapSession(Session.getDefaultInstance(System.getProperties(),null));
72    
73       // try to login
74
else{
75       login.login();
76
77       super.getImapWebSessionData().setImapURL(login.getSessionData().getImapURL());
78       super.getImapWebSessionData().setImapSession(login.getSessionData().getImapSession());
79       super.getImapWebSessionData().setImapStore(login.getSessionData().getImapStore());
80       }
81
82     } catch (ACLException e) {
83       // failed to login
84
return this.showPage(e.getMessage());
85     }
86     welcomeHTML page = (welcomeHTML)m_comms.xmlcFactory.create(welcomeHTML.class);
87     return page.toDocument();
88   }
89
90   public String JavaDoc handleDefault()
91     throws ServerPageRedirectException, HttpPresentationException {
92
93     String JavaDoc pUsername = getStringParameter(PARAM_username);
94     String JavaDoc pPassword = getStringParameter(PARAM_password);
95     String JavaDoc pEvent = getStringParameter(PARAM_event);
96
97     if (pEvent.equals(EVENT_login)) {
98       return login(pUsername, pPassword);
99     } else {
100       return showPage(null);
101     }
102   }
103
104     public String JavaDoc showPage(String JavaDoc errorMsg) {
105
106       loginHTML page = (loginHTML)m_comms.xmlcFactory.create(loginHTML.class);
107
108       //First priority: try to use the passed-in error message
109
// Second priority: try to use the session data's error message
110
// If there are no error messages then clear the prototype error text
111
if(null != errorMsg ||
112          null != (errorMsg = this.getImapWebSessionData().getAndClearUserMessage())) {
113           page.setTextErrorText(errorMsg);
114       } else {
115           page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
116       }
117
118       return page.toDocument();
119     }
120 }
121
Popular Tags