| 1 package com.quikj.application.communicator.admin.controller; 2 3 import java.io.IOException ; 4 import java.util.Locale ; 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 import org.apache.struts.action.Action; 9 import org.apache.struts.action.ActionError; 10 import org.apache.struts.action.ActionErrors; 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import java.sql.*; 15 import com.quikj.application.communicator.admin.model.*; 16 import com.quikj.server.framework.*; 17 import com.quikj.client.raccess.*; 18 19 26 27 public final class LogonAction extends Action 28 { 29 44 public ActionForward execute(ActionMapping mapping, 45 ActionForm form, 46 HttpServletRequest request, 47 HttpServletResponse response) 48 throws IOException , ServletException  49 { 50 51 Locale locale = getLocale(request); 53 ActionErrors errors = new ActionErrors(); 54 55 Connection c = (Connection)request.getSession().getAttribute("connection"); 57 if (c == null) 58 { 59 c = DBConnection.getInstance().getConnection(); 60 } 61 62 if (c == null) { 64 errors.add(ActionErrors.GLOBAL_ERROR, 65 new ActionError("error.database.error")); 66 } 67 68 AccountElement userinfo = null; 69 String authcode = null; 70 71 if (errors.isEmpty() == true) 72 { 73 AccountsTable accounts = new AccountsTable(AdminConfig.getInstance().getDBParams().getAdminDb()); 74 accounts.setConnection(c); 75 76 userinfo = accounts.authenticate(((LogonForm)form).getUsername(), 77 ((LogonForm) form).getPassword()); 78 79 if (userinfo == null) 80 { 81 errors.add(ActionErrors.GLOBAL_ERROR, 82 new ActionError("error.authentication.error")); 83 84 try 85 { 86 c.close(); 87 } 88 catch (SQLException ex) 89 { 90 ; 91 } 92 } 93 else 94 { 95 RemoteAccessClient cl = (RemoteAccessClient)request.getSession().getServletContext().getAttribute("remoteAccess"); 97 if (cl == null) 98 { 99 errors.add(ActionErrors.GLOBAL_ERROR, 100 new ActionError("error.rmi.error")); 101 102 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 103 "LogonAction.execute()/" 104 + ((LogonForm)form).getUsername() 105 + ": Could not obtain RMI client object"); 106 } 107 else 108 { 109 try 110 { 111 authcode = cl.getRemoteAccess().getParam("com.quikj.application.web.oamp.plugin.CommunicatorClientList", 112 "register:" + ((LogonForm)form).getUsername() 113 + ':' + ((LogonForm) form).getPassword()); 114 if (authcode == null) 115 { 116 errors.add(ActionErrors.GLOBAL_ERROR, 117 new ActionError("error.rmi.error")); 118 119 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 120 "LogonAction.execute()/" 121 + ((LogonForm)form).getUsername() 122 + ": Could not obtain authcode from CommunicatorClientList"); 123 } 124 } 125 catch (Exception ex) 126 { 127 errors.add(ActionErrors.GLOBAL_ERROR, 128 new ActionError("error.rmi.error")); 129 130 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 131 "LogonAction.execute()/" 132 + ((LogonForm)form).getUsername() 133 + ": RMIException: " + ex.getMessage()); 134 } 135 } 136 } 137 } 138 139 if (errors.isEmpty() == true) 140 { 141 request.getSession().setAttribute("connection", c); 142 request.getSession().setAttribute("userInfo", userinfo); 143 144 if (authcode != null) 145 { 146 request.getSession().setAttribute("authCode", authcode); 147 } 148 149 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 150 "User " + ((LogonForm)form).getUsername() + " logged in"); 151 152 return (mapping.findForward("main_menu")); 153 } 154 else 155 { 156 saveErrors(request, errors); 157 return (new ActionForward(mapping.getInput())); 158 } 159 160 } 161 } 162 | Popular Tags |