mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-28 06:42:49 +00:00
Changed to reject empty passwords by default.
This commit is contained in:
parent
ee50d6e334
commit
d2ee383e06
@ -110,8 +110,8 @@ public class LdapAuthenticationProvider extends AbstractUserDetailsAuthenticatio
|
|||||||
private LdapAuthenticator authenticator;
|
private LdapAuthenticator authenticator;
|
||||||
private LdapAuthoritiesPopulator authoritiesPopulator;
|
private LdapAuthoritiesPopulator authoritiesPopulator;
|
||||||
|
|
||||||
/** The provider will reject an authentication request with an empty password if this is set to "true" */
|
/** The provider will allow an authentication request with an empty password if this is true */
|
||||||
private boolean allowEmptyPasswords = true;
|
private boolean allowEmptyPasswords = false;
|
||||||
|
|
||||||
//~ Constructors ===================================================================================================
|
//~ Constructors ===================================================================================================
|
||||||
|
|
||||||
@ -136,8 +136,17 @@ public class LdapAuthenticationProvider extends AbstractUserDetailsAuthenticatio
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the provider will reject empty passwords by default.
|
* Determines whether the provider will reject empty passwords by default.
|
||||||
* This may be useful when using LDAP servers which interpret an empty password as
|
* LDAP servers may allow an anonymous bind operation with an empty password, even if
|
||||||
* anonymous access, even if a (possibly non-existent) principal is supplied.
|
* a DN is supplied. In practice this means that if the LDAP directory is configured
|
||||||
|
* to allow unauthenitcated access, it might be possible to authenticate as <i>any</i>
|
||||||
|
* user just by supplying an empty password.
|
||||||
|
* <p>
|
||||||
|
* The use of empty passwords is disabled by default and should only be allowed
|
||||||
|
* if you have a very good reason.
|
||||||
|
* More information on the misuse of unauthenticated access can be found in
|
||||||
|
* <a href="http://www.ietf.org/internet-drafts/draft-ietf-ldapbis-authmeth-19.txt">
|
||||||
|
* draft-ietf-ldapbis-authmeth-19.txt</a>
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public void setAllowEmptyPasswords(boolean allowEmptyPasswords) {
|
public void setAllowEmptyPasswords(boolean allowEmptyPasswords) {
|
||||||
this.allowEmptyPasswords = allowEmptyPasswords;
|
this.allowEmptyPasswords = allowEmptyPasswords;
|
||||||
|
@ -86,23 +86,22 @@ public class LdapAuthenticationProviderTests extends TestCase {
|
|||||||
} catch (BadCredentialsException expected) {}
|
} catch (BadCredentialsException expected) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyPasswordIsAcceptedByDefault() {
|
public void testEmptyPasswordIsRejectedByDefault() {
|
||||||
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
|
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
|
||||||
new MockAuthoritiesPopulator());
|
new MockAuthoritiesPopulator());
|
||||||
ldapProvider.retrieveUser("jen", new UsernamePasswordAuthenticationToken("jen", ""));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testEmptyPasswordIsRejectedWhenFlagIsSet() {
|
|
||||||
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
|
|
||||||
new MockAuthoritiesPopulator());
|
|
||||||
ldapProvider.setAllowEmptyPasswords(false);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ldapProvider.retrieveUser("jen", new UsernamePasswordAuthenticationToken("jen", ""));
|
ldapProvider.retrieveUser("jen", new UsernamePasswordAuthenticationToken("jen", ""));
|
||||||
fail("Expected BadCredentialsException for empty password");
|
fail("Expected BadCredentialsException for empty password");
|
||||||
} catch (BadCredentialsException expected) {}
|
} catch (BadCredentialsException expected) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testEmptyPasswordIsAcceptedWhenFlagIsSet() {
|
||||||
|
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
|
||||||
|
new MockAuthoritiesPopulator());
|
||||||
|
ldapProvider.setAllowEmptyPasswords(true);
|
||||||
|
ldapProvider.retrieveUser("jen", new UsernamePasswordAuthenticationToken("jen", ""));
|
||||||
|
}
|
||||||
|
|
||||||
public void testNormalUsage() {
|
public void testNormalUsage() {
|
||||||
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
|
LdapAuthenticationProvider ldapProvider = new LdapAuthenticationProvider(new MockAuthenticator(),
|
||||||
new MockAuthoritiesPopulator());
|
new MockAuthoritiesPopulator());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user