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