Exception redirect too many times when try to connect servlet protected by LDAP authentication

Viewed 29

I use the below codes to make HTTP connection to a LDAP protected servlet to authenticate my user credentials.

LDAP: Definition

AuthLogin.java:

try {
    String encoding = Base64.getEncoder().encodeToString(("" + loginName + ":" + loginPassword + "").getBytes());
    String urlStr = System.WEBPATH + System.APPLICATIONCONTEXTPATH + "/AuthService";

    URL url = new URL(urlStr);

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Accept", "application/text");
    conn.setRequestProperty("Authorization", "Basic " + encoding);

    if (conn.getResponseCode() != 200) {
        log.error("LDAP authentication fail response: code: " + conn.getResponseCode() + ", message: " + conn.getResponseMessage());
    }
} catch (Exception e) {
    log.error("Exception login method response: " + e.getMessage() + ", cause: " + e.getCause() + ", redirectURL: Login.jsp");
}

Case 1

url: http://intranet-uat.com.example/foo/AuthService
210719 14:06:54:038 [] [1418960183] ERROR AuthLogin - LDAP authentication fail response: code: 302, message: Found

Case 2

url: https://intranet-uat.com.example/foo/AuthService
210719 14:31:43:728 [] [1101124779] ERROR AuthLogin - Exception login method response: Server redirected too many  times (20), cause: null, redirectURL: Login.jsp

Can someone help me understand why case 2 can have redirect exception?

0 Answers
Related