Changeset 34086

Show
Ignore:
Timestamp:
15.03.2020 17:47:35 (2 weeks ago)
Author:
davidb
Message:

Refactoring code to have generateRedirect method needed some additional work to correctly handle setting RedirectURL in both cases where the method is called

Files:
1 modified

Legend:

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

    r33770 r34086  
    465465    { 
    466466    baseURL = requestedURL.substring(0, requestedURL.indexOf(library_name)); 
     467     
     468    int protocol_boundary_pos = baseURL.indexOf("://"); 
     469    if (protocol_boundary_pos>=1) { 
     470        baseURL = baseURL.substring(protocol_boundary_pos+1); // change things like http:// or https:// to // 
     471    } 
     472         
    467473    } 
    468474    String fullURL; 
     
    917923    } 
    918924     
    919     private void generateLoginPage(String query_string, String error_message, UserContext userContext, PrintWriter out, String baseURL, String output) { 
     925    private void generateLoginPage(String redirect_url_string, String error_message, UserContext userContext, PrintWriter out, String baseURL, String output) { 
    920926     
    921927    Document loginPageDoc = XMLConverter.newDOM(); 
     
    939945    Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 
    940946    urlParam.setAttribute(GSXML.NAME_ATT, REDIRECT_URL_PARAM); 
    941     urlParam.setAttribute(GSXML.VALUE_ATT, library_name + query_string); 
     947 
     948    if (redirect_url_string.matches("^[a-z]+://.*$")) { 
     949        int protocol_boundary_pos = redirect_url_string.indexOf("://"); 
     950        redirect_url_string = redirect_url_string.substring(protocol_boundary_pos+1); // change things like http:// or https:// to // 
     951    } 
     952 
     953    urlParam.setAttribute(GSXML.VALUE_ATT, redirect_url_string); 
    942954    paramList.appendChild(urlParam); 
    943955     
    944956    Node loginPageResponse = this.recept.process(loginPageMessage); 
    945     out.println(XMLConverter.getPrettyString(loginPageResponse)); 
    946      
     957    out.println(XMLConverter.getPrettyString(loginPageResponse));    
    947958    } 
    948959     
     
    9911002        { 
    9921003            //The user entered in either the wrong username or the wrong password 
    993             String query_string = ""; 
    994             if (request.getQueryString() != null) 
     1004            String redirect_url_string = library_name; 
     1005            if (request.getQueryString() != null) //  && request.getQueryString().length() > 0) 
    9951006            { 
    996             query_string = "?" + request.getQueryString().replace("&", "&"); 
     1007            redirect_url_string += "?" + request.getQueryString().replace("&", "&"); 
    9971008            } 
    998          
    999             generateLoginPage(query_string, getTextString("auth.error.un_or_pw_err", lang), userContext, out, baseURL, output); 
     1009 
     1010            generateLoginPage(redirect_url_string, getTextString("auth.error.un_or_pw_err", lang), userContext, out, baseURL, output); 
    10001011            return false; 
    10011012        } 
     
    10961107            error_message = getTextString("auth.error.incorrect_login", lang); 
    10971108        } 
    1098         String query_string = ""; 
     1109        String redirect_url_string = request.getRequestURL().toString(); 
    10991110        if (request.getQueryString() != null && request.getQueryString().length() > 0) 
    11001111        { 
    1101             query_string = request.getRequestURL() + "?" + request.getQueryString().replace("&", "&"); 
     1112            redirect_url_string += "?" + request.getQueryString().replace("&", "&"); 
    11021113        } 
    1103         else 
    1104         { 
    1105             query_string = request.getRequestURL().toString(); 
    1106         } 
    1107         generateLoginPage(query_string, error_message, userContext, out, baseURL, output); 
     1114         
     1115        generateLoginPage(redirect_url_string, error_message, userContext, out, baseURL, output); 
    11081116        return false; 
    11091117        }