Changeset 33700 for main/trunk/greenstone3/src
- Timestamp:
- 2019-11-19T13:56:55+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java
r33612 r33700 55 55 import org.greenstone.gsdl3.core.Receptionist; 56 56 import org.greenstone.gsdl3.service.Authentication; 57 import org.greenstone.gsdl3.util.Dictionary; 57 58 import org.greenstone.gsdl3.util.GSConstants; 58 59 import org.greenstone.gsdl3.util.GSParams; … … 87 88 public class LibraryServlet extends BaseGreenstoneServlet 88 89 { 90 protected static final String LOGIN_MESSAGE_PARAM = "loginMessage"; 91 protected static final String REDIRECT_URL_PARAM = "redirectURL"; 89 92 /** the receptionist to send messages to */ 90 93 protected Receptionist recept = null; … … 346 349 String q = queryIter.next(); 347 350 String[] vals = queryMap.get(q); 348 queryParamStr += q +"="+String .join(",",vals)+" ";351 queryParamStr += q +"="+StringUtils.join(vals, ",")+" "; 349 352 } 350 353 } … … 493 496 userContext.setLanguage(lang); 494 497 userContext.setUserID(uid); 498 logger.error("LS new user context"); 495 499 if (request.getAuthType() != null) 496 500 { 497 501 //Get the username 498 502 userContext.setUsername(request.getUserPrincipal().getName()); 499 503 logger.error("setting username = "+request.getUserPrincipal().getName()); 500 504 //Get the groups for the user 501 505 Document msg_doc = XMLConverter.newDOM(); … … 858 862 xml_request.setAttribute("fullURL", fullURL.replace("&", "&")); 859 863 860 if (!runSecurityChecks(request, xml_request, userContext, out, baseURL, collection, document, queryMap ))864 if (!runSecurityChecks(request, xml_request, userContext, out, baseURL, collection, document, queryMap, lang)) 861 865 { 862 866 return; 863 867 } 864 868 869 logger.error("about to process this message"); 870 logger.error(XMLConverter.getPrettyString(xml_message)); 865 871 Node xml_result = this.recept.process(xml_message); 866 872 encodeURLs(xml_result, response); … … 895 901 } //end of doGet(HttpServletRequest, HttpServletResponse) 896 902 897 private boolean runSecurityChecks(HttpServletRequest request, Element xml_request, UserContext userContext, PrintWriter out, String baseURL, String collection, String document, Map<String, String[]> queryMap) throws ServletException903 private boolean runSecurityChecks(HttpServletRequest request, Element xml_request, UserContext userContext, PrintWriter out, String baseURL, String collection, String document, Map<String, String[]> queryMap, String lang) throws ServletException 898 904 { 905 logger.error("kk in run security"); 899 906 //Check if we need to login or logout 900 907 String username = getFirstParam(GSParams.USERNAME, queryMap); … … 909 916 if (username != null && password != null) 910 917 { 918 logger.error("kk u&p not null"); 911 919 //We are changing to another user, so log out first 912 920 if (request.getAuthType() != null) … … 946 954 947 955 Element messageParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 948 messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage");949 messageParam.setAttribute(GSXML.VALUE_ATT, "Either your username or password was incorrect, please try again.");956 messageParam.setAttribute(GSXML.NAME_ATT, LOGIN_MESSAGE_PARAM); 957 messageParam.setAttribute(GSXML.VALUE_ATT, getTextString("auth.error.un_or_pw_err", lang)); 950 958 paramList.appendChild(messageParam); 951 959 952 960 Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 953 urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL");961 urlParam.setAttribute(GSXML.NAME_ATT, REDIRECT_URL_PARAM); 954 962 String queryString = ""; 955 963 if (request.getQueryString() != null) … … 971 979 if (request.getAuthType() != null) 972 980 { 981 logger.error("kk auth type not null "+ request.getAuthType()); 973 982 Element userInformation = xml_request.getOwnerDocument().createElement(GSXML.USER_INFORMATION_ELEM); 974 983 userInformation.setAttribute(GSXML.USERNAME_ATT, request.getUserPrincipal().getName()); 975 984 logger.error("setting user info username "+request.getUserPrincipal().getName()); 976 985 Document msg_doc = XMLConverter.newDOM(); 977 986 Element userInfoMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM); … … 1000 1009 1001 1010 userInformation.setAttribute(GSXML.GROUPS_ATT, groups); 1002 userInformation.setAttribute( "editEnabled", (editEnabled != null) ? editEnabled : "false");1011 userInformation.setAttribute(GSXML.EDIT_ENABLED_ATT, (editEnabled != null) ? editEnabled : "false"); 1003 1012 xml_request.appendChild(userInformation); 1004 1013 } … … 1008 1017 if (collection != null && !collection.equals("")) 1009 1018 { 1019 logger.error("kk in a coll"+collection); 1010 1020 //Get the security info for this collection 1011 1021 Document msg_doc = XMLConverter.newDOM(); … … 1042 1052 if (!found) 1043 1053 { 1054 logger.error("kk current user not allowed to access"); 1044 1055 Document loginPageDoc = XMLConverter.newDOM(); 1045 1056 Element loginPageMessage = loginPageDoc.createElement(GSXML.MESSAGE_ELEM); … … 1055 1066 1056 1067 Element messageParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 1057 messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage");1068 messageParam.setAttribute(GSXML.NAME_ATT, LOGIN_MESSAGE_PARAM); 1058 1069 if (request.getAuthType() == null) 1059 1070 { 1060 messageParam.setAttribute(GSXML.VALUE_ATT, "Please log in to view this page");1071 messageParam.setAttribute(GSXML.VALUE_ATT, getTextString("auth.error.login", lang)); 1061 1072 } 1062 1073 else 1063 1074 { 1064 messageParam.setAttribute(GSXML.VALUE_ATT, "You are not in the correct group to view this page, would you like to log in as a different user?");1075 messageParam.setAttribute(GSXML.VALUE_ATT, getTextString("auth.error.incorrect_login", lang)); 1065 1076 } 1066 1077 paramList.appendChild(messageParam); 1067 1078 1068 1079 Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 1069 urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL");1080 urlParam.setAttribute(GSXML.NAME_ATT, REDIRECT_URL_PARAM); 1070 1081 if (request.getQueryString() != null && request.getQueryString().length() > 0) 1071 1082 { … … 1078 1089 paramList.appendChild(urlParam); 1079 1090 1091 // for debugging purposes, eg adding o=xml to the url 1092 String output_p = getFirstParam(GSParams.OUTPUT, queryMap); 1093 if (output_p !=null && !output_p.equals("")) { 1094 loginPageRequest.setAttribute(GSXML.OUTPUT_ATT, output_p); 1095 } 1096 1097 logger.error("login page request="); 1098 logger.error(XMLConverter.getPrettyString(loginPageMessage)); 1080 1099 Node loginPageResponse = this.recept.process(loginPageMessage); 1081 1100 out.println(XMLConverter.getPrettyString(loginPageResponse)); … … 1085 1104 } 1086 1105 } 1106 logger.error("kk reurned true"); 1087 1107 return true; 1088 1108 } 1089 1109 1110 private String getTextString(String key, String lang) { 1111 return Dictionary.getTextString(key, lang, "ServiceRack", null, null); 1112 1113 } 1090 1114 //a debugging method 1091 1115 private void displaySize(Hashtable<String, UserSessionCache> table)
Note:
See TracChangeset
for help on using the changeset viewer.