public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { callback.executeWithContext(ctx, null); return null; } };
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { callback.executeWithContext(ctx, entryIdentification); return null; } }, ctx);
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { callback.executeWithContext(ctx, entryIdentification); return null; } }, ctx);
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { callback.executeWithContext(ctx, entryIdentification); return null; } }, ctx);
public Object executeWithContext(DirContext ctx) throws javax.naming.NamingException { callback.executeWithContext(ctx, entryIdentification); return null; } }, ctx);
/** * Execute authentication, if configured to do so, and then call the given callback on * authenticated context, or simply call the given callback if no authentication is needed. * * @param callback */ protected void authenticateIfNeeded(AuthenticatedLdapEntryContextCallback callback) { if (user != null && password != null) { template.authenticate(DistinguishedName.EMPTY_PATH, user, password, callback); } else { callback.executeWithContext(null, null); } }
@Test public void testAuthenticateWithErrorInCallbackShouldFail() throws Exception { when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(searchControlsRecursive(), searchResult); when(contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) .thenReturn(authenticatedContextMock); doThrow(new UncategorizedLdapException("Authentication failed")).when(entryContextCallbackMock) .executeWithContext(authenticatedContextMock, new LdapEntryIdentification( LdapUtils.newLdapName("cn=john doe,dc=jayway,dc=se"), LdapUtils.newLdapName("cn=john doe"))); boolean result = tested.authenticate(nameMock, "(ou=somevalue)", "password", entryContextCallbackMock); verify(authenticatedContextMock).close(); verify(dirContextMock).close(); assertThat(result).isFalse(); }
@Test public void testAuthenticateWithSingleUserFoundShouldBeSuccessful() throws Exception { when(contextSourceMock.getReadOnlyContext()).thenReturn(dirContextMock); Object expectedObject = new DirContextAdapter(new BasicAttributes(), LdapUtils.newLdapName("cn=john doe"), LdapUtils.newLdapName("dc=jayway, dc=se")); SearchResult searchResult = new SearchResult("", expectedObject, new BasicAttributes()); singleSearchResult(searchControlsRecursive(), searchResult); when(contextSourceMock.getContext("cn=john doe,dc=jayway,dc=se", "password")) .thenReturn(authenticatedContextMock); entryContextCallbackMock.executeWithContext(authenticatedContextMock, new LdapEntryIdentification( LdapUtils.newLdapName("cn=john doe,dc=jayway,dc=se"), LdapUtils.newLdapName("cn=john doe"))); boolean result = tested.authenticate(nameMock, "(ou=somevalue)", "password", entryContextCallbackMock); verify(authenticatedContextMock).close(); verify(dirContextMock).close(); assertThat(result).isTrue(); }