/** * Initializes an in-memory LDAP server to use for testing. * * @param allowAnonymous anonymous access is allowed or not */ public static boolean initLdapServer( boolean allowAnonymous, String ldapServerUrl, String basePath) throws Exception { return initLdapServer(allowAnonymous, ldapServerUrl, basePath, "data.ldif"); }
@After public void tearDown() throws Exception { tempFolder.delete(); LDAPTestUtils.shutdownEmbeddedServer(); if (SecurityContextHolder.getContext() != null) { SecurityContextHolder.getContext().setAuthentication(null); } } }
public static void cleanAndSetup( ContextSource contextSource, DistinguishedName rootNode, Resource ldifFile) throws NamingException, IOException { clearSubContexts(contextSource, rootNode); loadLdif(contextSource, ldifFile); }
throws Exception { try { if (!portIsBusy("127.0.0.1", LDAP_SERVER_PORT)) { startEmbeddedServer(LDAP_SERVER_PORT, basePath, "test", allowAnonymous); cleanAndSetup( template.getContextSource(), new DistinguishedName("dc=example,dc=com"),
if (!portIsBusy("127.0.0.1", LDAP_SERVER_PORT)) { startApacheDirectoryServer(10389, basePath, "test", LdapTestUtils.DEFAULT_PRINCIPAL, LdapTestUtils.DEFAULT_PASSWORD, allowAnonymous);
partitionConfiguration.setSuffix(defaultPartitionSuffix); partitionConfiguration .setContextEntry(getRootPartitionAttributes(defaultPartitionName)); partitionConfiguration.setName(defaultPartitionName); Hashtable<String, String> env = createEnv(principal, credentials); env.putAll(cfg.toJndiEnvironment()); return new InitialDirContext(env);
/** * Clear the directory sub-tree starting with the node represented by the supplied distinguished * name. * * @param contextSource the ContextSource to use for getting a DirContext. * @param name the distinguished name of the root node. * @throws NamingException if anything goes wrong removing the sub-tree. */ public static void clearSubContexts(ContextSource contextSource, Name name) throws NamingException { DirContext ctx = null; try { ctx = contextSource.getReadWriteContext(); clearSubContexts(ctx, name); } finally { try { ctx.close(); } catch (Exception e) { // Never mind this } } }
ctx.destroySubcontext(childName); } catch (ContextNotEmptyException e) { clearSubContexts(ctx, childName); ctx.destroySubcontext(childName);
public void testTestConnectionWithUserFilter() throws Exception { if(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)) { setupPanel(null, USER_FILTER, USER_FORMAT); checkSuccessfulConnection(); } }
@After public void tearDown() throws Exception { LDAPTestUtils.shutdownEmbeddedServer(); }
public void testTestConnectionFailedWithUserFilter() throws Exception { if(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)) { setupPanel(null, USER_FILTER, USER_FORMAT); checkFailedConnection(); } }
@After public void tearDown() throws Exception { LDAPTestUtils.shutdownEmbeddedServer(); }
public void testTestConnectionWithDnLookup() throws Exception { if(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)) { setupPanel(USER_DN_PATTERN, null, null); checkSuccessfulConnection(); } }
@After public void tearDown() throws Exception { LDAPTestUtils.shutdownEmbeddedServer(); }
public void testTestConnectionFailedWithDnLookup() throws Exception { if(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)) { setupPanel(USER_DN_PATTERN, null, null); checkFailedConnection(); } }
@Test public void testGetRoles() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); checkAllRoles(); }
@Test public void testGetRolesCount() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); checkRoleCount(); }
@Test public void testGetAdminRoles() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); checkAdminRoles(); }
/** Test that LDAPAuthenticationProvider finds roles even if there is a colon in the password */ @Test public void testColonPassword() throws Exception { Assume.assumeTrue( LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath, "data3.ldif")); ((LDAPSecurityServiceConfig) config).setUserDnPattern("uid={0},ou=People"); createAuthenticationProvider(); authentication = new UsernamePasswordAuthenticationToken("colon", "da:da"); Authentication result = authProvider.authenticate(authentication); assertEquals(2, result.getAuthorities().size()); }
@Test public void testGetRoleByName() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); checkRoleByName(); }