Changeset 35287


Ignore:
Timestamp:
2021-08-12T19:34:43+12:00 (3 years ago)
Author:
anupama
Message:

Part 2 of commit on expanded user groups, related to prev commit (revision 35286) which was part 1. In this commit, I think I've identified the only times UserTermInfo.getExpandedGroups() needs to be called: when authentication-ping/ServletRealmCheck is called, which redirect to Authentication.processRemoteAuthentication(). At other times, the original group listing is what's required (for user listing display/modification in GS3 Reader Interface) or is sufficient (to check user is in admin group, the group listing in userDB/originally entered group listing is enough and no expanded list is needed. Maybe origGroups can better be renamed back to groups and getOrigGroups replaced with plain getGroups(), since getExpandedGroups() is the method called in more exceptional circumstances after all.

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

Legend:

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

    r35286 r35287  
    163163  protected static final String COLLECTION = "collection";
    164164  protected static final String GROUPS = "groups";
     165  protected static final String EXPANDED_GROUPS = "expanded_groups";
    165166  protected static final String STATUS = "status";
    166167  protected static final String RECAPTCHA_KEY = "recaptcha_key";
     
    427428               
    428429                // gliserver.pl used to return the groups when authentication succeeded
    429                 String groups = retrieveDataForUser(username, GROUPS); //comma-separated list
     430                String groups = retrieveDataForUser(username, EXPANDED_GROUPS); //comma-separated list
    430431               
    431432                if(collection.equals("")) {
     
    12111212                    break;
    12121213                }
     1214                else if (dataType.equals(EXPANDED_GROUPS))
     1215                {
     1216                    data = ((UserTermInfo) userInfo.get(i)).getExpandedGroups();
     1217                    break;
     1218                }
    12131219                else if (dataType.equals(STATUS))
    12141220                {
     
    12471253            String username = ((UserTermInfo) userInfo.get(i)).getUsername();
    12481254            String groups = ((UserTermInfo) userInfo.get(i)).getOrigGroups();
     1255            // Retrieve original (stored, user-entered) and not expanded groups
     1256            // as getUserNodeList only used in addUserInformationToNode() which
     1257            // allows displaying and modifying user info pages
     1258            // and authenticating admin user which doesn't require expanded groups.
    12491259            String accountstatus = ((UserTermInfo) userInfo.get(i)).getAccountStatus();
    12501260            String comment = ((UserTermInfo) userInfo.get(i)).getComment();
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/ModifyUsersDB.java

    r35286 r35287  
    138138            if (groups.equals(""))
    139139            {
     140                // groups should be origGroups and not expandedGroups
     141                // As we want to store the groups in DB as entered
     142                // and not as programmatically expanded.
    140143                groups = user.getOrigGroups();
    141144            }
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/UserTermInfo.java

    r35286 r35287  
    2020package org.greenstone.gsdl3.util;
    2121
    22 //import java.util.Set;
    23 //import java.util.TreeSet;
     22import java.util.Set;
     23import java.util.TreeSet;
    2424
    2525public class UserTermInfo
     
    2828    private String password;
    2929    private String origGroups;
    30     private String expandedGroups;   
     30        private String expandedGroups = null;
    3131    private String accountstatus;
    3232    private String comment;
     
    3838    this.password = password;
    3939    this.origGroups = groups;
    40     this.expandedGroups = UserTermInfo.expandGroups(this.origGroups);
     40    //this.expandedGroups = UserTermInfo.expandGroups(this.origGroups); // Will do lazy evaluation
    4141    this.accountstatus = accountStatus;
    4242    this.comment = comment;
     
    7070   
    7171    public String getExpandedGroups() {
     72    //return expandedGroups;
     73    //return UserTermInfo.expandGroups(this.origGroups); // not storing, evaluating on demand
     74   
     75    // lazy evaluation: getExpandedGroups() doesn't get called on every enquiry about
     76    // a UserTermInfo struct. It only gets called on authenticated-ping system-action
     77    // (including via ServletRealmCheck being run from run from commandline or gliserver.pl)
     78    // So for a whole list of users and the UserTermInfo struct of each,
     79    // don't pre-calculate and store the expanded groups.
     80    // Is it meaningful to store this at all Ever or better to always evaluate on demand?
     81    if(expandedGroups == null) {
     82        expandedGroups = UserTermInfo.expandGroups(this.origGroups);
     83    }
    7284    return expandedGroups;
    7385    }
     
    95107     *   katoa.maori.place.iwi.hapu, katoa.maori.place.iwi.hapu.person
    96108     * This method looks through all the groups and if any contains a period,
    97      * it will expand such into all their explicit subgroups in the manner of the above example
    98      * and then add them all back into the existing list of groups.
     109     * it will expand such into all their explicit subgroups.
    99110     * @param groups: String listing command-separated groups, any of which may
    100111     * need expanding out.
    101      * @return a comma-separated String listing the expanded groups.
     112     * @return a comma-separated String listing all the original groups plus any expanded groups
     113     * in natural order (so alphabetised).
    102114     *
    103115     * Tested at https://www.jdoodle.com/online-java-compiler/, where main contains:
     
    109121     *
    110122     * Also tested with the expandable string at start and at end of list of groups input string.
    111     */
    112     /*
    113     public static String expandGroups(String groups) {
    114     if(groups.indexOf('.') == -1) {
    115         return groups;
    116     }
    117     else {
    118         // Build up the string again
    119         StringBuilder expandedGroupList = new StringBuilder();     
    120 
    121         String[] indivGroups = groups.split("\\s*,\\s*"); // simultaneously get rid of any whitespace surrounding commas
    122         for(String s : indivGroups) {
    123         int indexOfPeriod = s.indexOf('.');
    124 
    125         if(indexOfPeriod != -1) {
    126             do {
    127             String expandedGroup = s.substring(0, indexOfPeriod);
    128             expandedGroupList.append(expandedGroup);
    129             expandedGroupList.append(',');
    130             indexOfPeriod += 1;         
    131             indexOfPeriod = s.indexOf('.', indexOfPeriod);
    132             } while(indexOfPeriod != -1);
    133         }
    134 
    135         // Whether this particular group s contained a period or not,
    136         // remember to add this group string, s, back in in its entirety too       
    137         expandedGroupList.append(s);
    138         expandedGroupList.append(',');
    139         }
    140         expandedGroupList.deleteCharAt(expandedGroupList.length()-1); // remove extraneous comma       
    141         return expandedGroupList.toString();
    142     }
    143     }
    144     */
    145 
    146     /**
     123     *
    147124     * This expansion method doesn't preserve overall ordering,
    148125     * e.g. if groups = "all-collections-editor, katoa.maori.place.iwi.hapu.person, admin"
    149126     * result is:
    150127     *    admin,all-collections-editor,katoa,katoa.maori,katoa.maori.place,katoa.maori.place.iwi,katoa.maori.place.iwi.hapu,katoa.maori.place.iwi.hapu.person
    151      * However, this method will ensure no duplicates, e.g. only one katoa, one katoa.maori etc.
     128     * Where admin is now at start and all-colls-editor now comes after it.
     129     * However, this method will ensure the requirement of no duplicates,
     130     * e.g. only one katoa, one katoa.maori etc.
     131     * to minimising checking if a user has necessary group membership,
    152132     *   e.g. String groups = "all-collections-editor, admin, org.waikato.cs.dl.anu , org.waikato.cs.dl.pinky";
    153133     * Produces the result:
     
    191171    }
    192172    }
     173
     174
     175     /*
     176    public static String expandGroups(String groups) {
     177    if(groups.indexOf('.') == -1) {
     178        return groups;
     179    }
     180    else {
     181        // Build up the string again
     182        StringBuilder expandedGroupList = new StringBuilder();     
     183
     184        String[] indivGroups = groups.split("\\s*,\\s*"); // simultaneously get rid of any whitespace surrounding commas
     185        for(String s : indivGroups) {
     186        int indexOfPeriod = s.indexOf('.');
     187
     188        if(indexOfPeriod != -1) {
     189            do {
     190            String expandedGroup = s.substring(0, indexOfPeriod);
     191            expandedGroupList.append(expandedGroup);
     192            expandedGroupList.append(',');
     193            indexOfPeriod += 1;         
     194            indexOfPeriod = s.indexOf('.', indexOfPeriod);
     195            } while(indexOfPeriod != -1);
     196        }
     197
     198        // Whether this particular group s contained a period or not,
     199        // remember to add this group string, s, back in in its entirety too       
     200        expandedGroupList.append(s);
     201        expandedGroupList.append(',');
     202        }
     203        expandedGroupList.deleteCharAt(expandedGroupList.length()-1); // remove extraneous comma       
     204        return expandedGroupList.toString();
     205    }
     206    }
     207    */
    193208   
    194209}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/txt2usersDB.java

    r35286 r35287  
    184184                                password = Authentication.hashPassword(password);
    185185                            }
     186
     187                            // groups should be origGroups and not expandedGroups
     188                            // As we want to store the groups in DB as entered
     189                            // and not as programmatically expanded.
    186190                            groups = groups.equals("") ? user.getOrigGroups() : groups;
    187191                            accountstatus = accountstatus.equals("") ? user.getAccountStatus() : accountstatus;
Note: See TracChangeset for help on using the changeset viewer.