1 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 19 public class ContactCenterAuthenticatorServlet extends HttpServlet 20 { 21 23 public void init(ServletConfig config) throws ServletException 24 { 25 super.init(config); 26 } 27 28 30 public void destroy() 31 { 32 33 } 34 35 39 protected void processRequest(HttpServletRequest request, HttpServletResponse response) 40 throws ServletException, IOException 41 { 42 String 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 ContactCenterCustomerProperty customer_property = 66 customer_bean.getCustomerProperty(customer); 67 68 if (customer_property == null) 69 { 70 request.setAttribute("errorMessage", 72 "talk.servlet.customer.undefined"); 73 goToPage("/aceapp/jsp/contactcenter/talk_internal_error.jsp", request, response); 74 return; 75 } 76 77 request.setAttribute("customerProperty", customer_property); 79 80 ContactCenterRestrictedAccessForm form_bean = new ContactCenterRestrictedAccessForm(); 82 form_bean.populate(request); 83 request.setAttribute("formBean", form_bean); 84 85 if(form_bean.isFormError() == true) 87 { 88 request.setAttribute( "errorMessage", "talk.restricted.enter.mandatory"); 89 90 String page = (String )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 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 page = (String )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 StringBuffer buffer = new StringBuffer (); 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 page = (String )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 page = (String )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 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 204 protected void doGet(HttpServletRequest request, HttpServletResponse response) 205 throws ServletException, IOException 206 { 207 processRequest(request, response); 208 } 209 210 214 protected void doPost(HttpServletRequest request, HttpServletResponse response) 215 throws ServletException, IOException 216 { 217 processRequest(request, response); 218 } 219 220 223 public String 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 235 private void goToPage( String 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 251 private HttpServletRequest request; 252 private HttpServletResponse response; 253 254 } 255 | Popular Tags |