Changeset 37390


Ignore:
Timestamp:
2023-03-02T23:05:36+13:00 (14 months ago)
Author:
davidb
Message:

A set of changes related to supporting GoogleIdentity signin

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
3 edited

Legend:

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

    r36023 r37390  
    169169       
    170170    //containerLog.debug("**** GoogleSigninJDBCRealm::initGoogleIdTokenVerifier():" + googlesignin_client_id);
    171     System.err.println("**** GoogleSigninJDBCRealm::initGoogleIdTokenVerifier() googlesignin_client_id=" + googlesignin_client_id);
     171    //System.err.println("**** GoogleSigninJDBCRealm::initGoogleIdTokenVerifier() googlesignin_client_id=" + googlesignin_client_id);
    172172    //GoogleSigninJDBCRealm.googlesignin_client_id = googlesignin_client_id;
    173173   
     
    326326    public String getGreenstoneUsernameFromGoogleTokenId(String googlesignin_id_token)
    327327    {   
    328     System.err.println("**** GoogleSigninJDBCRealm::getGreenstoneUsernameFromGoogleTokenId():" + googlesignin_id_token);
     328    //System.err.println("**** GoogleSigninJDBCRealm::getGreenstoneUsernameFromGoogleTokenId():" + googlesignin_id_token);
    329329   
    330330    String greenstone_username = null;
     
    371371    }
    372372    else {
    373         System.err.println("***** No googlesignin_id_token detected.  No Google Signin check to do");
     373        System.err.println("No googlesignin_id_token detected.  No Google Signin check to do");
    374374    }
    375375   
    376     System.err.println("***** End of getGoogleSinginInfo()");
     376    //System.err.println("***** End of getGoogleSinginInfo()");
    377377   
    378378    return greenstone_username;
     
    384384    public Principal authenticate(String username, String credentials)
    385385    {
     386    //System.err.println("**** in GogleSigninJDBCRealm::authenticte()");
     387    //System.err.println("  username = " + username);
     388    //System.err.println("  credentials = " + credentials);
     389   
    386390    Principal principal = null;
    387391   
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r37136 r37390  
    552552    userContext.setUserID(uid);
    553553
     554    // If GoogleSignin is operational (due to googlesignin_client_id specified in servlet.xml)
     555    // AND a Google Client ID Token is provided via googlesignin_id_token then
     556    // initiate authentication via Google Signin, which is then tied into Greenstone3 through
     557    // the customized Realm written for Greenstone3.
     558    //
     559    // This customized Realm, GoogleSigninJDBCRealm, works by overriding 'authenticate()'
     560    // in Realm.
     561
     562    // 1.  If the username 'googlesign' is provided, then the credentials
     563    //     passed in needs to be a valid verifyable Google Client Id Token.
     564    // 1a. From this verified token, the email address that is registered with
     565    //     Google for that user account is then used to find a match in the
     566    //     Greenstone3 JDBC-specified Username table.
     567    // 1b. Assuming that an email address match is found, then the customized Realm
     568    //     completes the authentication process by making the found username, the
     569    //     one that is autheticated.
     570    // 2.  If the username is anything but 'googlesignin' then the authentication process
     571    //     continues as with the regular JDBCRealm process
     572       
     573    //String googlesignin_id_token = getFirstParam("googlesignin_id_token",queryMap);
     574    //if ((googlesignin_id_token != null) && (!googlesignin_id_token.equals(""))) {
     575
     576    String googleidentity_signin = getFirstParam(GSParams.GOOGLE_SIGNIN,queryMap);
     577    if ((googleidentity_signin != null) && (googleidentity_signin.equals("1"))) {
     578    queryMap.put(GSParams.USERNAME, new String[] { GoogleSigninJDBCRealm.GOOGLESIGNIN_USERNAME_BRIDGE });
     579
     580    String googlesignin_credential = getFirstParam("credential",queryMap);
     581    queryMap.put(GSParams.PASSWORD, new String[] { googlesignin_credential });
     582    // logger.info("**** googlesignin_credenital (aka id_token) = '" + googlesignin_credential +"'");
     583    }
     584
     585   
    554586    if (!processLoginChanges(request, userContext, out, baseURL, queryMap, lang, output)) {
    555587    // any invalid login attempt will redirect to a new login page and return false
     
    813845        else
    814846          {
    815         Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
    816         param.setAttribute(GSXML.NAME_ATT, name);
    817         param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(value));
    818         if (this.gs_params.isSensitive(name)) {
    819           param.setAttribute(GSXML.SENSITIVE_ATT, "true");
    820         }
    821         xml_param_list.appendChild(param);
     847          // If logging out as the very next step after logging in, then
     848          // the 'password' param was found to be null
     849          //
     850          // This then causes GSXML.xsmSafe(value) to throw an exception
     851          // For now, the coding decision is to test for null, and skip
     852          // adding the param if it is null
     853          //
     854          // Could be that it is more meaningful to store the values as
     855          // the empty string.  In which case updating GSXML.xsmlSafe to
     856          // test for null and treat it as an empty string would be
     857          // a better way to go
     858         
     859          if (value != null) {
     860              Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
     861              param.setAttribute(GSXML.NAME_ATT, name);
     862              param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(value));
     863              if (this.gs_params.isSensitive(name)) {
     864              param.setAttribute(GSXML.SENSITIVE_ATT, "true");
     865              }
     866              xml_param_list.appendChild(param);
     867          }
    822868                       
    823869          }
     
    896942    xml_request.setAttribute("baseURL", baseURL);
    897943
    898 //    logger.error("about to process this message");
    899     //   logger.error(XMLConverter.getPrettyString(xml_message));
     944    // logger.error("about to process this message");
     945    // logger.error(XMLConverter.getPrettyString(xml_message));
    900946    Node xml_result = this.recept.process(xml_message);
    901947    encodeURLs(xml_result, response);
     
    10311077   
    10321078    private boolean processLoginChanges(HttpServletRequest request, UserContext userContext, PrintWriter out, String baseURL, Map<String, String[]> queryMap, String lang, String output) throws ServletException {
    1033    
     1079
     1080    //logger.info("Start of LibraryServlet::processLoginChanges()");   
     1081
    10341082    //Check if we need to login or logout
    10351083    String username = getFirstParam(GSParams.USERNAME, queryMap);
     
    10391087    if (logout != null)
    10401088    {
     1089        //logger.info("LibraryServlet::processLoginChanges() logging out (logout cgi param non-null)");
    10411090        request.logout();
    10421091    }
     
    10441093    if (username != null && password != null)
    10451094    {
     1095        //logger.info("LibrarySerlvet::processLoginChagnes(): username and password not null");
     1096
    10461097        //We are changing to another user, so log out first
    10471098        if (request.getAuthType() != null)
    10481099        {
     1100        //logger.info("Logging out (preparing to change to another user) ");
    10491101        request.logout();
    10501102        }
     
    10531105        try
    10541106        {
    1055         //Try a global login first
    1056         password = Authentication.hashPassword(password);
     1107        //Try a global login first, and then go on to site-login if throws exception
     1108        if (!username.equals(GoogleSigninJDBCRealm.GOOGLESIGNIN_USERNAME_BRIDGE)) {
     1109            // Hashing password used by a direct to Greenstone3 authentication text,
     1110            // but not when a Google Signin
     1111            password = Authentication.hashPassword(password);
     1112        }
     1113       
    10571114        request.login(username, password);
     1115        //logger.info("Global Login successful");
    10581116            }
    10591117        catch (Exception ex)
     
    10631121            //If the global login fails then try a site-level login
    10641122            String siteName = (String) this.recept.getConfigParams().get(GSConstants.SITE_NAME);
    1065             request.login(siteName + "-" + username, password);
    1066    
     1123            String siteUserName = siteName + "-" + username;
     1124            //logger.info("Global login unsuccessful, trying site-level login with: " + siteUserName);
     1125            request.login(siteUserName, password);
     1126            //logger.info("Site-wide login successful");
    10671127        }
    10681128        catch (Exception exc)
    10691129        {
     1130            //logger.info("Site-wide login unsuccessful => generating login page");         
     1131
    10701132            //The user entered in either the wrong username or the wrong password
    10711133       
     
    10911153    private void updateUserContextWithAuthenticatedInfo(HttpServletRequest request, UserContext userContext)
    10921154    {
     1155    //logger.info("Start of updateUserContextWithAutenticatedInfo");
    10931156   
    10941157    //Get the username
    10951158    String user_name = request.getUserPrincipal().getName();
     1159    //logger.info("  getUserPrincipal user_name = " + user_name);
     1160   
    10961161    userContext.setUsername(user_name);
    10971162
     
    12421307    private boolean runCollectionSecurityCheck(HttpServletRequest request, UserContext userContext, PrintWriter out, String baseURL, String collection, String document, String lang, String output) {
    12431308
     1309        // logger.info("LibraryServlet::runCollectionSecurityCheck(): start of check for collection:"+collection);
     1310   
    12441311    //Get the security info for this collection
    12451312    Document msg_doc = XMLConverter.newDOM();
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSParams.java

    r37097 r37390  
    7575 
    7676    //Administration
    77         public static final String PASSWORD = "password";
    78         public static final String USERNAME = "username";
    79         public static final String LOGOUT = "logout";
    80   public static final String VERIFIED = "hmvf";
     77    public static final String PASSWORD = "password";
     78    public static final String USERNAME = "username";
     79    public static final String GOOGLE_SIGNIN = "googleidentity-signin";
     80    public static final String LOGOUT = "logout";
     81    public static final String VERIFIED = "hmvf";
    8182
    8283    // some standard arg values
Note: See TracChangeset for help on using the changeset viewer.