1 5 6 package com.quikj.application.communicator.applications.webtalk.controller; 7 8 import javax.servlet.http.*; 9 import org.apache.struts.action.*; 10 import org.apache.struts.util.*; 11 import java.sql.*; 12 import java.io.UnsupportedEncodingException ; 13 import java.net.*; 14 import java.util.*; 15 16 import com.quikj.application.communicator.admin.model.*; 17 import com.quikj.application.communicator.admin.controller.*; 18 import com.quikj.application.communicator.applications.webtalk.model.*; 19 import com.quikj.client.raccess.*; 20 import com.quikj.server.framework.*; 21 25 public class UserManagementAction extends Action 26 { 27 28 29 public UserManagementAction() 30 { 31 } 32 33 public ActionForward execute(ActionMapping mapping, 34 ActionForm form, 35 HttpServletRequest request, 36 HttpServletResponse response) throws UnsupportedEncodingException 37 { 38 UserManagementForm uform = (UserManagementForm)form; 39 40 ActionErrors errors = new ActionErrors(); 41 42 Connection c = (Connection)request.getSession().getAttribute("connection"); 43 if (c == null) 44 { 45 errors.add(ActionErrors.GLOBAL_ERROR, 46 new ActionError("error.not.logged.in")); 47 saveErrors(request, errors); 48 return mapping.findForward("logon"); 49 } 50 51 AccountElement element = (AccountElement)request.getSession().getAttribute("userInfo"); 52 if (element.isAdminLevel() == false) 53 { 54 errors.add(ActionErrors.GLOBAL_ERROR, 55 new ActionError("error.insufficient.privilege")); 56 saveErrors(request, errors); 57 58 return mapping.findForward("main_menu"); 59 } 60 61 GroupTable groups = new GroupTable(); 62 groups.setConnection(c); 63 ArrayList group_list = groups.list(); 64 if (group_list != null) 65 { 66 ArrayList list = new ArrayList(); 67 Iterator iter = group_list.iterator(); 68 69 while (iter.hasNext() == true) 70 { 71 String group = (String )iter.next(); 72 list.add(new LabelValueBean(group, URLEncoder.encode(group, "UTF-8"))); 73 } 74 75 uform.setUserGroups(list); 76 } 77 78 if (uform.getSubmit().equals("Find") == true) 79 { 80 UserTable user_tbl = new UserTable(); 81 user_tbl.setConnection(c); 82 83 UserElement e = user_tbl.query(uform.getName()); 84 85 if (e == null) 86 { 87 errors.add(ActionErrors.GLOBAL_ERROR, 88 new ActionError("error.no.such.user")); 89 90 if (user_tbl.getErrorMessage() != null) 91 { 92 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 93 "UserManagementAction.execute()/Find/by-" 94 + element.getName() 95 + ": " 96 + user_tbl.getErrorMessage()); 97 } 98 } 99 else 100 { 101 uform.setAdditionalInfo(e.getAdditionalInfo()); 102 uform.setAddress(e.getAddress()); 103 uform.setFullName(e.getFullName()); 104 uform.setName(e.getName()); 105 uform.setUnavailXferTo(e.getUnavailXferTo()); 106 uform.setGatekeeper(e.getGatekeeper()); 107 Object [] owns = e.getOwnsGroups(); 108 if (owns != null) 109 { 110 for (int i = 0; i < owns.length; i++) 111 { 112 owns[i] = URLEncoder.encode((String )owns[i], "UTF-8"); 113 } 114 } 115 uform.setOwnsGroups(owns); 116 117 Object [] belongs = e.getBelongsToGroups(); 118 if (belongs != null) 119 { 120 for (int i = 0; i < belongs.length; i++) 121 { 122 belongs[i] = URLEncoder.encode((String )belongs[i], "UTF-8"); 123 } 124 } 125 uform.setBelongsToGroups(belongs); 126 } 127 } 128 else if (uform.getSubmit().equals("Modify") == true) 129 { 130 if (loggedIn(request, uform.getName(), errors, "Modify/by-" 131 + element.getName()) == false) 132 { 133 UserTable user_tbl = new UserTable(); 134 user_tbl.setConnection(c); 135 136 UserElement e = new UserElement(); 137 e.setAdditionalInfo(uform.getAdditionalInfo()); 138 e.setAddress(uform.getAddress()); 139 e.setFullName(uform.getFullName()); 140 e.setName(uform.getName()); 141 e.setUnavailXferTo(uform.getUnavailXferTo()); 142 e.setGatekeeper(uform.getGatekeeper()); 143 144 String password = uform.getPassword(); 145 if ((password != null) && (password.length() > 0)) 146 { 147 e.setPassword(password); 148 } 149 150 Object [] ogroups = uform.getOwnsGroups(); 151 if (ogroups != null) 152 { 153 for (int i = 0; i < ogroups.length; i++) 154 { 155 if (ogroups[i] != null) 156 { 157 String decoded_groups = URLDecoder.decode((String )ogroups[i], "UTF-8"); 158 e.addOwnsGroup(decoded_groups); 159 } 160 } 161 } 162 163 ogroups = uform.getBelongsToGroups(); 164 if (ogroups != null) 165 { 166 for (int i = 0; i < ogroups.length; i++) 167 { 168 if (ogroups[i] != null) 169 { 170 String decoded_groups = URLDecoder.decode((String )ogroups[i], "UTF-8"); 171 172 e.addBelongsToGroup(decoded_groups); 173 } 174 } 175 } 176 177 boolean status_ok = user_tbl.modify(e); 178 179 if (status_ok == false) 180 { 181 if (user_tbl.getErrorMessage() == null) 182 { 183 errors.add(ActionErrors.GLOBAL_ERROR, 184 new ActionError("error.user.modify.illegal")); 185 } 186 else 187 { 188 errors.add(ActionErrors.GLOBAL_ERROR, 189 new ActionError("error.db.failure")); 190 191 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 192 "UserManagementAction.execute()/Modify/by-" 193 + element.getName() 194 + ": " 195 + user_tbl.getErrorMessage()); 196 } 197 } 198 else 199 { 200 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 201 "User " + element.getName() + " modified webtalk user " + 202 uform.getName()); 203 204 ActionMessages messages = new ActionMessages(); 206 messages.add(ActionMessages.GLOBAL_MESSAGE, 207 new ActionMessage("message.user.modified")); 208 209 saveMessages(request, messages); 210 return mapping.findForward("webtalk_main_menu"); 211 } 212 } 213 } 214 else if (uform.getSubmit().equals("Create") == true) 215 { 216 UserTable user_tbl = new UserTable(); 217 user_tbl.setConnection(c); 218 219 UserElement e = new UserElement(); 220 221 e.setAdditionalInfo(uform.getAdditionalInfo()); 222 e.setAddress(uform.getAddress()); 223 e.setFullName(uform.getFullName()); 224 e.setName(uform.getName()); 225 e.setUnavailXferTo(uform.getUnavailXferTo()); 226 e.setGatekeeper(uform.getGatekeeper()); 227 e.setPassword(uform.getPassword()); 228 229 Object [] ogroups = uform.getOwnsGroups(); 230 if (ogroups != null) 231 { 232 for (int i = 0; i < ogroups.length; i++) 233 { 234 if (ogroups[i] != null) 235 { 236 String decoded_groups = URLDecoder.decode((String )ogroups[i], "UTF-8"); 237 238 e.addOwnsGroup(decoded_groups); 239 } 240 } 241 } 242 243 ogroups = uform.getBelongsToGroups(); 244 if (ogroups != null) 245 { 246 for (int i = 0; i < ogroups.length; i++) 247 { 248 if (ogroups[i] != null) 249 { 250 String decoded_groups = URLDecoder.decode((String )ogroups[i], "UTF-8"); 251 e.addBelongsToGroup(decoded_groups); 252 } 253 } 254 } 255 256 boolean status_ok = user_tbl.create(e); 257 258 if (status_ok == false) 259 { 260 errors.add(ActionErrors.GLOBAL_ERROR, 261 new ActionError("error.account.create.failure")); 262 263 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 264 "UserManagementAction.execute()/Create/by-" 265 + element.getName() 266 + ": " 267 + user_tbl.getErrorMessage()); 268 } 269 else 270 { 271 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 272 "User " + element.getName() + " created webtalk user " + 273 uform.getName()); 274 275 ActionMessages messages = new ActionMessages(); 277 messages.add(ActionMessages.GLOBAL_MESSAGE, 278 new ActionMessage("message.user.created")); 279 saveMessages(request, messages); 280 return mapping.findForward("webtalk_main_menu"); 281 } 282 } 283 else if (uform.getSubmit().equals("Delete") == true) 284 { 285 if (loggedIn(request, uform.getName(), errors, "Delete/by-" 286 + element.getName()) == false) 287 { 288 UserTable user_tbl = new UserTable(); 289 user_tbl.setConnection(c); 290 291 boolean status_ok = user_tbl.delete(uform.getName()); 292 293 if (status_ok == false) 294 { 295 if (user_tbl.getErrorMessage() == null) 296 { 297 errors.add(ActionErrors.GLOBAL_ERROR, 298 new ActionError("error.no.such.user")); 299 } 300 else 301 { 302 errors.add(ActionErrors.GLOBAL_ERROR, 303 new ActionError("error.db.failure")); 304 305 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 306 "UserManagementAction.execute()/Delete/by-" 307 + element.getName() 308 + ": " 309 + user_tbl.getErrorMessage()); 310 } 311 } 312 else 313 { 314 AceLogger.Instance().log(AceLogger.INFORMATIONAL, AceLogger.USER_LOG, 315 "User " + element.getName() + " deleted webtalk user " + 316 uform.getName()); 317 318 ActionMessages messages = new ActionMessages(); 320 messages.add(ActionMessages.GLOBAL_MESSAGE, 321 new ActionMessage("message.user.deleted")); 322 saveMessages(request, messages); 323 return mapping.findForward("webtalk_main_menu"); 324 } 325 } 326 } 327 328 if (errors.isEmpty() == false) 329 { 330 saveErrors(request, errors); 331 } 332 333 WebTalkRelatedTasks menu = new WebTalkRelatedTasks(); 335 menu.addLink(new LinkAttribute("Search users", "display_user_search")); 336 menu.addLink(new LinkAttribute("List all groups", "list_groups")); 337 menu.addLink(new LinkAttribute("Administer groups", "display_group_management")); 338 request.setAttribute("menu", menu); 339 340 return mapping.getInputForward(); 341 } 342 343 private boolean loggedIn(HttpServletRequest request, String user, ActionErrors errors, String log_prefix) 344 { 345 RemoteAccessClient cl = (RemoteAccessClient)request.getSession().getServletContext().getAttribute("remoteAccess"); 346 if (cl == null) 347 { 348 errors.add(ActionErrors.GLOBAL_ERROR, 349 new ActionError("error.rmi.error")); 350 351 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 352 "UserManagementAction.loggedIn()/" 353 + log_prefix 354 + ": Could not obtain RMI client object"); 355 356 return true; 357 } 358 359 try 360 { 361 String val = cl.getRemoteAccess().getParam("com.quikj.application.web.talk.plugin.ServiceController", 362 "logged-in:" + user); 363 if (val == null) 364 { 365 errors.add(ActionErrors.GLOBAL_ERROR, 366 new ActionError("error.rmi.error")); 367 368 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 369 "UserManagementAction.loggedIn()/" 370 + log_prefix 371 + ": Could not obtain logged-in param from ServiceController"); 372 373 return true; 374 } 375 else if (val.equals("no") == false) 376 { 377 errors.add(ActionErrors.GLOBAL_ERROR, 378 new ActionError("error.rmi.logged.in")); 379 return true; 380 } 381 } 382 catch (Exception ex) 383 { 384 errors.add(ActionErrors.GLOBAL_ERROR, 385 new ActionError("error.rmi.error")); 386 387 AceLogger.Instance().log(AceLogger.ERROR, AceLogger.SYSTEM_LOG, 388 "UserManagementAction.loggedIn()/" 389 + log_prefix 390 + ex.getClass().getName() + ": " + ex.getMessage()); 391 392 return true; 393 } 394 return false; 395 } 396 } 397 | Popular Tags |