Changeset 33700

Show
Ignore:
Timestamp:
19.11.2019 13:56:55 (3 weeks ago)
Author:
kjdon
Message:

starting to put some of the strings into a dictionary - using ServiceRack?.properties for now. Should rename this?? String.join is Java 8, but release kits use Java 7? so changing to StringUtils?.join. I am still working on this file, so debugging messages have been left in for now

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r33612 r33700  
    5555import org.greenstone.gsdl3.core.Receptionist; 
    5656import org.greenstone.gsdl3.service.Authentication; 
     57import org.greenstone.gsdl3.util.Dictionary; 
    5758import org.greenstone.gsdl3.util.GSConstants; 
    5859import org.greenstone.gsdl3.util.GSParams; 
     
    8788public class LibraryServlet extends BaseGreenstoneServlet 
    8889{ 
     90  protected static final String LOGIN_MESSAGE_PARAM = "loginMessage"; 
     91  protected static final String REDIRECT_URL_PARAM = "redirectURL"; 
    8992    /** the receptionist to send messages to */ 
    9093    protected Receptionist recept = null; 
     
    346349              String q = queryIter.next(); 
    347350              String[] vals = queryMap.get(q); 
    348               queryParamStr += q +"="+String.join(",",vals)+" "; 
     351              queryParamStr += q +"="+StringUtils.join(vals, ",")+" "; 
    349352            } 
    350353        } 
     
    493496        userContext.setLanguage(lang); 
    494497        userContext.setUserID(uid); 
     498        logger.error("LS new user context"); 
    495499        if (request.getAuthType() != null) 
    496500        { 
    497501            //Get the username 
    498502          userContext.setUsername(request.getUserPrincipal().getName()); 
    499  
     503          logger.error("setting username = "+request.getUserPrincipal().getName()); 
    500504            //Get the groups for the user 
    501505            Document msg_doc = XMLConverter.newDOM(); 
     
    858862        xml_request.setAttribute("fullURL", fullURL.replace("&", "&")); 
    859863 
    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)) 
    861865        { 
    862866            return; 
    863867        } 
    864868 
     869        logger.error("about to process this message"); 
     870        logger.error(XMLConverter.getPrettyString(xml_message)); 
    865871        Node xml_result = this.recept.process(xml_message); 
    866872        encodeURLs(xml_result, response); 
     
    895901    } //end of doGet(HttpServletRequest, HttpServletResponse) 
    896902 
    897     private boolean runSecurityChecks(HttpServletRequest request, Element xml_request, UserContext userContext, PrintWriter out, String baseURL, String collection, String document, Map<String, String[]> queryMap) throws ServletException 
     903  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 
    898904    { 
     905      logger.error("kk in run security"); 
    899906        //Check if we need to login or logout 
    900907        String username = getFirstParam(GSParams.USERNAME, queryMap); 
     
    909916        if (username != null && password != null) 
    910917        { 
     918          logger.error("kk u&p not null"); 
    911919            //We are changing to another user, so log out first 
    912920            if (request.getAuthType() != null) 
     
    946954 
    947955                    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)); 
    950958                    paramList.appendChild(messageParam); 
    951959 
    952960                    Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 
    953                     urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL"); 
     961                    urlParam.setAttribute(GSXML.NAME_ATT, REDIRECT_URL_PARAM); 
    954962                    String queryString = ""; 
    955963                    if (request.getQueryString() != null) 
     
    971979        if (request.getAuthType() != null) 
    972980        { 
     981          logger.error("kk auth type not null "+ request.getAuthType()); 
    973982          Element userInformation = xml_request.getOwnerDocument().createElement(GSXML.USER_INFORMATION_ELEM); 
    974983            userInformation.setAttribute(GSXML.USERNAME_ATT, request.getUserPrincipal().getName()); 
    975  
     984            logger.error("setting user info username "+request.getUserPrincipal().getName()); 
    976985            Document msg_doc = XMLConverter.newDOM(); 
    977986            Element userInfoMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM); 
     
    10001009 
    10011010                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"); 
    10031012                xml_request.appendChild(userInformation); 
    10041013            } 
     
    10081017        if (collection != null && !collection.equals("")) 
    10091018        { 
     1019          logger.error("kk in a coll"+collection); 
    10101020            //Get the security info for this collection 
    10111021          Document msg_doc = XMLConverter.newDOM(); 
     
    10421052                if (!found) 
    10431053                { 
     1054                  logger.error("kk current user not allowed to access"); 
    10441055                  Document loginPageDoc = XMLConverter.newDOM(); 
    10451056                    Element loginPageMessage = loginPageDoc.createElement(GSXML.MESSAGE_ELEM); 
     
    10551066 
    10561067                    Element messageParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 
    1057                     messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage"); 
     1068                    messageParam.setAttribute(GSXML.NAME_ATT, LOGIN_MESSAGE_PARAM); 
    10581069                    if (request.getAuthType() == null) 
    10591070                    { 
    1060                         messageParam.setAttribute(GSXML.VALUE_ATT, "Please log in to view this page"); 
     1071                      messageParam.setAttribute(GSXML.VALUE_ATT, getTextString("auth.error.login", lang)); 
    10611072                    } 
    10621073                    else 
    10631074                    { 
    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)); 
    10651076                    } 
    10661077                    paramList.appendChild(messageParam); 
    10671078 
    10681079                    Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 
    1069                     urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL"); 
     1080                    urlParam.setAttribute(GSXML.NAME_ATT, REDIRECT_URL_PARAM); 
    10701081                    if (request.getQueryString() != null && request.getQueryString().length() > 0) 
    10711082                    { 
     
    10781089                    paramList.appendChild(urlParam); 
    10791090 
     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)); 
    10801099                    Node loginPageResponse = this.recept.process(loginPageMessage); 
    10811100                    out.println(XMLConverter.getPrettyString(loginPageResponse)); 
     
    10851104            } 
    10861105        } 
     1106        logger.error("kk reurned true"); 
    10871107        return true; 
    10881108    } 
    10891109 
     1110  private String getTextString(String key, String lang) { 
     1111    return Dictionary.getTextString(key, lang, "ServiceRack", null, null); 
     1112   
     1113  } 
    10901114    //a debugging method 
    10911115    private void displaySize(Hashtable<String, UserSessionCache> table)