Source Code Cross Referenced for LoginService.java in  » Chat » claros-intouch » org » claros » intouch » profiling » services » 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 » Chat » claros intouch » org.claros.intouch.profiling.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.claros.intouch.profiling.services;
002:
003:        import java.io.IOException;
004:        import java.io.PrintWriter;
005:        import java.util.HashMap;
006:        import java.util.Set;
007:
008:        import javax.servlet.ServletException;
009:        import javax.servlet.http.HttpServlet;
010:        import javax.servlet.http.HttpServletRequest;
011:        import javax.servlet.http.HttpServletResponse;
012:
013:        import org.apache.commons.logging.Log;
014:        import org.apache.commons.logging.LogFactory;
015:        import org.claros.commons.auth.MailAuth;
016:        import org.claros.commons.auth.exception.LoginInvalidException;
017:        import org.claros.commons.auth.models.AuthProfile;
018:        import org.claros.commons.exception.SystemException;
019:        import org.claros.commons.mail.exception.ServerDownException;
020:        import org.claros.commons.mail.models.ConnectionMetaHandler;
021:        import org.claros.commons.mail.models.ConnectionProfile;
022:        import org.claros.commons.mail.models.ConnectionProfileList;
023:        import org.claros.intouch.webmail.controllers.FolderController;
024:        import org.claros.intouch.webmail.factory.FolderControllerFactory;
025:
026:        public class LoginService extends HttpServlet {
027:            private static final long serialVersionUID = -7565470602365037845L;
028:            private static Log log = LogFactory.getLog(LoginService.class);
029:
030:            /**
031:             * The doPost method of the servlet. <br>
032:             *
033:             * This method is called when a form has its tag value method equals to post.
034:             * 
035:             * @param request the request send by the client to the server
036:             * @param response the response send by the server to the client
037:             * @throws ServletException if an error occurred
038:             * @throws IOException if an error occurred
039:             */
040:            public void doPost(HttpServletRequest request,
041:                    HttpServletResponse response) throws ServletException,
042:                    IOException {
043:
044:                response.setHeader("Expires", "-1");
045:                response.setHeader("Pragma", "no-cache");
046:                response.setHeader("Cache-control", "no-cache");
047:                response.setHeader("Content-Type", "text/html; charset=utf-8");
048:
049:                PrintWriter out = response.getWriter();
050:
051:                log
052:                        .debug("Fetching the server profile from the config.xml file");
053:
054:                try {
055:                    HashMap map = ConnectionProfileList.getConList();
056:                    if (map != null) {
057:                        Set set = map.keySet();
058:                        if (set == null) {
059:                            log
060:                                    .fatal("Mail server profile is not accessable. Can't continue. :( Sorry. Please check your config.xml file.1");
061:                            throw new SystemException();
062:                        }
063:                        Object arr[] = set.toArray();
064:                        if (arr == null || arr.length <= 0) {
065:                            log
066:                                    .fatal("Mail server profile is not accessable. Can't continue. :( Sorry. Please check your config.xml file.2");
067:                            throw new SystemException();
068:                        }
069:                        ConnectionProfile profile = ConnectionProfileList
070:                                .getProfileByShortName((String) arr[0]);
071:                        if (profile == null) {
072:                            log
073:                                    .fatal("Mail server profile is not accessable. Can't continue. :( Sorry. Please check your config.xml file.3");
074:                            throw new SystemException();
075:                        }
076:                        log
077:                                .debug("I've got the mail server profile. Keep on... "
078:                                        + profile.toString());
079:
080:                        String username = request.getParameter("username");
081:                        String password = request.getParameter("password");
082:
083:                        if (username != null && password != null) {
084:                            AuthProfile auth = new AuthProfile();
085:                            auth.setUsername(username);
086:                            auth.setPassword(password);
087:                            ConnectionMetaHandler handler = (ConnectionMetaHandler) request
088:                                    .getSession().getAttribute("handler");
089:                            log.debug("Starting authentication");
090:
091:                            try {
092:                                handler = MailAuth.authenticate(profile, auth,
093:                                        handler);
094:                                if (handler != null) {
095:                                    log
096:                                            .debug("Authentication was successful... :) Good news!");
097:
098:                                    request.getSession().setAttribute(
099:                                            "handler", handler);
100:                                    request.getSession().setAttribute("auth",
101:                                            auth);
102:                                    request.getSession().setAttribute(
103:                                            "profile", profile);
104:
105:                                    // create default mailboxes if not exists
106:                                    try {
107:                                        log
108:                                                .debug("Trying to create default mailbox folders if they don't exist.");
109:
110:                                        FolderControllerFactory factory = new FolderControllerFactory(
111:                                                auth, profile, handler);
112:                                        FolderController foldCont = factory
113:                                                .getFolderController();
114:                                        foldCont.createDefaultFolders();
115:                                    } catch (Exception e) {
116:                                        log
117:                                                .error(
118:                                                        "unable to create default folders!!!! It will probably fail but giving a try",
119:                                                        e);
120:                                    }
121:
122:                                    log
123:                                            .debug("Everything was fine. Sending an OK signal to the UI");
124:                                    out.print("ok");
125:                                } else {
126:                                    log
127:                                            .debug("Can't authenticate. username and password is most probably wrong.1");
128:                                    out.print("no");
129:                                }
130:                            } catch (LoginInvalidException e) {
131:                                log
132:                                        .debug("Can't authenticate. username and password is most probably wrong.3");
133:                                out.print("no");
134:                            } catch (ServerDownException e) {
135:                                log
136:                                        .error("Can't reach the server. Please make sure everything is fine at config.xml file and server is up and running.");
137:                                out.print("system");
138:                            }
139:                        } else {
140:                            log
141:                                    .debug("Can't authenticate. username and password is most probably wrong.2");
142:                            out.print("no");
143:                        }
144:                    } else {
145:                        throw new SystemException();
146:                    }
147:                } catch (SystemException e) {
148:                    log
149:                            .error(
150:                                    "Can't get mail server list. Please make sure everything is fine at config.xml file.",
151:                                    e);
152:                    out.print("system");
153:                } catch (Throwable e) {
154:                    log
155:                            .error(
156:                                    "Unknown error. Please check logs for more information. ",
157:                                    e);
158:                    out.print("system");
159:                }
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.