Skip to content

Commit 2d29201

Browse files
authored
Merge pull request #9597 from IQSS/9369-shib-subgroup
9369 Shib groups (and other custom groups), as subgroups of an explicit group
2 parents 746c448 + ee27329 commit 2d29201

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

src/main/java/edu/harvard/iq/dataverse/authorization/groups/GroupServiceBean.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup;
88
import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider;
99
import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean;
10+
import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroup;
1011
import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider;
1112
import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupsServiceBean;
13+
import edu.harvard.iq.dataverse.authorization.groups.impl.maildomain.MailDomainGroup;
1214
import edu.harvard.iq.dataverse.authorization.groups.impl.maildomain.MailDomainGroupProvider;
1315
import edu.harvard.iq.dataverse.authorization.groups.impl.maildomain.MailDomainGroupServiceBean;
16+
import edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroup;
1417
import edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroupProvider;
1518
import edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroupServiceBean;
1619
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
@@ -97,9 +100,49 @@ public MailDomainGroupProvider getMailDomainGroupProvider() {
97100
* @return The groups {@code req} is part of under {@code dvo}.
98101
*/
99102
public Set<Group> groupsFor( DataverseRequest req, DvObject dvo ) {
100-
return groupProviders.values().stream()
103+
Set<Group> ret = groupProviders.values().stream()
101104
.flatMap(gp->(Stream<Group>)gp.groupsFor(req, dvo).stream())
102105
.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;
103146
}
104147

105148
/**

src/main/java/edu/harvard/iq/dataverse/authorization/groups/impl/explicit/ExplicitGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
@NamedQuery( name="ExplicitGroup.findByAuthenticatedUserIdentifier",
6262
query="SELECT eg FROM ExplicitGroup eg JOIN eg.containedAuthenticatedUsers au "
6363
+ "WHERE au.userIdentifier=:authenticatedUserIdentifier"),
64-
@NamedQuery( name="ExplicitGroup.findByRoleAssgineeIdentifier",
64+
@NamedQuery( name="ExplicitGroup.findByRoleAssigneeIdentifier",
6565
query="SELECT eg FROM ExplicitGroup eg JOIN eg.containedRoleAssignees cra "
6666
+ "WHERE cra=:roleAssigneeIdentifier"),
6767
@NamedQuery( name="ExplicitGroup.findByContainedExplicitGroupId",

src/main/java/edu/harvard/iq/dataverse/authorization/groups/impl/explicit/ExplicitGroupServiceBean.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public Set<ExplicitGroup> findDirectlyContainingGroups( RoleAssignee ra ) {
169169
} else {
170170
return provider.updateProvider(
171171
new HashSet<>(
172-
em.createNamedQuery("ExplicitGroup.findByRoleAssgineeIdentifier", ExplicitGroup.class)
172+
em.createNamedQuery("ExplicitGroup.findByRoleAssigneeIdentifier", ExplicitGroup.class)
173173
.setParameter("roleAssigneeIdentifier", ra.getIdentifier())
174174
.getResultList()
175175
));
@@ -198,7 +198,7 @@ public Set<ExplicitGroup> findGroups( RoleAssignee ra, DvObject o ) {
198198
.filter( g -> g.owner.isAncestorOf(o) )
199199
.collect( Collectors.toSet() );
200200
}
201-
201+
202202
/**
203203
* Finds all the groups {@code ra} directly belongs to in the context of {@code o}. In effect,
204204
* collects all the groups {@code ra} belongs to and that are defined at {@code o}
@@ -252,7 +252,7 @@ public Set<ExplicitGroup> findDirectGroups( RoleAssignee ra, DvObject o ) {
252252
* @param seed the initial set of groups.
253253
* @return Transitive closure (based on group containment) of the groups in {@code seed}.
254254
*/
255-
protected Set<ExplicitGroup> findClosure( Set<ExplicitGroup> seed ) {
255+
public Set<ExplicitGroup> findClosure( Set<ExplicitGroup> seed ) {
256256

257257
if ( seed.isEmpty() ) return Collections.emptySet();
258258

src/main/java/edu/harvard/iq/dataverse/authorization/groups/impl/shib/ShibGroup.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,4 @@ public RoleAssigneeDisplayInfo getDisplayInfo() {
135135
public boolean contains(DataverseRequest aRequest) {
136136
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
137137
}
138-
139138
}

0 commit comments

Comments
 (0)