1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.match.saml;
18
19 import org.opensaml.saml2.metadata.EntitiesDescriptor;
20 import org.opensaml.saml2.metadata.EntityDescriptor;
21 import org.opensaml.xml.util.DatatypeHelper;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 import edu.internet2.middleware.shibboleth.common.attribute.filtering.provider.match.basic.AbstractMatchFunctor;
26
27
28
29
30 public abstract class AbstractEntityGroupMatchFunctor extends AbstractMatchFunctor {
31
32
33 private final Logger log = LoggerFactory.getLogger(AbstractEntityGroupMatchFunctor.class);
34
35
36 private String entityGroup;
37
38
39
40
41
42
43 public String getEntityGroup() {
44 return entityGroup;
45 }
46
47
48
49
50
51
52 public void setEntityGroup(String group) {
53 entityGroup = DatatypeHelper.safeTrimOrNullString(group);
54 }
55
56
57
58
59
60
61
62
63 protected boolean isEntityInGroup(EntityDescriptor entity) {
64 if (entityGroup == null) {
65 log.debug("No entity group specified, unable to check if entity is in group");
66 return false;
67 }
68
69 if (entity == null) {
70 log.debug("No entity metadata available, unable to check if entity is in group {}", entityGroup);
71 return false;
72 }
73
74 EntitiesDescriptor currentGroup = (EntitiesDescriptor) entity.getParent();
75 if (currentGroup == null) {
76 log.debug("Entity descriptor does not have a parent object, unable to check if entity is in group {}",
77 entityGroup);
78 return false;
79 }
80
81 do {
82 if (entityGroup.equals(currentGroup.getName())) {
83 return true;
84 }
85 currentGroup = (EntitiesDescriptor) currentGroup.getParent();
86 } while (currentGroup != null);
87
88 return false;
89 }
90 }