Skip to content

Commit

Permalink
[CDAP-20840] Check for empty LDAP password
Browse files Browse the repository at this point in the history
  • Loading branch information
rmstar committed Oct 9, 2023
1 parent 550a8f3 commit e17ba25
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ protected void doStart() throws Exception {
@Override
public UserIdentity login(final String username, final Object credentials) {
try {
CallbackHandler callbackHandler = null;
if (credentials instanceof String && ((String) credentials).isEmpty()) {
throw new LoginException("Empty password");
}

CallbackHandler callbackHandler = null;
if (callbackHandlerClass == null) {
callbackHandler = new CallbackHandler() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import io.cdap.cdap.common.conf.CConfiguration;
import io.cdap.cdap.common.conf.Constants;
import io.cdap.cdap.common.conf.SConfiguration;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* Tests for {@link ExternalAuthenticationServer}.
Expand Down Expand Up @@ -72,4 +75,19 @@ protected Map<String, String> getAuthRequestHeader() {
protected String getAuthenticatedUserName() {
return "admin";
}

/**

Check warning on line 79 in cdap-security/src/test/java/io/cdap/cdap/security/server/ExternalLDAPAuthenticationServerTest.java

View workflow job for this annotation

GitHub Actions / Checkstyle

com.puppycrawl.tools.checkstyle.checks.indentation.CommentsIndentationCheck

Block comment has incorrect indentation level 2, expected is 3, indentation should be the same level as line 82.
* Test request to server with empty password
*/
@Test
public void testEmptyPassword() throws Exception {
HttpURLConnection urlConn = openConnection(getURL(GrantAccessToken.Paths.GET_TOKEN));
try {
// base64 encoding of admin: (username=admin, password=empty string)
urlConn.addRequestProperty("Authorization", "Basic YWRtaW46");
Assert.assertEquals(401, urlConn.getResponseCode());
} finally {
urlConn.disconnect();
}
}
}

0 comments on commit e17ba25

Please sign in to comment.