Changeset 25257
- Timestamp:
- 2012-03-23T14:11:02+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java
r25129 r25257 3 3 import org.greenstone.gsdl3.comms.*; 4 4 import org.greenstone.gsdl3.core.*; 5 import org.greenstone.gsdl3.service.Authentication; 5 6 import org.greenstone.gsdl3.util.*; 6 7 import org.greenstone.gsdl3.action.PageAction; // used to get the default action 7 import org.greenstone.util.GlobalProperties;8 8 import org.w3c.dom.Document; 9 9 import org.w3c.dom.Element; … … 14 14 import javax.servlet.http.*; 15 15 16 import java.util.Collection;17 16 import java.util.Enumeration; 18 17 import java.util.ArrayList; … … 21 20 import java.util.List; 22 21 import java.util.Map; 23 import java.util.Set;24 import java.io.File;25 22 import java.lang.reflect.Type; 26 import java.nio.channels.FileChannel;27 23 import java.util.Hashtable; 28 24 import org.apache.log4j.*; … … 32 28 33 29 // Apache Commons 34 import org.apache.commons.fileupload.FileItem;35 import org.apache.commons.fileupload.disk.DiskFileItemFactory;36 import org.apache.commons.fileupload.servlet.ServletFileUpload;37 30 import org.apache.commons.lang3.*; 38 31 … … 277 270 this.recept.configure(); 278 271 272 //Allow the message router and the document to be accessed from anywhere in this servlet context 273 this.getServletContext().setAttribute("GSRouter", this.recept.getMessageRouter()); 274 this.getServletContext().setAttribute("GSDocument", this.doc); 279 275 } 280 276 … … 526 522 527 523 } 528 529 524 } 530 525 … … 546 541 if (!name.equals(GSXML.USER_SESSION_CACHE_ATT) && !name.equals(GSParams.LANGUAGE) && !name.equals(GSXML.USER_ID_ATT)) 547 542 { 548 549 543 session.removeAttribute(name); 550 544 } … … 606 600 xml_request.appendChild(xml_param_list); 607 601 608 Enumeration params = request.getParameterNames(); 609 while (params.hasMoreElements()) 610 { 611 String name = (String) params.nextElement(); 602 for (String name : queryMap.keySet()) 603 { 612 604 if (!name.equals(GSParams.ACTION) && !name.equals(GSParams.SUBACTION) && !name.equals(GSParams.LANGUAGE) && !name.equals(GSParams.OUTPUT)) 613 605 {// we have already dealt with these … … 650 642 651 643 // put in all the params from the session cache 652 params = session.getAttributeNames();644 Enumeration params = session.getAttributeNames(); 653 645 while (params.hasMoreElements()) 654 646 { … … 701 693 } 702 694 } 703 695 696 String requestedURL = request.getRequestURL().toString(); 697 String baseURL = requestedURL.substring(0, requestedURL.indexOf(this.getServletName())); 698 xml_request.setAttribute("baseURL", baseURL); 699 xml_request.setAttribute("remoteAddress", request.getRemoteAddr()); 700 701 if(!runSecurityChecks(request, xml_request, userContext, out, baseURL, collection, document)) 702 { 703 return; 704 } 705 706 Node xml_result = this.recept.process(xml_message); 707 encodeURLs(xml_result, response); 708 out.println(this.converter.getPrettyString(xml_result)); 709 710 displaySize(session_ids_table); 711 712 } //end of doGet(HttpServletRequest, HttpServletResponse) 713 714 private boolean runSecurityChecks(HttpServletRequest request, Element xml_request, UserContext userContext, PrintWriter out, String baseURL, String collection, String document) throws ServletException 715 { 704 716 //Check if we need to login or logout 705 717 Map<String, String[]> params = request.getParameterMap(); … … 719 731 request.logout(); 720 732 } 721 733 722 734 try 723 735 { 736 password[0] = Authentication.hashPassword(password[0]); 724 737 request.login(username[0], password[0]); 725 738 } 726 catch (Exception ex)739 catch (Exception ex) 727 740 { 728 741 //The user entered in either the wrong username or the wrong password … … 732 745 loginPageRequest.setAttribute(GSXML.SUBACTION_ATT, "login"); 733 746 loginPageRequest.setAttribute(GSXML.OUTPUT_ATT, "html"); 747 loginPageRequest.setAttribute(GSXML.BASE_URL, baseURL); 734 748 loginPageMessage.appendChild(loginPageRequest); 735 749 … … 744 758 Element urlParam = this.doc.createElement(GSXML.PARAM_ELEM); 745 759 urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL"); 746 urlParam.setAttribute(GSXML.VALUE_ATT, this.getServletName() + "?" + request.getQueryString().replace("&", "&")); 760 String queryString = ""; 761 if(request.getQueryString() != null) 762 { 763 queryString = "?" + request.getQueryString().replace("&", "&"); 764 } 765 urlParam.setAttribute(GSXML.VALUE_ATT, this.getServletName() + queryString); 747 766 paramList.appendChild(urlParam); 748 767 … … 750 769 out.println(this.converter.getPrettyString(loginPageResponse)); 751 770 752 return ;771 return false; 753 772 } 754 773 } … … 757 776 if (request.getAuthType() != null) 758 777 { 759 Element userInformation = this.doc.createElement("userInformation"); 760 xml_request.appendChild(userInformation); 778 Element userInformation = this.doc.createElement(GSXML.USER_INFORMATION_ELEM); 761 779 userInformation.setAttribute("username", request.getUserPrincipal().getName()); 762 780 … … 769 787 770 788 Element param = this.doc.createElement(GSXML.PARAM_ELEM); 771 param.setAttribute(GSXML.NAME_ATT, "username");789 param.setAttribute(GSXML.NAME_ATT, GSXML.USERNAME_ATT); 772 790 param.setAttribute(GSXML.VALUE_ATT, request.getUserPrincipal().getName()); 773 791 paramList.appendChild(param); … … 779 797 logger.error("Can't get the groups for user " + request.getUserPrincipal().getName()); 780 798 } 781 782 HashMap responseParams = GSXML.extractParams(responseParamList, true); 783 String groups = (String) responseParams.get("groups"); 784 785 userInformation.setAttribute("groups", groups); 799 else 800 { 801 HashMap responseParams = GSXML.extractParams(responseParamList, true); 802 String groups = (String) responseParams.get(GSXML.GROUPS_ATT); 803 804 userInformation.setAttribute(GSXML.GROUPS_ATT, groups); 805 xml_request.appendChild(userInformation); 806 } 786 807 } 787 808 … … 795 816 if (document != null && !document.equals("")) 796 817 { 797 securityRequest.setAttribute( "oid", document);818 securityRequest.setAttribute(GSXML.NODE_OID, document); 798 819 } 799 820 … … 822 843 loginPageRequest.setAttribute(GSXML.SUBACTION_ATT, "login"); 823 844 loginPageRequest.setAttribute(GSXML.OUTPUT_ATT, "html"); 845 loginPageRequest.setAttribute(GSXML.BASE_URL, baseURL); 824 846 loginPageMessage.appendChild(loginPageRequest); 825 847 … … 847 869 out.println(this.converter.getPrettyString(loginPageResponse)); 848 870 849 return; 850 } 851 } 852 } 853 854 Node xml_result = this.recept.process(xml_message); 855 encodeURLs(xml_result, response); 856 out.println(this.converter.getPrettyString(xml_result)); 857 858 displaySize(session_ids_table); 859 860 } //end of doGet(HttpServletRequest, HttpServletResponse) 861 871 return false; 872 } 873 } 874 } 875 return true; 876 } 877 862 878 //a debugging method 863 879 private void displaySize(Hashtable table)
Note:
See TracChangeset
for help on using the changeset viewer.