Changeset 35299
- Timestamp:
- 2021-08-16T20:38:05+12:00 (3 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java
r35298 r35299 1084 1084 for (int i = 0; i < userQueryResult.getSize(); i++) 1085 1085 { 1086 // can call either getExpandedGroups() or get OrigGroups() to check admin group is in there:1087 if (((UserTermInfo) userInfo.get(i)).get OrigGroups() != null && ((UserTermInfo) userInfo.get(i)).getOrigGroups().matches(".*\\badministrator\\b.*"))1086 // can call either getExpandedGroups() or getCompactedGroups() to check admin group is in there: 1087 if (((UserTermInfo) userInfo.get(i)).getCompactedGroups() != null && ((UserTermInfo) userInfo.get(i)).getCompactedGroups().matches(".*\\badministrator\\b.*")) 1088 1088 { 1089 1089 adminFound = true; … … 1217 1217 else if (dataType.equals(COMPACTED_GROUPS)) 1218 1218 { 1219 data = ((UserTermInfo) userInfo.get(i)).get OrigGroups();1219 data = ((UserTermInfo) userInfo.get(i)).getCompactedGroups(); 1220 1220 break; 1221 1221 } … … 1260 1260 Element user_node = doc.createElement(GSXML.USER_NODE_ELEM); 1261 1261 String username = ((UserTermInfo) userInfo.get(i)).getUsername(); 1262 String compactedGroups = ((UserTermInfo) userInfo.get(i)).get OrigGroups();1262 String compactedGroups = ((UserTermInfo) userInfo.get(i)).getCompactedGroups(); 1263 1263 // Since this is used for display in admin pages, get compacted (more similar to user-entered) groups 1264 1264 // and not expanded groups, as getUserNodeList only used in addUserInformationToNode() which -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/UserTermInfo.java
r35298 r35299 27 27 private String username; 28 28 private String password; 29 private String origGroups = null; // TODO: rename to compactedGroups and get-method, and update method calls accordingly 29 /** The user-entered value of groups listing sorted into natural ordering 30 * (alphabetic/ASCII order in this case) and with duplicates removed */ 31 private String compactedGroups; 32 /** The user-entered value of groups listing with hierarchical groups expanded, sorted and duplicates removed 33 * e.g. if groups="nz.ac.waikato.toto,nz.ac.waikato.cs.pinky"; expandedGroups="nz,nz.ac,nz.ac.waikato,nz.ac.waikato.cs,nz.ac.waikato.cs.pinky,nz.ac.waikato.toto" */ 30 34 private String expandedGroups; 31 35 private String accountstatus; … … 34 38 35 39 // This constructor is called to instantiate a UserTermInfo object from entries in the userDB 36 // which now stores expandedGroups instead of the user-entered origGroups 37 // Use the other constructor if you know the user-entered groups 40 // which now stores expandedGroups instead of the user-entered groups or the latter's more compactedGroups form 38 41 public UserTermInfo(String username, String password, String expandedGroups, 39 42 String accountStatus, String comment, String email) { … … 41 44 this.password = password; 42 45 43 46 // Ensure these 2 representations of the groups listing are always in sync 44 47 this.expandedGroups = expandedGroups; 45 this.origGroups = UserTermInfo.compactGroups(this.expandedGroups); // alternative: don't set here and do lazy evaluation when getOrigGroups() is called 48 this.compactedGroups = UserTermInfo.compactGroups(this.expandedGroups); // alternative: don't set here and do lazy evaluation when getCompactedGroups() is called 49 46 50 this.accountstatus = accountStatus; 47 51 this.comment = comment; 48 52 this.email = email; 49 53 } 50 51 52 // Not used, for completion's sake:53 // If you only have user-entered groups at hand, pass in null or "" for expandedGroups54 // to create a UserTermInfo object, which will work out the expandedGroups.55 /*56 public UserTermInfo(String username, String password, String userEnteredGroups, String expandedGroups,57 String accountStatus, String comment, String email) {58 this.username = username;59 this.password = password;60 61 this.origGroups = (userEnteredGroups == null) ? "" : userEnteredGroups;62 if(expandedGroups == null || expandedGroups.equals("")) {63 this.expandedGroups = UserTermInfo.expandGroups(this.origGroups);64 }65 this.accountstatus = accountStatus;66 this.comment = comment;67 this.email = email;68 }69 */70 54 71 55 public String toString() … … 74 58 result += "<username = " + username + ">"; 75 59 result += "<password = " + password + ">"; 76 result += "<groups = " + origGroups + ">";60 result += "<groups = " + expandedGroups + ">"; // compactedGroups? 77 61 result += "<enable = " + accountstatus + ">"; 78 62 result += "<comment = " + comment + ">"; … … 90 74 } 91 75 92 public String getOrigGroups() { 93 return origGroups; 94 //return UserTermInfo.compactGroups(this.expandedGroups); // not storing, evaluating on demand 95 96 // lazy evaluation: getExpandedGroups() doesn't get called on every enquiry about 97 // a UserTermInfo struct. It only gets called on authenticated-ping system-action 98 // (including via ServletRealmCheck being run from run from commandline or gliserver.pl) 99 // So for a whole list of users and the UserTermInfo struct of each, 100 // don't pre-calculate and store the expanded groups. 101 // Is it meaningful to store this at all Ever or better to always evaluate on demand? 102 76 public String getCompactedGroups() { 77 return compactedGroups; 78 // could do lazy evaluation by calling UserTermInfo.compactGroups(this.expandedGroups) here and returning it 79 // or 1st storing answer in compactedGroups member var before returning to avoid reevaluating multiple times. 103 80 } 104 81 105 82 public String getExpandedGroups() { 106 83 return expandedGroups; 107 //return UserTermInfo.expandGroups(this.origGroups); // not storing, evaluating on demand108 109 // lazy evaluation: getExpandedGroups() doesn't get called on every enquiry about110 // a UserTermInfo struct. It only gets called on authenticated-ping system-action111 // (including via ServletRealmCheck being run from run from commandline or gliserver.pl)112 // So for a whole list of users and the UserTermInfo struct of each,113 // don't pre-calculate and store the expanded groups.114 // Is it meaningful to store this at all Ever or better to always evaluate on demand?115 ///if(expandedGroups == null) {116 /// expandedGroups = UserTermInfo.expandGroups(this.origGroups);117 ///}118 ///return expandedGroups;119 84 } 120 85 … … 196 161 return compactGroupList.toString(); 197 162 } 198 199 200 /*201 else {202 203 204 String[] indivGroups = groups.split("\\s*,\\s*"); // simultaneously get rid of whitespace surrounding commas205 if(indivGroups.length == 0) {206 return groups;207 }208 Set<String> compactGroups = new TreeSet<String>();209 String currGroup = indivGroups[indivGroups.length-1];210 for(int i = indivGroups.length-1; i--; i > 0) {211 String prevGroup = indivGroups[i-1];212 213 int indexOfPeriod = currGroup.indexOf('.');214 if(indexOfPeriod == -1) {215 compactGroups.add(currGroup);216 currGroup = prevGroup;217 }218 else {219 220 if(currGroup.startsWith(prevGroup)) {221 compactGroups.add(currGroup);222 if(i == 0) {223 break;224 } else {225 i--;226 currGroup = indivGroups[i];227 }228 }229 else {230 compactGroups.add(currGroup);231 currGroup = prevGroup;232 }233 }234 }235 }236 */237 163 } 238 164 … … 311 237 312 238 313 /*314 public static String expandGroups(String groups) {315 if(groups.indexOf('.') == -1) {316 return groups;317 }318 else {319 // Build up the string again320 StringBuilder expandedGroupList = new StringBuilder();321 322 String[] indivGroups = groups.split("\\s*,\\s*"); // simultaneously get rid of any whitespace surrounding commas323 for(String s : indivGroups) {324 int indexOfPeriod = s.indexOf('.');325 326 if(indexOfPeriod != -1) {327 do {328 String expandedGroup = s.substring(0, indexOfPeriod);329 expandedGroupList.append(expandedGroup);330 expandedGroupList.append(',');331 indexOfPeriod += 1;332 indexOfPeriod = s.indexOf('.', indexOfPeriod);333 } while(indexOfPeriod != -1);334 }335 336 // Whether this particular group s contained a period or not,337 // remember to add this group string, s, back in in its entirety too338 expandedGroupList.append(s);339 expandedGroupList.append(',');340 }341 expandedGroupList.deleteCharAt(expandedGroupList.length()-1); // remove extraneous comma342 return expandedGroupList.toString();343 }344 }345 */346 347 239 }
Note:
See TracChangeset
for help on using the changeset viewer.