Changeset 37660 for main


Ignore:
Timestamp:
2023-04-13T21:49:38+12:00 (13 months ago)
Author:
anupama
Message:

ModifyUsersDB() had been modified in revision 35333 and important code present in 35298 had not been retained. That code would re-read the groups and other unmodified fields of a user whose other field(s) were being modified, before storing modified and unmodified values back in the userDB. The new code did not persist existing unmodified values, as a result, running ant config-admin from cmdline or through the installer to change the admin password through all but the GS3 web system (or running update-userdb from the cmdline for any user), would clobber the existing values in the userdb for the fields not being modified. DerbyWrapper.modifyUserInfo() also expressly clobbers the groups field unless the provided groups is null. However, ModifyUsersDB nowadays uses groups = expandGroups(groups) to deal with domain-style groups. Method expandGroups(groups) never returns null, only empty string at minimum, so this would not have fixed the issue either. I still don't know what route the GS3 web system is taking for setting the password, but it did not clobber the groups field at least. However, I've made the minimum number of changes I think necessary to get the ModifyUsersDB.java part of the code (used by ant config-admin/ant update-userdb) to work again.

File:
1 edited

Legend:

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

    r35333 r37660  
    183183    }
    184184
    185   public static void modifyUser(DerbyWrapper dw, UserTermInfo user, String username, String password, String groups, String addgroups, String accountstatus, String comment, String email) { 
    186                    
     185  private static void modifyUser(DerbyWrapper dw, UserTermInfo user, String username, String password, String groups, String addgroups, String accountstatus, String comment, String email) {
     186
     187      // Copied code back from svn rev=35298 into this function, as without it, modifying users/admin pwd
     188      // wiped out rest of its details from userdb. Notably groups, as groups below now needs to be null
     189      // for code to read groups' values back in from db
     190      if (groups.equals(""))
     191    {
     192        // groups should be expandedGroups because we no longer store the groups in userDB
     193        // as user-entered or compacted, but as programmatically expanded.
     194        // This allows HttpServletRequest.isUserInRole() to now automatically retrieve the
     195        // expandedGroups list of a user to check collectionConfig.xml security elements against.
     196       
     197        groups = user.getExpandedGroups(); // get from database
     198    } //else {
     199    //groups = UserTermInfo.expandGroups(groups); // ensure groups are stored expanded in userDB
     200    //} // Covered: groups var comes in expanded when called from ModifyUsersDB.java::main()
     201    // Only should be done if anyone else can call this modifyUser() function and if they don't ensure
     202    // groups expanded first
     203    // in case any of fields other than username are not specified, get fallbacks from the database
     204   
     205
     206      // groups can never be null at this point if called by ModifyUsersDB.java::main() above,
     207      // as main() does groups=expandGroups() which never returns null, only "" at minimum.     
    187208    if (groups == null && addgroups != null) {
    188209      groups = user.getExpandedGroups(); // get the groups from db, as we want to add on to what is already there
    189210    }
     211
     212    if (password.equals(""))
     213    {
     214        password = user.getPassword(); // already stored hashed-and-hexed in DB
     215    }
     216   
     217    if (accountstatus.equals(""))
     218    {
     219        accountstatus = user.getAccountStatus().equals("") ? "true" : user.getAccountStatus();
     220    }
     221    if (comment.equals(""))
     222    {
     223        comment = user.getComment();
     224    }
     225    if (email.equals(""))
     226    {
     227        email = user.getEmail();
     228    }
     229   
    190230    if (addgroups != null) {
    191231      if (!groups.equals("")) {
Note: See TracChangeset for help on using the changeset viewer.