public Object mapFromContext(Object ctx) { DirContextAdapter adapter = (DirContextAdapter) ctx; Map<String, String[]> record = new HashMap<String, String[]>(); for (String attributeName : attributeNames) { String[] values = adapter.getStringAttributes(attributeName); if (values == null || values.length == 0) { logger.debug("No attribute value found for '" + attributeName + "'"); } else { record.put(attributeName, values); } } record.put(DN_KEY, new String[] {adapter.getDn().toString()}); set.add(record); return null; } };
public String[] mapFromContext(Object ctx) { DirContextAdapter context = (DirContextAdapter)ctx; String[] s=context.getStringAttributes(EventProcessorImpl.ldapAttrMemberOf); return s; } }
public String[] mapFromContext(Object ctx) { DirContextAdapter context = (DirContextAdapter)ctx; String[] s=context.getStringAttributes(EventProcessorImpl.ldapAttrUniqueMember); return s; } }
public String[] mapFromContext(Object ctx) { DirContextAdapter context = (DirContextAdapter) ctx; String[] s = context.getStringAttributes("o"); return s; } }
public Object mapFromContext(Object ctx) { DirContextAdapter adapter = (DirContextAdapter) ctx; String[] values = adapter.getStringAttributes(attributeName); if (values == null || values.length == 0) { logger.debug("No attribute value found for '" + attributeName + "'"); } else { set.addAll(Arrays.asList(values)); } return null; } };
public Object mapFromContext(Object ctx) { DirContextAdapter adapter = (DirContextAdapter) ctx; String[] members = adapter.getStringAttributes("uniqueMember"); return members; } };
public Object mapFromContext(Object ctx) { DirContextAdapter adapter = (DirContextAdapter) ctx; return adapter.getStringAttributes(SUPPORTED_CONTROL); }
/** * Fetch and return all normalized companies. Note the result use cache, so does not reflect the current state of * LDAP. * * @return the companies. Key is the normalized name. */ @Override public Map<String, CompanyOrg> findAllNoCache() { final Map<String, CompanyOrg> companiesNameToDn = new HashMap<>(); for (final DirContextAdapter ldap : template.search(companyBaseDn, "objectClass=" + ORGANIZATIONAL_UNIT, (Object ctx) -> (DirContextAdapter) ctx)) { final CompanyOrg company = new CompanyOrg(ldap.getDn().toString(), ldap.getStringAttributes("ou")[0]); companiesNameToDn.put(company.getId(), company); } // Also add/replace the quarantine zone final CompanyOrg quarantine = new CompanyOrg(quarantineBaseDn, getQuarantineCompany()); quarantine.setLocked(true); companiesNameToDn.put(quarantine.getId(), quarantine); // The complete the hierarchy of companies companiesNameToDn.values().forEach(this::buildLdapName); companiesNameToDn.values().forEach(c -> this.buildHierarchy(companiesNameToDn, c)); return companiesNameToDn; }
final String name = ldap.getStringAttribute("cn"); final HashSet<String> subGroups = new HashSet<>(); for (final String memberDN : ArrayUtils.nullToEmpty(ldap.getStringAttributes(UNIQUE_MEMBER))) { if (memberDN.startsWith("uid")) {
@Test public void testGetStringAttributesNotExists() throws Exception { String s[] = tested.getStringAttributes("abc"); assertThat(s).isNull(); }
@Test public void testModifyAttributes_DirContextAdapter_MultiAttributes() { DirContextAdapter adapter = (DirContextAdapter) tested.lookup(PERSON5_DN); adapter.setAttributeValues("description", new String[] { "qwe", "123", "klytt", "kalle" }); tested.modifyAttributes(PERSON5_DN, adapter.getModificationItems()); // Verify adapter = (DirContextAdapter) tested.lookup(PERSON5_DN); List<String> attributes = Arrays.asList(adapter.getStringAttributes("description")); assertThat(attributes).hasSize(4); assertThat(attributes.contains("qwe")).isTrue(); assertThat(attributes.contains("123")).isTrue(); assertThat(attributes.contains("klytt")).isTrue(); assertThat(attributes.contains("kalle")).isTrue(); }
@Test public void testModifyAttributes_MultiValueAdd() { BasicAttribute attr = new BasicAttribute("description", "Some other description"); attr.add("Another description"); ModificationItem[] mods = new ModificationItem[1]; mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr); tested.modifyAttributes(PERSON4_DN, mods); DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN); List<String> attributes = Arrays.asList(result.getStringAttributes("description")); assertThat(attributes).hasSize(3); assertThat(attributes.contains("Some other description")).isTrue(); assertThat(attributes.contains("Another description")).isTrue(); assertThat(attributes.contains("Some description")).isTrue(); }
@Test public void testModifyAttributes_MultiValueReplace() { BasicAttribute attr = new BasicAttribute("description", "Some other description"); attr.add("Another description"); ModificationItem[] mods = new ModificationItem[1]; mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attr); tested.modifyAttributes(PERSON4_DN, mods); DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN); List<String> attributes = Arrays.asList(result.getStringAttributes("description")); assertThat(attributes).hasSize(2); assertThat(attributes.contains("Some other description")).isTrue(); assertThat(attributes.contains("Another description")).isTrue(); }
@Test public void testGetStringAttributesWhenMultiValueAttributeExists() throws Exception { final Attributes attrs = new BasicAttributes(); Attribute multi = new BasicAttribute("abc"); multi.add("123"); multi.add("234"); attrs.put(multi); class TestableDirContextAdapter extends DirContextAdapter { public TestableDirContextAdapter() { super(attrs, null); } } tested = new TestableDirContextAdapter(); String s[] = tested.getStringAttributes("abc"); assertThat(s[0]).isEqualTo("123"); assertThat(s[1]).isEqualTo("234"); assertThat(s.length).isEqualTo(2); }
/** * Test written originally to verify that duplicates are allowed on ordered * attributes, but had to be changed since Apache DS seems to disallow * duplicates even for ordered attributes. */ @Test public void testModifyAttributes_MultiValueAddDuplicateToOrdered() { BasicAttribute attr = new BasicAttribute("description", "Some other description", true); // ordered attr.add("Another description"); // Commented out duplicate to make test work for Apache DS // attr.add("Some description"); ModificationItem[] mods = new ModificationItem[1]; mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr); tested.modifyAttributes(PERSON4_DN, mods); DirContextAdapter result = (DirContextAdapter) tested.lookup(PERSON4_DN); List<String> attributes = Arrays.asList(result.getStringAttributes("description")); assertThat(attributes).hasSize(3); assertThat(attributes.contains("Some other description")).isTrue(); assertThat(attributes.contains("Another description")).isTrue(); assertThat(attributes.contains("Some description")).isTrue(); }
@Test public void testGetStringAttributesExistsEmpty() throws Exception { final Attributes attrs = new BasicAttributes(); Attribute multi = new BasicAttribute("abc"); attrs.put(multi); class TestableDirContextAdapter extends DirContextAdapter { public TestableDirContextAdapter() { super(attrs, null); } } tested = new TestableDirContextAdapter(); String s[] = tested.getStringAttributes("abc"); assertThat(s).isNotNull(); assertThat(s.length).isEqualTo(0); }
@Test public void testGetStringAttributesExistsWithInvalidType() throws Exception { final Attributes attrs = new BasicAttributes(); Attribute multi = new BasicAttribute("abc"); multi.add(new Object()); attrs.put(multi); class TestableDirContextAdapter extends DirContextAdapter { public TestableDirContextAdapter() { super(attrs, null); } } tested = new TestableDirContextAdapter(); try { tested.getStringAttributes("abc"); fail("ClassCastException expected"); } catch (IllegalArgumentException expected) { assertThat(true).isTrue(); } }