@Test public void testMyLdifFileWasLoaded() throws Exception { LdapTemplate t = new LdapTemplate(); LdapContextSource s = new LdapContextSource(); s.setPassword(LdapConfiguration.DEFAULT_PASSWORD); s.setUserDn(LdapConfiguration.DEFAULT_BIND_DN); s.setUrl(String.format("ldap://*****:*****@SuppressWarnings("unchecked") List<String> dns = t.search( "", filter.encode(), new ContextMapper() { public Object mapFromContext(Object ctx) { DirContextAdapter context = (DirContextAdapter) ctx; return context.getDn().toString(); } }); assertEquals(2, dns.size()); assertTrue(dns.contains("dc=root")); assertTrue(dns.contains("dc=child,dc=root")); }
public static LdapContextSource contextSourceTarget() { LdapContextSource ldapContextSource = new LdapContextSource(); ldapContextSource.setUrl("ldap://Alenas-iMac:1389"); ldapContextSource.setBase("ou=metis_authentication,dc=europeana,dc=eu"); ldapContextSource.setUserDn("cn=Metis Authentication"); ldapContextSource.setPassword("secret"); return ldapContextSource; }
private LdapContextSource getLdapContextSource() throws Exception { LdapContextSource ldapContextSource = new DefaultSpringSecurityContextSource(ldapURL); ldapContextSource.setUserDn(ldapBindDN); ldapContextSource.setPassword(ldapBindPassword); ldapContextSource.setReferral(ldapReferral); ldapContextSource.setCacheEnvironmentProperties(false); ldapContextSource.setAnonymousReadOnly(false); ldapContextSource.setPooled(true); ldapContextSource.afterPropertiesSet(); return ldapContextSource; }
@Bean public LdapContextSource contextSource() { /* * We need to statically set these values, since we cannot use the * real contextSource in LdapConfig because is retrieves values * from the Play! application.conf. Play! is not running in a test * environment, so we set these here for the tests. */ LdapContextSource contextSource = new LdapContextSource(); contextSource.setUrl("ldap://localhost:389"); // contextSource.setBase("dc=example,dc=com"); contextSource.setUserDn("cn=Directory Manager"); contextSource.setPassword("password"); return contextSource; }
// @see: http://stackoverflow.com/questions/26004062/ldap-query-configuration-using-spring-boot @Bean @ConfigurationProperties(prefix = "ldap") public LdapContextSource contextSource() { LdapContextSource contextSource = new LdapContextSource(); contextSource.setUrl(this.getUrl()); contextSource.setUserDn(this.getUserOn()); contextSource.setPassword(this.getPassword()); try { contextSource.afterPropertiesSet(); } catch (Exception e) { e.printStackTrace(); } LOG.debug("LdapContextSource:" + this.toString()); // LdapContextSource contextSource = new LdapContextSource(); return contextSource; }
@Before public void setUp() throws Exception { lctxs = new LdapContextSource(); lctxs.setBase(baseDn); lctxs.setUrl(ldapUrl); lctxs.setUserDn(bindDn); lctxs.setPassword(bindPassword); lctxs.afterPropertiesSet(); ltmpl = new LdapTemplate(); ltmpl.setContextSource(lctxs); ltmpl.afterPropertiesSet(); // removing users try { ltmpl.unbind("ou=users", true); } catch (NamingException e) { } // removing roles try { ltmpl.unbind("ou=roles", true); } catch (NamingException e) { } // recreating ou=users try { DirContextOperations ctx = new DirContextAdapter("ou=users"); ctx.addAttributeValue("objectClass", "top"); ctx.addAttributeValue("objectClass", "organizationalUnit"); ctx.addAttributeValue("ou", "users"); ltmpl.bind(ctx); } catch (Exception e) { } ; // recreating ou=roles try { DirContextOperations ctx = new DirContextAdapter("ou=roles"); ctx.addAttributeValue("objectClass", "top"); ctx.addAttributeValue("objectClass", "organizationalUnit"); ctx.addAttributeValue("ou", "roles"); ltmpl.bind(ctx); } catch (Exception e) { } ; }
@Before public void setUp() throws Exception { // Bind to the directory LdapContextSource contextSource = new LdapContextSource(); contextSource.setUrl("ldap://127.0.0.1:" + PORT); contextSource.setUserDn(""); contextSource.setPassword(""); contextSource.setPooled(false); contextSource.afterPropertiesSet(); // Create the Sprint LDAP template LdapTemplate template = new LdapTemplate(contextSource); // Clear out any old data - and load the test data LdapTestUtils.cleanAndSetup( template.getContextSource(), baseName, new ClassPathResource("testdata.ldif")); }