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; } };
logger.debug("Found DN: " + dca.getDn());
logger.debug("Found DN: " + dca.getDn());
record.put(DN_KEY, new String[]{adapter.getDn().toString()}); String mailAttr = configureMailAttribute(username, record); ExtendedLdapUserImpl result = new ExtendedLdapUserImpl(ldapUserDetails, record);
/** * This method depends on a DirObjectFactory ( * {@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) * being set in the ContextSource. */ @Test public void testLookupContextRoot() { DirContextAdapter result = (DirContextAdapter) tested.lookup(""); assertThat(result.getDn().toString()).isEqualTo(""); assertThat(result.getNameInNamespace()).isEqualTo(base); }
@Test public void testGetDn_BasePath() { DirContextAdapter tested = new DirContextAdapter(null, DUMMY_NAME, BASE_NAME); Name result = tested.getDn(); assertThat(result).isEqualTo(DUMMY_NAME); }
@Test public void testGetDn() throws Exception { DirContextAdapter tested = new DirContextAdapter(DUMMY_NAME); Name result = tested.getDn(); assertThat(result).isEqualTo(DUMMY_NAME); }
@Test @Category(NoAdTest.class) public void testLookup_GetNameInNamespace_MultiRdn() { DirContextAdapter result = (DirContextAdapter) tested.lookup("cn=Some Person+sn=Person,ou=company1,ou=Norway"); assertThat(result.getDn().toString()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway"); assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base); } }
@Test public void testGetObjectInstance() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(contextMock, DN, null, new Hashtable(), expectedAttributes); verify(contextMock).close(); assertThat(adapter.getDn()).isEqualTo(DN); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }
@Test public void testStringConstructor() { DirContextAdapter tested = new DirContextAdapter("cn=john doe, ou=company"); assertThat(tested.getDn()).isEqualTo(LdapUtils.newLdapName("cn=john doe, ou=company")); }
@Test public void testGetObjectInstance_nullObject() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(null, DN, null, new Hashtable(), expectedAttributes); assertThat(adapter.getDn()).isEqualTo(DN); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }
@Test public void testGetObjectInstance_ObjectNotContext() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(new Object(), DN, null, new Hashtable(), expectedAttributes); assertThat(adapter.getDn()).isEqualTo(DN); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }
@Test public void testLookup_GetNameInNamespace_Plain() { String expectedDn = "cn=Some Person2, ou=company1,ou=Sweden"; DirContextAdapter result = (DirContextAdapter) tested.lookup(expectedDn); LdapName expectedName = LdapUtils.newLdapName(expectedDn); assertThat(result.getDn()).isEqualTo(expectedName); assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person2,ou=company1,ou=Sweden," + base); } }
/** * Test for LDAP-109, since also DirContextAdapter may get an invalid * CompositeName sent to it. */ @Test public void testConstructorUsingCompositeNameWithBackslashes() throws Exception { CompositeName compositeName = new CompositeName(); compositeName.add("cn=Some\\\\Person6,ou=company1,c=Sweden"); DirContextAdapter adapter = new DirContextAdapter(compositeName); assertThat(adapter.getDn().toString()).isEqualTo("cn=Some\\\\Person6,ou=company1,c=Sweden"); }
/** * This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.support.DefaultDirObjectFactory}) * being set in the ContextSource. */ @Test public void testLookup_Plain() { String expectedDn = "cn=Some Person2, ou=company1, ou=Sweden," + base; DirContextAdapter result = (DirContextAdapter) tested.lookup(expectedDn); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person2"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); assertThat(result.getStringAttribute("description")).isEqualTo("Sweden, Company1, Some Person2"); LdapName expectedName = LdapUtils.newLdapName(expectedDn); assertThat(result.getDn()).isEqualTo(expectedName); assertThat(result.getNameInNamespace()).isEqualTo(expectedDn); }
@Test public void testGetObjectInstance_CompositeName() throws Exception { Attributes expectedAttributes = new NameAwareAttributes(); expectedAttributes.put("someAttribute", "someValue"); CompositeName name = new CompositeName(); name.add(DN_STRING); DirContextAdapter adapter = (DirContextAdapter) tested.getObjectInstance(contextMock, name, null, new Hashtable(), expectedAttributes); verify(contextMock).close(); assertThat(adapter.getDn()).isEqualTo(DN); assertThat(adapter.getAttributes()).isEqualTo(expectedAttributes); }
@Test public void testConstructAdapterFromName_OnlySlash() throws InvalidNameException { CompositeName name = new CompositeName(); name.add("ldap://localhost:389/"); DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); assertThat(result.getDn().toString()).isEqualTo(""); assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); } }
@Test public void testConstructAdapterFromName() throws InvalidNameException { CompositeName name = new CompositeName(); name.add("ldap://localhost:389/ou=People,o=JNDITutorial"); DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); assertThat(result.getDn().toString()).isEqualTo("ou=People,o=JNDITutorial"); assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); }
@Test public void testConstructAdapterFromName_Ldaps() throws InvalidNameException { CompositeName name = new CompositeName(); name.add("ldaps://localhost:389/ou=People,o=JNDITutorial"); DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); assertThat(result.getDn().toString()).isEqualTo("ou=People,o=JNDITutorial"); assertThat(result.getReferralUrl().toString()).isEqualTo("ldaps://localhost:389"); }
@Test public void testConstructAdapterFromName_EmptyName() throws InvalidNameException { CompositeName name = new CompositeName(); name.add("ldap://localhost:389"); DefaultDirObjectFactory tested = new DefaultDirObjectFactory(); DirContextAdapter result = tested.constructAdapterFromName(new BasicAttributes(), name, ""); assertThat(result.getDn().toString()).isEqualTo(""); assertThat(result.getReferralUrl().toString()).isEqualTo("ldap://localhost:389"); }