Source Code Cross Referenced for MailSession.java in  » Groupware » ivatagroupware » com » ivata » groupware » business » mail » session » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Groupware » ivatagroupware » com.ivata.groupware.business.mail.session 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2001 - 2005 ivata limited.
003:         * All rights reserved.
004:         * -----------------------------------------------------------------------------
005:         * ivata groupware may be redistributed under the GNU General Public
006:         * License as published by the Free Software Foundation;
007:         * version 2 of the License.
008:         *
009:         * These programs are free software; you can redistribute them and/or
010:         * modify them under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; version 2 of the License.
012:         *
013:         * These programs are distributed in the hope that they will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016:         *
017:         * See the GNU General Public License in the file LICENSE.txt for more
018:         * details.
019:         *
020:         * If you would like a copy of the GNU General Public License write to
021:         *
022:         * Free Software Foundation, Inc.
023:         * 59 Temple Place - Suite 330
024:         * Boston, MA 02111-1307, USA.
025:         *
026:         *
027:         * To arrange commercial support and licensing, contact ivata at
028:         *                  http://www.ivata.com/contact.jsp
029:         * -----------------------------------------------------------------------------
030:         * $Log: MailSession.java,v $
031:         * Revision 1.4  2005/10/02 14:08:59  colinmacleod
032:         * Added/improved log4j logging.
033:         *
034:         * Revision 1.3  2005/09/14 16:16:52  colinmacleod
035:         * Removed unused local and class variables.
036:         * Added serialVersionUID.
037:         *
038:         * Revision 1.2  2005/04/09 17:20:01  colinmacleod
039:         * Changed copyright text to GPL v2 explicitly.
040:         *
041:         * Revision 1.1.1.1  2005/03/10 17:51:16  colinmacleod
042:         * Restructured ivata op around Hibernate/PicoContainer.
043:         * Renamed ivata groupware.
044:         *
045:         * Revision 1.6  2004/11/12 18:16:08  colinmacleod
046:         * Ordered imports.
047:         *
048:         * Revision 1.5  2004/11/12 15:57:25  colinmacleod
049:         * Removed dependencies on SSLEXT.
050:         * Moved Persistence classes to ivata masks.
051:         *
052:         * Revision 1.4  2004/07/13 19:48:12  colinmacleod
053:         * Moved project to POJOs from EJBs.
054:         * Applied PicoContainer to services layer (replacing session EJBs).
055:         * Applied Hibernate to persistence layer (replacing entity EJBs).
056:         *
057:         * Revision 1.3  2004/03/21 21:16:39  colinmacleod
058:         * Shortened name to ivata op.
059:         *
060:         * Revision 1.2  2004/02/01 22:07:32  colinmacleod
061:         * Added full names to author tags
062:         *
063:         * Revision 1.1.1.1  2004/01/27 20:59:58  colinmacleod
064:         * Moved ivata openportal to SourceForge..
065:         *
066:         * Revision 1.2  2003/10/15 14:11:33  colin
067:         * fixing for XDoclet
068:         *
069:         * Revision 1.1  2003/02/24 19:09:24  colin
070:         * moved to business
071:         *
072:         * Revision 1.3  2003/02/04 17:39:22  colin
073:         * copyright notice
074:         *
075:         * Revision 1.2  2002/09/09 11:00:38  colin
076:         * made session classes serializable :-)
077:         *
078:         * Revision 1.3  2002/09/09 08:44:52  colin
079:         * made new mail session class to abstract the non-serializable JavaMail session
080:         *
081:         * Revision 1.1  2002/09/09 08:26:37  colin
082:         * first version of MailSession logs into session everytime
083:         * -----------------------------------------------------------------------------
084:         */
085:        package com.ivata.groupware.business.mail.session;
086:
087:        import org.apache.log4j.Logger;
088:
089:        import java.security.NoSuchProviderException;
090:        import java.util.Properties;
091:
092:        import javax.mail.MessagingException;
093:        import javax.mail.Session;
094:        import javax.mail.Store;
095:        import javax.naming.AuthenticationException;
096:
097:        import org.picocontainer.PicoContainer;
098:
099:        import com.ivata.groupware.admin.security.server.AbstractSecuritySession;
100:        import com.ivata.groupware.admin.security.server.SecurityServerException;
101:        import com.ivata.groupware.admin.security.user.UserDO;
102:        import com.ivata.mask.util.SystemException;
103:
104:        /**
105:         * <p><code>javax.mail.Session</code> is not serializable and cannot
106:         * be passed from client to server. This class stores the login details
107:         * an provides a new session instance when required, by logging in
108:         * again.</p>
109:         *
110:         * @since 2002-09-08
111:         * @author Colin MacLeod
112:         * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
113:         * @version $Revision: 1.4 $
114:         */
115:        public class MailSession extends AbstractSecuritySession {
116:            /**
117:             * Logger for this class.
118:             */
119:            private static final Logger logger = Logger
120:                    .getLogger(MailSession.class);
121:
122:            /**
123:             * Serialization version (for <code>Serializable</code> interface).
124:             */
125:            private static final long serialVersionUID = 1L;
126:
127:            /**
128:             * <p>Contains all of the properties necessary to log into the
129:             * <code>javax.mail.Session</code>.</p>
130:             */
131:            private Properties mailProperties = null;
132:
133:            /**
134:             * <p>Used to autheticate this mail session, whenever the
135:             * <code>javax.mail.Session</code> is recreated.</p>
136:             */
137:            public MailAuthenticator authenticator;
138:
139:            /**
140:             * Construct a new mail session.
141:             */
142:            public MailSession(PicoContainer container, UserDO user)
143:                    throws SystemException {
144:                super (container, user);
145:            }
146:
147:            /**
148:             * <p>Logs into the mail session for the first time. This stores the
149:             * user name and password so that the session can be continued again
150:             * later.</p>
151:             *
152:             * @userName name of the user to log in.
153:             * @param password clear-text user's password to log into the mail
154:             * server.
155:             * @param mailProperties all of the mail properties necessary to login
156:             * to the system.
157:             * @throws AuthenticationException thrown by JavaMail if the user cannot
158:             *      login.
159:             * @return newly created mail session.
160:             */
161:            public Session login(final String password,
162:                    final Properties mailProperties)
163:                    throws SecurityServerException, NoSuchProviderException,
164:                    MessagingException {
165:                if (logger.isDebugEnabled()) {
166:                    logger.debug("login(String password = " + password
167:                            + ", Properties mailProperties = " + mailProperties
168:                            + ") - start");
169:                }
170:
171:                authenticator = new MailAuthenticator(mailProperties
172:                        .getProperty("mail.user"), password);
173:                this .mailProperties = mailProperties;
174:
175:                Session returnSession = getJavaMailSession();
176:                if (logger.isDebugEnabled()) {
177:                    logger
178:                            .debug("login(String, Properties) - end - return value = "
179:                                    + returnSession);
180:                }
181:                return returnSession;
182:            }
183:
184:            /**
185:             * <p>Return the current mail session as a
186:             * <code>javax.mail.Session</code> instance. This involves logging in
187:             * again.</p>
188:             *
189:             * @throws AuthenticationException thrown by JavaMail if the user cannot login.
190:             * @throws NoSuchProviderException thrown by JavaMail if the user cannot login.
191:             * @throws MessagingException thrown by JavaMail if the user cannot login.
192:             * @return the current mail session as a
193:             * <code>javax.mail.Session</code> instance.
194:             */
195:            public Session getJavaMailSession() throws SecurityServerException,
196:                    NoSuchProviderException, MessagingException {
197:                if (logger.isDebugEnabled()) {
198:                    logger.debug("getJavaMailSession() - start");
199:                }
200:
201:                Session javaSession = Session.getInstance(mailProperties,
202:                        authenticator);
203:                Store store = javaSession.getStore("imap");
204:                if (!store.isConnected()) {
205:                    store.connect();
206:                }
207:                store.close();
208:
209:                if (logger.isDebugEnabled()) {
210:                    logger.debug("getJavaMailSession() - end - return value = "
211:                            + javaSession);
212:                }
213:                return javaSession;
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.