Changeset 28966 for main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java
- Timestamp:
- 2014-04-10T14:39:33+12:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java
r28958 r28966 19 19 import org.greenstone.gsdl3.util.UserQueryResult; 20 20 import org.greenstone.gsdl3.util.UserTermInfo; 21 import org.greenstone.gsdl3.util.XMLConverter; 21 22 import org.greenstone.util.GlobalProperties; 23 24 import org.w3c.dom.Document; 22 25 import org.w3c.dom.Element; 23 26 import org.w3c.dom.NodeList; … … 168 171 169 172 // set up Authentication service info - for now just has name and type 170 Element authentication_service = this.d oc.createElement(GSXML.SERVICE_ELEM);173 Element authentication_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM); 171 174 authentication_service.setAttribute(GSXML.TYPE_ATT, "authen"); 172 175 authentication_service.setAttribute(GSXML.NAME_ATT, AUTHENTICATION_SERVICE); 173 176 this.short_service_info.appendChild(authentication_service); 174 177 175 Element getUserInformation_service = this.d oc.createElement(GSXML.SERVICE_ELEM);178 Element getUserInformation_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM); 176 179 getUserInformation_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS); 177 180 getUserInformation_service.setAttribute(GSXML.NAME_ATT, GET_USER_INFORMATION_SERVICE); 178 181 this.short_service_info.appendChild(getUserInformation_service); 179 182 180 Element changeEditMode_service = this.d oc.createElement(GSXML.SERVICE_ELEM);183 Element changeEditMode_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM); 181 184 changeEditMode_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS); 182 185 changeEditMode_service.setAttribute(GSXML.NAME_ATT, CHANGE_USER_EDIT_MODE_SERVICE); 183 186 this.short_service_info.appendChild(changeEditMode_service); 184 187 185 Element remoteAuthentication_service = this.d oc.createElement(GSXML.SERVICE_ELEM);188 Element remoteAuthentication_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM); 186 189 remoteAuthentication_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS); 187 190 remoteAuthentication_service.setAttribute(GSXML.NAME_ATT, REMOTE_AUTHENTICATION_SERVICE); … … 214 217 } 215 218 216 protected Element getServiceDescription(String service_id, String lang, String subset)217 { 218 219 Element authen_service = this.doc.createElement(GSXML.SERVICE_ELEM);219 protected Element getServiceDescription(Document doc, String service_id, String lang, String subset) 220 { 221 222 Element authen_service = doc.createElement(GSXML.SERVICE_ELEM); 220 223 221 224 if (service_id.equals(AUTHENTICATION_SERVICE)) … … 246 249 if (service_id.equals(AUTHENTICATION_SERVICE) && (subset == null || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER))) 247 250 { 248 authen_service.appendChild(GSXML.createDisplayTextElement( this.doc, GSXML.DISPLAY_TEXT_NAME, getServiceName(service_id, lang)));249 authen_service.appendChild(GSXML.createDisplayTextElement( this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getServiceDescription(service_id, lang)));251 authen_service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_NAME, getServiceName(service_id, lang))); 252 authen_service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getServiceDescription(service_id, lang))); 250 253 } 251 254 return authen_service; … … 270 273 { 271 274 // Create a new (empty) result message 272 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM); 275 Document result_doc = XMLConverter.newDOM(); 276 Element result = result_doc.createElement(GSXML.RESPONSE_ELEM); 273 277 274 278 result.setAttribute(GSXML.FROM_ATT, CHANGE_USER_EDIT_MODE_SERVICE); … … 278 282 if (paramList == null) 279 283 { 280 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));284 GSXML.addError(result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST)); 281 285 return result; 282 286 } … … 362 366 } 363 367 } 364 365 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);368 Document result_doc = XMLConverter.newDOM(); 369 Element result = result_doc.createElement(GSXML.RESPONSE_ELEM); 366 370 result.setAttribute(GSXML.FROM_ATT, REMOTE_AUTHENTICATION_SERVICE); 367 371 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS); 368 Element s = GSXML.createTextElement( this.doc, GSXML.STATUS_ELEM, message);372 Element s = GSXML.createTextElement(result_doc, GSXML.STATUS_ELEM, message); 369 373 result.appendChild(s); 370 374 return result; … … 374 378 { 375 379 // Create a new (empty) result message 376 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM); 380 Document result_doc = XMLConverter.newDOM(); 381 Element result = result_doc.createElement(GSXML.RESPONSE_ELEM); 377 382 378 383 result.setAttribute(GSXML.FROM_ATT, GET_USER_INFORMATION_SERVICE); … … 382 387 if (paramList == null) 383 388 { 384 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));389 GSXML.addError(result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST)); 385 390 return result; 386 391 } … … 392 397 if (username == null) 393 398 { 394 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_USERNAME_NOT_SPECIFIED));399 GSXML.addError(result, _errorMessageMap.get(ERROR_USERNAME_NOT_SPECIFIED)); 395 400 return result; 396 401 } … … 405 410 if (terms.size() == 0) 406 411 { 407 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_REQUESTED_USER_NOT_FOUND));412 GSXML.addError(result, _errorMessageMap.get(ERROR_REQUESTED_USER_NOT_FOUND)); 408 413 return result; 409 414 } 410 415 411 416 UserTermInfo userInfo = terms.get(0); 412 Element userInfoList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);417 Element userInfoList = result_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 413 418 result.appendChild(userInfoList); 414 419 415 Element usernameField = GSXML.createParameter( this.doc, "username", userInfo.username);416 Element passwordField = GSXML.createParameter( this.doc, "password", userInfo.password);417 Element groupsField = GSXML.createParameter( this.doc, "groups", userInfo.groups);418 Element accountStatusField = GSXML.createParameter( this.doc, "accountstatus", userInfo.accountstatus);419 Element commentField = GSXML.createParameter( this.doc, "comment", userInfo.comment);420 Element usernameField = GSXML.createParameter(result_doc, "username", userInfo.username); 421 Element passwordField = GSXML.createParameter(result_doc, "password", userInfo.password); 422 Element groupsField = GSXML.createParameter(result_doc, "groups", userInfo.groups); 423 Element accountStatusField = GSXML.createParameter(result_doc, "accountstatus", userInfo.accountstatus); 424 Element commentField = GSXML.createParameter(result_doc, "comment", userInfo.comment); 420 425 421 426 if (editEnabled != null) 422 427 { 423 Element editEnabledElem = GSXML.createParameter( this.doc, "editEnabled", editEnabled);428 Element editEnabledElem = GSXML.createParameter(result_doc, "editEnabled", editEnabled); 424 429 userInfoList.appendChild(editEnabledElem); 425 430 } … … 441 446 442 447 // Create a new (empty) result message 443 Element result = this.doc.createElement(GSXML.RESPONSE_ELEM); 448 Document result_doc = XMLConverter.newDOM(); 449 Element result = result_doc.createElement(GSXML.RESPONSE_ELEM); 444 450 result.setAttribute(GSXML.FROM_ATT, AUTHENTICATION_SERVICE); 445 451 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS); 446 452 447 453 // Create an Authentication node put into the result 448 Element authenNode = this.doc.createElement(GSXML.AUTHEN_NODE_ELEM);454 Element authenNode = result_doc.createElement(GSXML.AUTHEN_NODE_ELEM); 449 455 result.appendChild(authenNode); 450 result.appendChild(getCollectList( this.site_home + File.separatorChar + "collect"));456 result.appendChild(getCollectList(result_doc, this.site_home + File.separatorChar + "collect")); 451 457 452 458 // Create a service node added into the Authentication node 453 Element serviceNode = this.doc.createElement(GSXML.SERVICE_ELEM);459 Element serviceNode = result_doc.createElement(GSXML.SERVICE_ELEM); 454 460 authenNode.appendChild(serviceNode); 455 461 … … 459 465 { 460 466 serviceNode.setAttribute("operation", LOGIN); 461 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));467 GSXML.addError(result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST)); 462 468 return result; // Return the empty result 463 469 } … … 473 479 { 474 480 serviceNode.setAttribute("operation", LOGIN); 475 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_NOT_LOGGED_IN));481 GSXML.addError(result, _errorMessageMap.get(ERROR_NOT_LOGGED_IN)); 476 482 return result; 477 483 } … … 486 492 { 487 493 serviceNode.setAttribute("operation", LOGIN); 488 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_NOT_LOGGED_IN));494 GSXML.addError(result, _errorMessageMap.get(ERROR_NOT_LOGGED_IN)); 489 495 return result; 490 496 } … … 493 499 { 494 500 serviceNode.setAttribute("operation", LOGIN); 495 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_ADMIN_NOT_LOGGED_IN));501 GSXML.addError(result, _errorMessageMap.get(ERROR_ADMIN_NOT_LOGGED_IN)); 496 502 return result; 497 503 } … … 502 508 if (error != NO_ERROR) 503 509 { 504 GSXML.addError( this.doc,result, _errorMessageMap.get(error));510 GSXML.addError(result, _errorMessageMap.get(error)); 505 511 } 506 512 } … … 518 524 if ((error = checkUsername(newUsername)) != NO_ERROR) 519 525 { 520 GSXML.addError( this.doc,result, _errorMessageMap.get(error));526 GSXML.addError(result, _errorMessageMap.get(error)); 521 527 return result; 522 528 } … … 525 531 if ((error = checkPassword(newPassword)) != NO_ERROR) 526 532 { 527 GSXML.addError( this.doc,result, _errorMessageMap.get(error));533 GSXML.addError(result, _errorMessageMap.get(error)); 528 534 return result; 529 535 } … … 535 541 { 536 542 serviceNode.setAttribute("operation", ADD_USER); 537 GSXML.addError( this.doc,result, _errorMessageMap.get(error));543 GSXML.addError(result, _errorMessageMap.get(error)); 538 544 } 539 545 else … … 553 559 if ((error = checkUsername(newUsername)) != NO_ERROR) 554 560 { 555 GSXML.addError( this.doc,result, _errorMessageMap.get(error));561 GSXML.addError(result, _errorMessageMap.get(error)); 556 562 return result; 557 563 } … … 560 566 if ((error = checkPassword(newPassword)) != NO_ERROR) 561 567 { 562 GSXML.addError( this.doc,result, _errorMessageMap.get(error));568 GSXML.addError(result, _errorMessageMap.get(error)); 563 569 return result; 564 570 } … … 584 590 { 585 591 serviceNode.setAttribute("operation", REGISTER); 586 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_CAPTCHA_MISSING));592 GSXML.addError(result, _errorMessageMap.get(ERROR_CAPTCHA_MISSING)); 587 593 return result; 588 594 } … … 593 599 { 594 600 serviceNode.setAttribute("operation", REGISTER); 595 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_CAPTCHA_DOES_NOT_MATCH));601 GSXML.addError(result, _errorMessageMap.get(ERROR_CAPTCHA_DOES_NOT_MATCH)); 596 602 return result; 597 603 } … … 606 612 { 607 613 serviceNode.setAttribute("operation", REGISTER); 608 GSXML.addError( this.doc,result, _errorMessageMap.get(error));614 GSXML.addError(result, _errorMessageMap.get(error)); 609 615 } 610 616 } … … 623 629 if ((error = checkUsername(newUsername)) != NO_ERROR) 624 630 { 625 GSXML.addError( this.doc,result, _errorMessageMap.get(error));631 GSXML.addError(result, _errorMessageMap.get(error)); 626 632 return result; 627 633 } … … 636 642 if ((error = checkPassword(newPassword)) != NO_ERROR) 637 643 { 638 GSXML.addError( this.doc,result, _errorMessageMap.get(error));644 GSXML.addError(result, _errorMessageMap.get(error)); 639 645 return result; 640 646 } … … 654 660 { 655 661 serviceNode.setAttribute("operation", EDIT_USER); 656 GSXML.addError( this.doc,result, _errorMessageMap.get(error));662 GSXML.addError(result, _errorMessageMap.get(error)); 657 663 } 658 664 return result; … … 663 669 { 664 670 serviceNode.setAttribute("operation", EDIT_USER); 665 GSXML.addError( this.doc,result, _errorMessageMap.get(error));671 GSXML.addError(result, _errorMessageMap.get(error)); 666 672 } 667 673 else … … 684 690 addUserInformationToNode(previousUsername, serviceNode); 685 691 serviceNode.setAttribute("operation", ACCOUNT_SETTINGS); 686 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_USER_ALREADY_EXISTS));692 GSXML.addError(result, _errorMessageMap.get(ERROR_USER_ALREADY_EXISTS)); 687 693 return result; 688 694 } … … 698 704 addUserInformationToNode(previousUsername, serviceNode); 699 705 serviceNode.setAttribute("operation", ACCOUNT_SETTINGS); 700 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_INCORRECT_PASSWORD), "Incorrect Password");706 GSXML.addError(result, _errorMessageMap.get(ERROR_INCORRECT_PASSWORD), "Incorrect Password"); 701 707 return result; 702 708 } … … 706 712 if ((error = checkPassword(newPassword)) != NO_ERROR) 707 713 { 708 GSXML.addError( this.doc,result, _errorMessageMap.get(error));714 GSXML.addError(result, _errorMessageMap.get(error)); 709 715 return result; 710 716 } … … 721 727 if ((error = checkUsername(newUsername)) != NO_ERROR) 722 728 { 723 GSXML.addError( this.doc,result, _errorMessageMap.get(error));729 GSXML.addError(result, _errorMessageMap.get(error)); 724 730 return result; 725 731 } … … 741 747 addUserInformationToNode(previousUsername, serviceNode); 742 748 serviceNode.setAttribute("operation", ACCOUNT_SETTINGS); 743 GSXML.addError( this.doc,result, _errorMessageMap.get(error));749 GSXML.addError(result, _errorMessageMap.get(error)); 744 750 } 745 751 return result; … … 749 755 if (error != NO_ERROR) 750 756 { 751 GSXML.addError( this.doc,result, _errorMessageMap.get(error));757 GSXML.addError(result, _errorMessageMap.get(error)); 752 758 } 753 759 … … 767 773 if (user_name == null || oldPassword == null || newPassword == null) 768 774 { 769 GSXML.addError( this.doc,result, _errorMessageMap.get("missing compulsory parameters: username, oldPassword, or newPassword"));775 GSXML.addError(result, _errorMessageMap.get("missing compulsory parameters: username, oldPassword, or newPassword")); 770 776 return result; 771 777 } … … 775 781 { 776 782 addUserInformationToNode(user_name, serviceNode); 777 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_INCORRECT_PASSWORD), "Incorrect Password");783 GSXML.addError(result, _errorMessageMap.get(ERROR_INCORRECT_PASSWORD), "Incorrect Password"); 778 784 return result; 779 785 } … … 783 789 if ((error = checkPassword(newPassword)) != NO_ERROR) 784 790 { 785 GSXML.addError( this.doc,result, _errorMessageMap.get(error));791 GSXML.addError(result, _errorMessageMap.get(error)); 786 792 return result; 787 793 } … … 794 800 if (info != "succeed") 795 801 {//see DerbyWrapper.modifyUserInfo 796 GSXML.addError( this.doc,result, _errorMessageMap.get(info));802 GSXML.addError(result, _errorMessageMap.get(info)); 797 803 return result; 798 804 } … … 804 810 if (error != NO_ERROR) 805 811 { 806 GSXML.addError( this.doc,result, _errorMessageMap.get(error));812 GSXML.addError(result, _errorMessageMap.get(error)); 807 813 } 808 814 } … … 814 820 { 815 821 serviceNode.setAttribute("operation", ""); 816 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_USERNAME_NOT_SPECIFIED));822 GSXML.addError(result, _errorMessageMap.get(ERROR_USERNAME_NOT_SPECIFIED)); 817 823 return result; 818 824 } … … 821 827 { 822 828 serviceNode.setAttribute("operation", LOGIN); 823 GSXML.addError( this.doc,result, _errorMessageMap.get(ERROR_NOT_AUTHORISED));829 GSXML.addError(result, _errorMessageMap.get(ERROR_NOT_AUTHORISED)); 824 830 return result; 825 831 } … … 827 833 if (error != NO_ERROR) 828 834 { 829 GSXML.addError( this.doc,result, _errorMessageMap.get(error));835 GSXML.addError(result, _errorMessageMap.get(error)); 830 836 } 831 837 } … … 861 867 if (_recaptchaPublicKey != null && _recaptchaPrivateKey != null) 862 868 { 863 Element recaptchaElem = this.doc.createElement("recaptcha");869 Element recaptchaElem = result_doc.createElement("recaptcha"); 864 870 recaptchaElem.setAttribute("publicKey", _recaptchaPublicKey); 865 871 recaptchaElem.setAttribute("privateKey", _recaptchaPrivateKey); … … 873 879 if (error != NO_ERROR) 874 880 { 875 GSXML.addError( this.doc,result, _errorMessageMap.get(error));881 GSXML.addError(result, _errorMessageMap.get(error)); 876 882 } 877 883 addUserInformationToNode(null, serviceNode); … … 985 991 if (userQueryResult != null) 986 992 { 987 Element user_node = getUserNode(userQueryResult);993 Element user_node = getUserNodeList(serviceNode.getOwnerDocument(), userQueryResult); 988 994 serviceNode.appendChild(user_node); 989 995 return NO_ERROR; … … 1114 1120 } 1115 1121 1116 private Element getUserNode(UserQueryResult userQueryResult)1117 { 1118 Element user_list_node = this.doc.createElement(GSXML.USER_NODE_ELEM + "List");1122 private Element getUserNodeList(Document doc, UserQueryResult userQueryResult) 1123 { 1124 Element user_list_node = doc.createElement(GSXML.USER_NODE_ELEM + GSXML.LIST_MODIFIER); 1119 1125 1120 1126 Vector userInfo = userQueryResult.users; … … 1122 1128 for (int i = 0; i < userQueryResult.getSize(); i++) 1123 1129 { 1124 Element user_node = this.doc.createElement(GSXML.USER_NODE_ELEM);1130 Element user_node = doc.createElement(GSXML.USER_NODE_ELEM); 1125 1131 String username = ((UserTermInfo) userInfo.get(i)).username; 1126 1132 String groups = ((UserTermInfo) userInfo.get(i)).groups; … … 1139 1145 } 1140 1146 1141 private Element getCollectList(String collect)1142 { 1143 Element collect_list_node = this.doc.createElement(GSXML.COLLECTION_ELEM + "List");1147 private Element getCollectList(Document doc, String collect) 1148 { 1149 Element collect_list_node = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 1144 1150 File[] collect_dir = (new File(collect)).listFiles(); 1145 1151 if (collect_dir != null && collect_dir.length > 0) … … 1149 1155 if (collect_dir[i].isDirectory() && (!collect_dir[i].getName().startsWith(".svn"))) 1150 1156 { 1151 Element collect_node = this.doc.createElement(GSXML.COLLECTION_ELEM);1152 collect_node.setAttribute( "name", collect_dir[i].getName());1157 Element collect_node = doc.createElement(GSXML.COLLECTION_ELEM); 1158 collect_node.setAttribute(GSXML.NAME_ATT, collect_dir[i].getName()); 1153 1159 collect_list_node.appendChild(collect_node); 1154 1160 }
Note:
See TracChangeset
for help on using the changeset viewer.