Search in sources :

Example 1 with PagsGroup

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();
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) PagsGroup(org.apereo.portal.groups.pags.PagsGroup) IPersonAttributes(org.jasig.services.persondir.IPersonAttributes) IPersonAttributeDao(org.jasig.services.persondir.IPersonAttributeDao) Element(net.sf.ehcache.Element) RestrictedPerson(org.apereo.portal.security.provider.RestrictedPerson) GroupsException(org.apereo.portal.groups.GroupsException)

Example 2 with PagsGroup

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;
}
Also used : PagsGroup(org.apereo.portal.groups.pags.PagsGroup) IPersonTester(org.apereo.portal.groups.pags.IPersonTester) Element(net.sf.ehcache.Element) TestGroup(org.apereo.portal.groups.pags.TestGroup)

Example 3 with PagsGroup

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[] {});
}
Also used : PagsGroup(org.apereo.portal.groups.pags.PagsGroup) ArrayList(java.util.ArrayList)

Aggregations

PagsGroup (org.apereo.portal.groups.pags.PagsGroup)3 Element (net.sf.ehcache.Element)2 ArrayList (java.util.ArrayList)1 GroupsException (org.apereo.portal.groups.GroupsException)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 IPersonTester (org.apereo.portal.groups.pags.IPersonTester)1 TestGroup (org.apereo.portal.groups.pags.TestGroup)1 RestrictedPerson (org.apereo.portal.security.provider.RestrictedPerson)1 IPersonAttributeDao (org.jasig.services.persondir.IPersonAttributeDao)1 IPersonAttributes (org.jasig.services.persondir.IPersonAttributes)1