use of org.apereo.portal.groups.pags.PagsGroup in project uPortal by Jasig.
the class EntityPersonAttributesGroupStore method contains.
@Override
public boolean contains(IEntityGroup group, IGroupMember member) {
if (!IPERSON_CLASS.equals(member.getLeafType())) {
// group.getLeafType() is (presumably) IPerson.class.
return false;
}
if (member.isGroup()) {
// PAGS groups may only contain other PAGS groups (and people, of course)
final IEntityGroup ieg = (IEntityGroup) member;
if (!PagsService.SERVICE_NAME_PAGS.equals(ieg.getServiceName().toString())) {
return false;
}
}
final MembershipCacheKey cacheKey = new MembershipCacheKey(group.getEntityIdentifier(), member.getUnderlyingEntityIdentifier());
Element element = membershipCache.get(cacheKey);
if (element == null) {
logger.debug("Checking if group {} contains member {}/{}", group.getName(), member.getKey(), member.getLeafType().getSimpleName());
// default
boolean answer = false;
final PagsGroup groupDef = convertEntityToGroupDef(group);
if (member.isGroup()) {
final String key = ((IEntityGroup) member).getLocalKey();
answer = groupDef.hasMember(key);
} else {
try {
final IPersonAttributeDao pa = PersonAttributeDaoLocator.getPersonAttributeDao();
final IPersonAttributes personAttributes = pa.getPerson(member.getKey());
if (personAttributes != null) {
final RestrictedPerson rp = PersonFactory.createRestrictedPerson();
rp.setAttributes(personAttributes.getAttributes());
answer = groupDef.contains(rp);
}
} catch (Exception ex) {
logger.error("Exception acquiring attributes for member " + member + " while checking if group " + group + " contains this member.", ex);
return false;
}
}
element = new Element(cacheKey, answer);
membershipCache.put(element);
}
return (Boolean) element.getObjectValue();
}
use of org.apereo.portal.groups.pags.PagsGroup in project uPortal by Jasig.
the class EntityPersonAttributesGroupStore method initGroupDef.
private PagsGroup initGroupDef(IPersonAttributesGroupDefinition group) {
Element element = this.pagsGroupCache.get(group.getName());
if (element != null) {
return (PagsGroup) element.getObjectValue();
}
PagsGroup groupDef = new PagsGroup();
groupDef.setKey(group.getName());
groupDef.setName(group.getName());
groupDef.setDescription(group.getDescription());
addMemberKeys(groupDef, group.getMembers());
Set<IPersonAttributesGroupTestGroupDefinition> testGroups = group.getTestGroups();
for (IPersonAttributesGroupTestGroupDefinition testGroup : testGroups) {
TestGroup tg = new TestGroup();
Set<IPersonAttributesGroupTestDefinition> tests = testGroup.getTests();
for (IPersonAttributesGroupTestDefinition test : tests) {
IPersonTester testerInst = initializeTester(test);
if (testerInst == null) {
/*
* A tester was intended that we cannot now recreate. This
* is a potentially dangerous situation, since tests in PAGS
* are "or-ed" together; a functioning group with a missing
* test would have a wider membership, not narrower. (And
* remember -- permissions are tied to groups.) We need to
* play it safe and keep this group out of the mix.
*/
return null;
}
tg.addTest(testerInst);
}
groupDef.addTestGroup(tg);
}
element = new Element(group.getName(), groupDef);
this.pagsGroupCache.put(element);
return groupDef;
}
use of org.apereo.portal.groups.pags.PagsGroup in project uPortal by Jasig.
the class EntityPersonAttributesGroupStore method findMemberGroupKeys.
@Override
public String[] findMemberGroupKeys(IEntityGroup group) throws GroupsException {
List<String> keys = new ArrayList<String>();
PagsGroup groupDef = convertEntityToGroupDef(// Will prevent wasting time on non-PAGS groups, if those calls even happen
group);
if (groupDef != null) {
for (Iterator<String> i = groupDef.getMembers().iterator(); i.hasNext(); ) {
keys.add(i.next());
}
}
return keys.toArray(new String[] {});
}
Aggregations