/** * 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"); }
public void testTestConnectionWithUserFilter() throws Exception { if(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)) { setupPanel(null, USER_FILTER, USER_FORMAT); checkSuccessfulConnection(); } }
public void testTestConnectionFailedWithUserFilter() throws Exception { if(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)) { setupPanel(null, USER_FILTER, USER_FORMAT); 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(); }
@Test public void testGetRolesForUserUsingUserFilter() throws Exception { Assume.assumeTrue( LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath, "data2.ldif")); checkUserRoles("admin", true); }
@Test public void testTestConnectionWitUserGroupService() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(USER_DN_PATTERN, null, null, "default"); testSuccessfulConnection(); }
@Test public void testTestConnectionWithUserFilter() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(null, USER_FILTER, USER_FORMAT, null); testSuccessfulConnection(); }
@Test public void testTestConnectionWithDnLookup() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(USER_DN_PATTERN, null, null, null); testSuccessfulConnection(); }
@Test public void testGetUserNamesForRoleUsingUserFilter() throws Exception { Assume.assumeTrue( LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath, "data2.ldif")); checkUserNamesForRole("admin", 1, true); checkUserNamesForRole("other", 2, true); }
@Test public void testDataLoadedFromConfigurationWithAuthentication() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(true, true); checkBaseConfig(); tester.assertModelValue("form:panel:authenticationPanelContainer:authenticationPanel:user", AUTH_USER); tester.assertModelValue("form:panel:authenticationPanelContainer:authenticationPanel:password", AUTH_PASSWORD); }
@Test public void testRequiredFields() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(false, false); tester.newFormTester("form").submit(); tester.assertErrorMessages( (Serializable[]) new String[] { "Field 'Server URL' is required.", "Field 'Group search base' is required." }); }
@Test public void testDataLoadedFromConfigurationWithoutAuthentication() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(false, true); checkBaseConfig(); assertNull(tester.getComponentFromLastRenderedPage("form:panel:authenticationPanelContainer:authenticationPanel:user")); assertNull(tester.getComponentFromLastRenderedPage("form:panel:authenticationPanelContainer:authenticationPanel:password")); }
@Test public void testAuthenticationDisabled() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(false, true); tester.assertInvisible("form:panel:authenticationPanelContainer:authenticationPanel"); tester.newFormTester("form").setValue("panel:bindBeforeGroupSearch", "on"); tester.executeAjaxEvent("form:panel:bindBeforeGroupSearch","onclick"); tester.assertVisible("form:panel:authenticationPanelContainer:authenticationPanel"); }
@Test public void testAuthenticationDisabled() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(false, true); tester.assertInvisible("form:panel:authenticationPanelContainer:authenticationPanel"); tester.newFormTester("form").setValue("panel:bindBeforeGroupSearch", "on"); tester.executeAjaxEvent("form:panel:bindBeforeGroupSearch", "click"); tester.assertVisible("form:panel:authenticationPanelContainer:authenticationPanel"); }
@Before public void createUserGroupService() throws Exception { config.setGroupNameAttribute("cn"); config.setUserSearchBase("ou=People"); config.setUserNameAttribute("uid"); config.setGroupSearchFilter("member={1},dc=example,dc=com"); ((LDAPUserGroupServiceConfig) config) .setPopulatedAttributes("sn, givenName, telephoneNumber, mail"); service = new LDAPUserGroupService(config); Assume.assumeTrue( LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath, "data4.ldif")); }
@Test public void testDataLoadedFromConfigurationWithoutAuthentication() throws Exception { Assume.assumeTrue(LDAPTestUtils.initLdapServer(true, ldapServerUrl, basePath)); setupPanel(false, true); checkBaseConfig(); assertNull( tester.getComponentFromLastRenderedPage( "form:panel:authenticationPanelContainer:authenticationPanel:user")); assertNull( tester.getComponentFromLastRenderedPage( "form:panel:authenticationPanelContainer:authenticationPanel:password")); }