Changeset 35287
- Timestamp:
- 2021-08-12T19:34:43+12:00 (3 years ago)
- 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 163 163 protected static final String COLLECTION = "collection"; 164 164 protected static final String GROUPS = "groups"; 165 protected static final String EXPANDED_GROUPS = "expanded_groups"; 165 166 protected static final String STATUS = "status"; 166 167 protected static final String RECAPTCHA_KEY = "recaptcha_key"; … … 427 428 428 429 // gliserver.pl used to return the groups when authentication succeeded 429 String groups = retrieveDataForUser(username, GROUPS); //comma-separated list430 String groups = retrieveDataForUser(username, EXPANDED_GROUPS); //comma-separated list 430 431 431 432 if(collection.equals("")) { … … 1211 1212 break; 1212 1213 } 1214 else if (dataType.equals(EXPANDED_GROUPS)) 1215 { 1216 data = ((UserTermInfo) userInfo.get(i)).getExpandedGroups(); 1217 break; 1218 } 1213 1219 else if (dataType.equals(STATUS)) 1214 1220 { … … 1247 1253 String username = ((UserTermInfo) userInfo.get(i)).getUsername(); 1248 1254 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. 1249 1259 String accountstatus = ((UserTermInfo) userInfo.get(i)).getAccountStatus(); 1250 1260 String comment = ((UserTermInfo) userInfo.get(i)).getComment(); -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/ModifyUsersDB.java
r35286 r35287 138 138 if (groups.equals("")) 139 139 { 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. 140 143 groups = user.getOrigGroups(); 141 144 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/UserTermInfo.java
r35286 r35287 20 20 package org.greenstone.gsdl3.util; 21 21 22 //import java.util.Set;23 //import java.util.TreeSet;22 import java.util.Set; 23 import java.util.TreeSet; 24 24 25 25 public class UserTermInfo … … 28 28 private String password; 29 29 private String origGroups; 30 private String expandedGroups; 30 private String expandedGroups = null; 31 31 private String accountstatus; 32 32 private String comment; … … 38 38 this.password = password; 39 39 this.origGroups = groups; 40 this.expandedGroups = UserTermInfo.expandGroups(this.origGroups);40 //this.expandedGroups = UserTermInfo.expandGroups(this.origGroups); // Will do lazy evaluation 41 41 this.accountstatus = accountStatus; 42 42 this.comment = comment; … … 70 70 71 71 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 } 72 84 return expandedGroups; 73 85 } … … 95 107 * katoa.maori.place.iwi.hapu, katoa.maori.place.iwi.hapu.person 96 108 * 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. 99 110 * @param groups: String listing command-separated groups, any of which may 100 111 * 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). 102 114 * 103 115 * Tested at https://www.jdoodle.com/online-java-compiler/, where main contains: … … 109 121 * 110 122 * 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 * 147 124 * This expansion method doesn't preserve overall ordering, 148 125 * e.g. if groups = "all-collections-editor, katoa.maori.place.iwi.hapu.person, admin" 149 126 * result is: 150 127 * 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, 152 132 * e.g. String groups = "all-collections-editor, admin, org.waikato.cs.dl.anu , org.waikato.cs.dl.pinky"; 153 133 * Produces the result: … … 191 171 } 192 172 } 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 */ 193 208 194 209 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/txt2usersDB.java
r35286 r35287 184 184 password = Authentication.hashPassword(password); 185 185 } 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. 186 190 groups = groups.equals("") ? user.getOrigGroups() : groups; 187 191 accountstatus = accountstatus.equals("") ? user.getAccountStatus() : accountstatus;
Note:
See TracChangeset
for help on using the changeset viewer.