Update Deprecated Usage
Issue gh-3834
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.security.ldap;
|
||||
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
@@ -29,7 +30,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -60,7 +60,8 @@ public class SpringSecurityLdapTemplateTests {
|
||||
String searchResultName = "ldap://example.com/dc=springframework,dc=org";
|
||||
Object[] params = new Object[] {};
|
||||
DirContextAdapter searchResultObject = mock(DirContextAdapter.class);
|
||||
given(this.ctx.search(any(DistinguishedName.class), eq(filter), eq(params), this.searchControls.capture()))
|
||||
given(this.ctx.getNameInNamespace()).willReturn("dc=springframework,dc=org");
|
||||
given(this.ctx.search(any(Name.class), eq(filter), eq(params), this.searchControls.capture()))
|
||||
.willReturn(this.resultsEnum);
|
||||
given(this.resultsEnum.hasMore()).willReturn(true, false);
|
||||
given(this.resultsEnum.next()).willReturn(this.searchResult);
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.ldap.core.DirContextAdapter;
|
||||
import org.springframework.ldap.core.DistinguishedName;
|
||||
import org.springframework.ldap.support.LdapNameBuilder;
|
||||
import org.springframework.security.authentication.AccountExpiredException;
|
||||
import org.springframework.security.authentication.BadCredentialsException;
|
||||
import org.springframework.security.authentication.CredentialsExpiredException;
|
||||
@@ -118,8 +118,7 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
customProvider.contextFactory = createContextFactoryReturning(ctx);
|
||||
Authentication result = customProvider.authenticate(this.joe);
|
||||
assertThat(result.isAuthenticated()).isTrue();
|
||||
verify(ctx).search(any(DistinguishedName.class), eq(defaultSearchFilter), any(Object[].class),
|
||||
any(SearchControls.class));
|
||||
verify(ctx).search(any(Name.class), eq(defaultSearchFilter), any(Object[].class), any(SearchControls.class));
|
||||
}
|
||||
|
||||
// SEC-2897,SEC-2224
|
||||
@@ -158,8 +157,8 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
given(ctx.getNameInNamespace()).willReturn("");
|
||||
DirContextAdapter dca = new DirContextAdapter();
|
||||
SearchResult sr = new SearchResult("CN=Joe Jannsen,CN=Users", dca, dca.getAttributes());
|
||||
given(ctx.search(eq(new DistinguishedName("DC=mydomain,DC=eu")), any(String.class), any(Object[].class),
|
||||
any(SearchControls.class)))
|
||||
given(ctx.search(eq(LdapNameBuilder.newInstance("DC=mydomain,DC=eu").build()), any(String.class),
|
||||
any(Object[].class), any(SearchControls.class)))
|
||||
.willReturn(new MockNamingEnumeration(sr));
|
||||
this.provider.contextFactory = createContextFactoryReturning(ctx);
|
||||
assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(() -> this.provider.authenticate(this.joe));
|
||||
@@ -363,7 +362,7 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
DirContextAdapter dca = new DirContextAdapter();
|
||||
SearchResult sr = new SearchResult("CN=Joe Jannsen,CN=Users", dca, dca.getAttributes());
|
||||
@SuppressWarnings("deprecation")
|
||||
DistinguishedName searchBaseDn = new DistinguishedName(rootDn);
|
||||
Name searchBaseDn = LdapNameBuilder.newInstance(rootDn).build();
|
||||
given(ctx.search(eq(searchBaseDn), any(String.class), any(Object[].class), any(SearchControls.class)))
|
||||
.willReturn(new MockNamingEnumeration(sr))
|
||||
.willReturn(new MockNamingEnumeration(sr));
|
||||
|
||||
Reference in New Issue
Block a user