PersonARPEnforcer { public Person enforceARP(Person person, ARP arp) { Assert.notNull(person); if (arp == null || arp.isNoArp()) { return person; } Person newP = new Person(); if (arp.isNoAttrArp()) { return newP; } final Set<String> arpAttributeNames = arp.getAttributes().keySet(); if (CollectionUtils.containsAny(nameAttributes, arpAttributeNames)) { newP.setDisplayName(person.getDisplayName()); newP.setName(person.getName()); newP.setNickname(person.getNickname()); } if (CollectionUtils.containsAny(organizationAttributes, arpAttributeNames)) { newP.setOrganizations(person.getOrganizations()); } if (arpAttributeNames.contains(Attribute.EMAIL.name)) { newP.setEmails(person.getEmails()); } if (CollectionUtils.containsAny(idAttributes, arpAttributeNames)) { newP.setTags(person.getTags()); newP.setAccounts(person.getAccounts()); newP.setId(person.getId()); newP.setVoot_membership_role(person.getVoot_membership_role()); } return newP; }  Person enforceARP(Person person, ARP arp);  }
@Test public void allowAll() throws Exception { Person p = new Person(); ARP arp = null; Person enforced = e.enforceARP(p, arp); assertThat(enforced, equalTo(p)); }
@Test public void allowNone() { Person p = initPerson(); Set<Organization> organizations = new HashSet<Organization>(); Organization org = new Organization("topSecret"); organizations.add(org); p.setOrganizations(organizations); ARP arp = new ARP(); Map<String, List<Object>> attr = new HashMap<String, List<Object>>(); arp.setAttributes(attr); Person enforced = e.enforceARP(p, arp); assertNull(enforced.getDisplayName()); assertNull(enforced.getName()); }
@Test public void nameOnly() { Person p = initPerson(); p.setEmails(Collections.singleton(new Email("foo@bar.com"))); ARP arp = new ARP(); arp.getAttributes().put("urn:mace:dir:attribute-def:displayName", Collections.<Object>singletonList("*")); Person enforced = e.enforceARP(p, arp); assertThat(enforced.getDisplayName(), equalTo("boobaa")); assertThat(enforced.getName().getFamilyName(), equalTo("baa")); assertThat(enforced.getEmails(), nullValue()); }
@Test public void id() { Person p = initPerson(); p.setId("myid"); ARP arp = new ARP(); arp.getAttributes().put("urn:oid:1.3.6.1.4.1.1076.20.40.40.1", Collections.<Object>singletonList("*")); Person enforced = e.enforceARP(p, arp); assertThat(enforced.getId(), equalTo("myid")); assertThat(enforced.getDisplayName(), nullValue()); }
@Test public void testArpWithPrefixMatchingInformation() { Person p = initPerson(); ARP arp = new ARP(); arp.getAttributes().put(PersonARPEnforcer.Attribute.UID.name, Arrays.<Object>asList("*", true)); Person enforced = e.enforceARP(p, arp); assertNull(enforced.getDisplayName()); }
@Test public void testNoArp() { Person p = new Person(); p.setDisplayName("john.doe"); ARP arp = new ARP(); arp.setNoArp(true); Person enforced = e.enforceARP(p, arp); assertEquals(p.getDisplayName(), enforced.getDisplayName()); }