1 5 6 package com.quikj.application.communicator.applications.webtalk.controller; 7 8 import javax.servlet.http.HttpServletRequest ; 9 import org.apache.struts.action.*; 10 import org.apache.struts.util.*; 11 import java.util.*; 12 import java.sql.*; 13 import java.net.*; 14 import com.quikj.application.communicator.applications.webtalk.model.*; 15 16 20 public class UserManagementForm extends ActionForm 21 { 22 23 24 private String name; 25 26 27 private String password; 28 29 30 private String verifyPassword; 31 32 33 private String submit; 34 35 36 private String additionalInfo; 37 38 39 private Object [] belongsToGroups; 40 41 42 private Object [] ownsGroups; 43 44 45 private String fullName; 46 47 48 private String address; 49 50 51 private String unavailXferTo; 52 53 private static int MIN_PASSWORD_LENGTH = 4; 54 55 56 private ArrayList userGroups = new ArrayList(); 57 58 59 private String gatekeeper; 60 61 62 private String domain; 63 64 65 public UserManagementForm() 66 { 67 reset(); 68 } 69 70 76 public String getName() 77 { 78 return this.name; 79 } 80 81 88 public void setName(String name) 89 { 90 this.name = name.trim(); 91 } 92 93 99 public String getPassword() 100 { 101 return this.password; 102 } 103 104 111 public void setPassword(String password) 112 { 113 this.password = password; 114 } 115 116 122 public String getVerifyPassword() 123 { 124 return this.verifyPassword; 125 } 126 127 134 public void setVerifyPassword(String verifyPassword) 135 { 136 this.verifyPassword = verifyPassword; 137 } 138 139 145 public String getSubmit() 146 { 147 return this.submit; 148 } 149 150 157 public void setSubmit(String submit) 158 { 159 this.submit = submit; 160 } 161 162 168 public String getAdditionalInfo() 169 { 170 return this.additionalInfo; 171 } 172 173 180 public void setAdditionalInfo(String additionalInfo) 181 { 182 this.additionalInfo = additionalInfo.trim(); 183 } 184 185 public ActionErrors validate(ActionMapping mapping, 186 HttpServletRequest request) 187 { 188 if ((submit.startsWith("Finished") == true) 189 || (submit.startsWith("Cancel") == true)) 190 { 191 return null; 192 } 193 194 ActionErrors errors = new ActionErrors(); 196 try 197 { 198 if ((name == null) || (name.length() == 0)) 199 { 200 errors.add("name", new ActionError("error.user.no.name")); 201 } 202 203 if (DataCheckUtility.followsTableIdRules(name) == false) 204 { 205 errors.add("name", new ActionError("error.user.invalid.id")); 206 } 207 208 if (submit.startsWith("Create") == true) 210 { 211 if ((password == null) || (password.length() == 0)) 212 { 213 errors.add("password", new ActionError( 214 "error.user.no.password")); 215 } 216 else 217 { 218 validatePassword(password, errors); 219 220 if (verifyPassword != null) 221 { 222 if (password.equals(verifyPassword) == false) 223 { 224 errors.add("password", new ActionError( 225 "error.user.password.mismatch")); 226 } 227 } 228 else 229 { 230 errors.add("password", new ActionError( 231 "error.user.password.mismatch")); 232 } 233 } 234 } 235 236 if (submit.equals("Modify") == true) 238 { 239 if ((password != null) && (password.length() > 0)) 240 { 241 validatePassword(password, errors); 242 243 if (verifyPassword != null) 244 { 245 if (password.equals(verifyPassword) == false) 246 { 247 errors.add("password", new ActionError( 248 "error.user.password.mismatch")); 249 } 250 } 251 else 252 { 253 errors.add("password", new ActionError( 254 "error.user.password.mismatch")); 255 } 256 } 257 } 258 259 if ((submit.startsWith("Create") == true) 261 || (submit.equals("Modify") == true)) 262 { 263 if (ownsGroups != null) 265 { 266 if (belongsToGroups != null) 267 { 268 for (int i = 0; i < ownsGroups.length; i++) 269 { 270 String name = ownsGroups[i].toString(); 271 272 for (int j = 0; j < belongsToGroups.length; j++) 273 { 274 if (belongsToGroups[j].toString().equals(name) == true) 275 { 276 errors 277 .add( 278 "belongsToGroups", 279 new ActionError( 280 "error.user.groups.illegal")); 281 break; 282 } 283 } 284 } 285 } 286 } 287 288 if (unavailXferTo != null) 290 { 291 if (unavailXferTo.equals(name) == true) 292 { 293 errors.add("unavailXferTo", new ActionError( 294 "error.user.unavail.invalid")); 295 } 296 } 297 298 } 299 300 if (errors.isEmpty() == false) 301 { 302 GroupTable groups = new GroupTable(); 303 Connection c = (Connection) request.getSession().getAttribute( 304 "connection"); 305 306 groups.setConnection(c); 307 ArrayList group_list = groups.list(domain); 308 309 if (group_list != null) 310 { 311 ArrayList list = new ArrayList(); 312 Iterator iter = group_list.iterator(); 313 314 while (iter.hasNext() == true) 315 { 316 String group = (String ) iter.next(); 317 318 if (group.equals(domain) == false) 319 { 320 list.add(new LabelValueBean(group, URLEncoder 321 .encode(group, "UTF-8"))); 322 } 323 } 324 325 setUserGroups(list); 326 } 327 } 328 } 329 catch (Exception e) 330 { 331 errors.add("unavailXferTo", new ActionError( 332 "error.internal.error")); 333 } 334 return errors; 335 } 336 337 public static void validatePassword(String password, ActionErrors errors) 338 { 339 password = password.trim(); 340 if (password.length() == 0) 341 { 342 errors.add("password", new ActionError( 343 "error.user.password.hasblanks")); 344 } 345 else 346 { 347 int len = password.length(); 348 349 if (len < MIN_PASSWORD_LENGTH) 350 { 351 errors.add("password", new ActionError( 352 "error.user.password.tooshort", new Integer ( 353 MIN_PASSWORD_LENGTH))); 354 } 355 356 boolean letter = false; 358 boolean digit = false; 359 360 for (int i = 0; i < len; i++) 361 { 362 char c = password.charAt(i); 363 if (Character.isDigit(c) == true) 364 { 365 digit = true; 366 } 367 else if (Character.isLetter(c) == true) 368 { 369 letter = true; 370 } 371 else if (Character.isSpaceChar(c) == true) 372 { 373 errors.add("password", new ActionError( 374 "error.user.password.hasblanks")); 375 } 376 } 377 378 if ((letter == false) || (digit == false)) 379 { 380 errors.add("password", new ActionError( 381 "error.user.password.content")); 382 } 383 } 384 } 385 386 public void reset() 387 { 388 belongsToGroups = null; 389 ownsGroups = null; 390 name = null; 391 password = null; 392 verifyPassword = null; 393 submit = "Find"; 394 additionalInfo = null; 395 fullName = null; 396 address = null; 397 unavailXferTo = null; 398 } 399 400 406 public Object [] getBelongsToGroups() 407 { 408 return this.belongsToGroups; 409 } 410 411 418 public void setBelongsToGroups(Object [] belongsToGroups) 419 { 420 this.belongsToGroups = belongsToGroups; 421 } 422 423 429 public Object [] getOwnsGroups() 430 { 431 return this.ownsGroups; 432 } 433 434 441 public void setOwnsGroups(Object [] ownsGroups) 442 { 443 this.ownsGroups = ownsGroups; 444 } 445 446 452 public String getFullName() 453 { 454 return this.fullName; 455 } 456 457 464 public void setFullName(String fullName) 465 { 466 this.fullName = fullName.trim(); 467 } 468 469 475 public String getAddress() 476 { 477 return this.address; 478 } 479 480 487 public void setAddress(String address) 488 { 489 this.address = address.trim(); 490 } 491 492 498 public String getUnavailXferTo() 499 { 500 return this.unavailXferTo; 501 } 502 503 510 public void setUnavailXferTo(String unavailXferTo) 511 { 512 this.unavailXferTo = unavailXferTo.trim(); 513 } 514 515 521 public ArrayList getUserGroups() 522 { 523 return this.userGroups; 524 } 525 526 533 public void setUserGroups(ArrayList userGroups) 534 { 535 this.userGroups = userGroups; 536 } 537 538 544 public String getGatekeeper() 545 { 546 return this.gatekeeper; 547 } 548 549 556 public void setGatekeeper(String gatekeeper) 557 { 558 this.gatekeeper = gatekeeper; 559 } 560 561 567 public String getDomain() 568 { 569 return this.domain; 570 } 571 572 579 public void setDomain(String domain) 580 { 581 this.domain = domain; 582 } 583 584 } | Popular Tags |