KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > web > talk > jspbeans > ContactCenterAuthenticatorServlet


1 /*
2  * VerifyPassWordServlet.java
3  *
4  * Created on March 11, 2003
5  */

6
7 package com.quikj.application.web.talk.jspbeans;
8
9 import java.io.*;
10 import java.net.*;
11 import javax.servlet.*;
12 import javax.servlet.http.*;
13
14 /**
15  *
16  * @author Robert
17  * @version 1.0
18  */

19 public class ContactCenterAuthenticatorServlet extends HttpServlet
20 {
21     /** Initializes the servlet.
22      */

23     public void init(ServletConfig config) throws ServletException
24     {
25         super.init(config);
26     }
27     
28     /** Destroys the servlet.
29      */

30     public void destroy()
31     {
32         
33     }
34     
35     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
36      * @param request servlet request
37      * @param response servlet response
38      */

39     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
40     throws ServletException, IOException
41     {
42         String JavaDoc customer = request.getParameter("customer");
43         if (customer == null)
44         {
45             request.setAttribute("errorMessage",
46             "talk.servlet.no.customer");
47             goToPage( "/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
48             return;
49             
50         }
51         
52         ContactCenterCustomerList customer_bean = (ContactCenterCustomerList)getServletContext().getAttribute(
53         ContactCenterServlet.CUSTOMER_BEAN);
54         if (customer_bean == null)
55         {
56             request.setAttribute("errorMessage",
57             "talk.servlet.uninitialized");
58             goToPage( "/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
59             return;
60         }
61         
62         try
63         {
64             // Get the properties for this customer
65
ContactCenterCustomerProperty customer_property =
66             customer_bean.getCustomerProperty(customer);
67             
68             if (customer_property == null)
69             {
70                 // go to an error page
71
request.setAttribute("errorMessage",
72                 "talk.servlet.customer.undefined");
73                 goToPage("/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
74                 return;
75             }
76             
77             // Set the properties in the request scope
78
request.setAttribute("customerProperty", customer_property);
79                                                 
80             // Create a new instance of the form bean and populate it
81
ContactCenterRestrictedAccessForm form_bean = new ContactCenterRestrictedAccessForm();
82             form_bean.populate(request);
83             request.setAttribute("formBean", form_bean);
84             
85             // If any of the required attributes are not specified
86
if(form_bean.isFormError() == true)
87             {
88                 request.setAttribute( "errorMessage", "talk.restricted.enter.mandatory");
89                 
90                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("userLoginPage");
91                 if (page == null)
92                 {
93                     page = "/aceapp/jsp/contactcenter/talk_restricted_login.jsp";
94                 }
95                 goToPage(page, request, response );
96                 return;
97             }
98             
99             // perform a database lookup
100
ContactCenterAuthenticatorInterface validator = customer_property.getValidatorObject();
101             CustomerInformationElement e = validator.validate(form_bean.getLoginId(),
102             form_bean.getPassWord());
103             if (e == null)
104             {
105                 request.setAttribute( "errorMessage", "talk.restricted.enter.mandatory");
106                 
107                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("userLoginPage");
108                 if (page == null)
109                 {
110                     page = "/aceapp/jsp/contactcenter/talk_restricted_login.jsp";
111                 }
112                 goToPage(page, request, response);
113                 return;
114             }
115             
116             // the user is authenticated
117
StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
118             if (e.getFullName() != null)
119             {
120                 if (buffer.length() > 0)
121                 {
122                     buffer.append("&");
123                 }
124                 
125                 buffer.append(URLEncoder.encode("full-name", "UTF-8")
126                 + "="
127                 + URLEncoder.encode(e.getFullName(), "UTF-8"));
128             }
129             
130             if (e.getEmail() != null)
131             {
132                 if (buffer.length() > 0)
133                 {
134                     buffer.append("&");
135                 }
136                 
137                 buffer.append(URLEncoder.encode("email", "UTF-8")
138                 + "="
139                 + URLEncoder.encode(e.getEmail(), "UTF-8"));
140             }
141             
142             if (e.getInfo() != null)
143             {
144                 if (buffer.length() > 0)
145                 {
146                     buffer.append("&");
147                 }
148                 
149                 buffer.append(e.getInfo());
150             }
151             
152             if (form_bean.getAdditionalInfo() != null)
153             {
154                 if (buffer.length() > 0)
155                 {
156                     buffer.append("&");
157                 }
158                 
159                 buffer.append(URLEncoder.encode("addnl", "UTF-8")
160                 + "="
161                 + URLEncoder.encode(form_bean.getAdditionalInfo(), "UTF-8"));
162             }
163             
164             ContactCenterUnrestrictedAccessForm form = new ContactCenterUnrestrictedAccessForm();
165             form.setName(e.getFullName());
166             form.setEmail(e.getEmail());
167             form.setAdditionalInfo(form_bean.getAdditionalInfo());
168             form.setInfo(buffer.toString());
169             
170             request.setAttribute("formBean", form);
171             if (customer_property.getClientType().equals("JAVA") == true)
172             {
173                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("chatButtonPage");
174                 if (page == null)
175                 {
176                     page = "/aceapp/jsp/contactcenter/talk_display_applet.jsp";
177                 }
178                 goToPage(page, request, response );
179             }
180             else if (customer_property.getClientType().equals("HTML") == true)
181             {
182                 String JavaDoc page = (String JavaDoc)customer_property.getPagesParams().get("chatPage");
183                 if (page == null)
184                 {
185                     page = "/aceapp/jsp/contactcenter/talk_display_chat.jsp";
186                 }
187                 goToPage(page, request, response );
188             } return;
189         }
190         catch (Exception JavaDoc ex)
191         {
192             request.setAttribute ("exceptionMessage",
193             ex.getClass().getName() + ": " + ex.getMessage());
194             goToPage( "/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response);
195             return;
196         }
197         
198     }
199     
200     /** Handles the HTTP <code>GET</code> method.
201      * @param request servlet request
202      * @param response servlet response
203      */

204     protected void doGet(HttpServletRequest request, HttpServletResponse response)
205     throws ServletException, IOException
206     {
207         processRequest(request, response);
208     }
209     
210     /** Handles the HTTP <code>POST</code> method.
211      * @param request servlet request
212      * @param response servlet response
213      */

214     protected void doPost(HttpServletRequest request, HttpServletResponse response)
215     throws ServletException, IOException
216     {
217         processRequest(request, response);
218     }
219     
220     /** Returns a short description of the servlet.
221      *
222      */

223     public String JavaDoc getServletInfo()
224     {
225         return "This Servlets "
226         + " verifies the login id and password. Throws user back to"
227         + " the login page if verification fails";
228     }
229     
230     /** Handles the forwarding process
231      * @param String address - URL of the request
232      * @param request servlet request
233      * @param response servlet response
234      */

235     private void goToPage( String JavaDoc address,
236     HttpServletRequest request,
237     HttpServletResponse response )
238     throws ServletException, IOException
239     {
240         
241         RequestDispatcher dispatcher =
242         getServletContext().getRequestDispatcher( address );
243         dispatcher.forward( request, response );
244         
245     }
246         
247     /**
248      * Private members
249      *
250      */

251     private HttpServletRequest request;
252     private HttpServletResponse response;
253     
254 }
255
Popular Tags