Search in sources :

Example 1 with IPersonTester

use of org.apereo.portal.groups.pags.IPersonTester in project uPortal by Jasig.

the class InjectAttributeRegexTesterTest method testInjectAttributeRegexTester.

@Test
public void testInjectAttributeRegexTester() throws Exception {
    IPerson newPerson = getIPerson("de3");
    Assert.assertNotNull(newPerson);
    // add matching value of Person attribute in key 2
    stringList.add(new String(randomStrings[0] + randomStrings[1] + randomStrings[0]));
    final String key4 = attributeNames[4];
    final String key5 = "ESCOUAICourant";
    newPerson.setAttribute(key1, randomStrings[0]);
    newPerson.setAttribute(key2, randomStrings[1]);
    newPerson.setAttribute(key3, stringList);
    newPerson.setAttribute(key4, null);
    newPerson.setAttribute(key5, "0450822X");
    //  test with an injected attribute not given, so like equals test.  Should return true.
    IPersonTester tester1 = new InjectAttributeRegexTester(new TestPersonAttributesGroupTestDefinition(key1, randomStrings[0]));
    // test with an injected attributes.  Should return true.
    String testValue2 = randomStrings[0] + "@" + key2 + "@.*";
    IPersonTester tester2 = new InjectAttributeRegexTester(new TestPersonAttributesGroupTestDefinition(key3, testValue2));
    // test an injected attributes that doesn't exist.  Should return false.
    String testValue3 = randomStrings[0] + "@" + missingKey + "@.*";
    IPersonTester tester3 = new InjectAttributeRegexTester(new TestPersonAttributesGroupTestDefinition(key3, testValue3));
    //  test an injected attribute with same String.  Should return true.
    String testValue4 = ".*@" + key2 + "@.*";
    IPersonTester tester4 = new InjectAttributeRegexTester(new TestPersonAttributesGroupTestDefinition(key2, testValue4));
    // test an injected attribute with different String.  Should return false.
    String testValue5 = ".*@" + key2 + "@.*";
    IPersonTester tester5 = new InjectAttributeRegexTester(new TestPersonAttributesGroupTestDefinition(key1, testValue5));
    // test value on null user attribute value.  Should return false.
    String testValue6 = ".*@" + key2 + "@.*";
    IPersonTester tester6 = new InjectAttributeRegexTester(new TestPersonAttributesGroupTestDefinition(key4, testValue6));
    Assert.assertTrue(tester1.test(newPerson));
    Assert.assertTrue(tester2.test(newPerson));
    Assert.assertFalse(tester3.test(newPerson));
    Assert.assertTrue(tester4.test(newPerson));
    Assert.assertFalse(tester5.test(newPerson));
    Assert.assertFalse(tester6.test(newPerson));
}
Also used : IPerson(org.apereo.portal.security.IPerson) IPersonTester(org.apereo.portal.groups.pags.IPersonTester) TestPersonAttributesGroupTestDefinition(org.apereo.portal.groups.pags.TestPersonAttributesGroupTestDefinition) Test(org.junit.Test)

Example 2 with IPersonTester

use of org.apereo.portal.groups.pags.IPersonTester 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)

Aggregations

IPersonTester (org.apereo.portal.groups.pags.IPersonTester)2 Element (net.sf.ehcache.Element)1 PagsGroup (org.apereo.portal.groups.pags.PagsGroup)1 TestGroup (org.apereo.portal.groups.pags.TestGroup)1 TestPersonAttributesGroupTestDefinition (org.apereo.portal.groups.pags.TestPersonAttributesGroupTestDefinition)1 IPerson (org.apereo.portal.security.IPerson)1 Test (org.junit.Test)1