Update Deprecated Usage

Issue gh-3834
This commit is contained in:
Josh Cummings
2024-06-17 18:05:47 -06:00
parent ef5c1a72db
commit 55895f3b08
13 changed files with 119 additions and 62 deletions

View File

@@ -159,17 +159,19 @@ public class BindAuthenticatorTests {
BindAuthenticator authenticator = new BindAuthenticator(contextSource);
authenticator.setUserDnPatterns(new String[] { "uid={0},ou=people" });
LdapContext dirContext = mock(LdapContext.class);
given(dirContext.getAttributes(any(Name.class), any())).willThrow(new javax.naming.AuthenticationException("exception"));
Name fullDn = LdapUtils.newLdapName("uid=bob,ou=people").addAll(0, contextSource.getBaseLdapPath());
given(dirContext.getAttributes(any(Name.class), any()))
.willThrow(new javax.naming.AuthenticationException("exception"));
Name fullDn = LdapUtils.prepend(LdapUtils.newLdapName("uid=bob,ou=people"), contextSource.getBaseLdapName());
given(contextSource.getContext(fullDn.toString(), (String) this.bob.getCredentials())).willReturn(dirContext);
authenticator.setAlsoHandleJavaxNamingBindExceptions(true);
assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(authenticateBob(authenticator));
authenticator.setAlsoHandleJavaxNamingBindExceptions(false);
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(authenticateBob(authenticator))
.withCauseInstanceOf(javax.naming.AuthenticationException.class);
.withCauseInstanceOf(javax.naming.AuthenticationException.class);
}
private ThrowingCallable authenticateBob(BindAuthenticator authenticator) {
return () -> authenticator.authenticate(this.bob);
}
}

View File

@@ -185,7 +185,7 @@ public class LdapUserDetailsManagerTests {
assertThatExceptionOfType(UsernameNotFoundException.class).isThrownBy(() -> this.mgr.loadUserByUsername("don"));
// Check that no authorities are left
assertThat(this.mgr.getUserAuthorities(this.mgr.usernameMapper.buildDn("don"), "don")).hasSize(0);
assertThat(this.mgr.getUserAuthorities(this.mgr.usernameMapper.buildLdapName("don"), "don")).hasSize(0);
}
@Test