|
7 | 7 | import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup; |
8 | 8 | import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider; |
9 | 9 | import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean; |
| 10 | +import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup; |
10 | 11 | import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider; |
11 | 12 | import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupsServiceBean; |
| 13 | +import edu.harvard.iq.dataverse.authorization.groups.impl.maildomain.MailDomainGroup; |
12 | 14 | import edu.harvard.iq.dataverse.authorization.groups.impl.maildomain.MailDomainGroupProvider; |
13 | 15 | import edu.harvard.iq.dataverse.authorization.groups.impl.maildomain.MailDomainGroupServiceBean; |
| 16 | +import edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroup; |
14 | 17 | import edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroupProvider; |
15 | 18 | import edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroupServiceBean; |
16 | 19 | import edu.harvard.iq.dataverse.engine.command.DataverseRequest; |
@@ -97,9 +100,49 @@ public MailDomainGroupProvider getMailDomainGroupProvider() { |
97 | 100 | * @return The groups {@code req} is part of under {@code dvo}. |
98 | 101 | */ |
99 | 102 | public Set<Group> groupsFor( DataverseRequest req, DvObject dvo ) { |
100 | | - return groupProviders.values().stream() |
| 103 | + Set<Group> ret = groupProviders.values().stream() |
101 | 104 | .flatMap(gp->(Stream<Group>)gp.groupsFor(req, dvo).stream()) |
102 | 105 | .collect(toSet()); |
| 106 | + |
| 107 | + // ShibGroupProvider.groupsFor(), above, only returns the Shib Groups |
| 108 | + // (as you would expect), but not the Explicit Groups that may include them |
| 109 | + // (unlike the ExplicitGroupProvider, that returns all the ancestors too). |
| 110 | + // We appear to rely on this method returning all of the ancestor groups |
| 111 | + // for everything, so we need to perform some extra hacky steps in |
| 112 | + // order to obtain the ancestors for the shib groups as well: |
| 113 | + |
| 114 | + Set<ExplicitGroup> directAncestorsOfShibGroups = new HashSet<>(); |
| 115 | + for (Group group : ret) { |
| 116 | + |
| 117 | + if (group instanceof ShibGroup |
| 118 | + || group instanceof IpGroup |
| 119 | + || group instanceof MailDomainGroup) { |
| 120 | + // if this is one of the non-explicit group types above, we |
| 121 | + // need to find if it is included in some explicit group; i.e., |
| 122 | + // if it has direct ancestors that happen to be explicit groups: |
| 123 | + |
| 124 | + directAncestorsOfShibGroups.addAll(explicitGroupService.findDirectlyContainingGroups(group)); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + if (!directAncestorsOfShibGroups.isEmpty()) { |
| 129 | + // ... and now we can run the Monster Query in the ExplicitServiceBean |
| 130 | + // that will find ALL the hierarchical explicit group ancestors of |
| 131 | + // these groups that include the shib groups fond |
| 132 | + |
| 133 | + Set<ExplicitGroup> allAncestorsOfShibGroups = explicitGroupService.findClosure(directAncestorsOfShibGroups); |
| 134 | + |
| 135 | + if (allAncestorsOfShibGroups != null) { |
| 136 | + ret.addAll(allAncestorsOfShibGroups); |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + // Perhaps the code above should be moved into the ShibGroupProvider (??) |
| 141 | + // Also, this most likely applies not just to ShibGroups, but to the |
| 142 | + // all the groups that are not ExplicitGroups, i.e., IP- and domain-based |
| 143 | + // groups too. (??) |
| 144 | + |
| 145 | + return ret; |
103 | 146 | } |
104 | 147 |
|
105 | 148 | /** |
|
0 commit comments