Skip to content

Commit 0ec8e8b

Browse files
authored
Service responds HTTP status 504 in case of LDAP timeout (#289)
* Service responds HTTP status 504 in case of LDAP timeout
1 parent b6f644f commit 0ec8e8b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

publish-service/src/main/java/com/ericsson/eiffel/remrem/publish/config/CustomAuthenticationEntryPoint.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.slf4j.LoggerFactory;
1111
import org.springframework.http.HttpStatus;
1212
import org.springframework.security.authentication.BadCredentialsException;
13+
import org.springframework.security.authentication.InternalAuthenticationServiceException;
1314
import org.springframework.security.core.AuthenticationException;
1415
import org.springframework.security.web.AuthenticationEntryPoint;
1516
import org.springframework.stereotype.Component;
@@ -27,5 +28,17 @@ public void commence(HttpServletRequest request, HttpServletResponse response,
2728
LOGGER.warn("Bad Credentials {}", HttpStatus.UNAUTHORIZED);
2829
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid credentials");
2930
}
31+
else if (authException instanceof InternalAuthenticationServiceException) {
32+
Throwable cause = authException.getCause();
33+
if (cause instanceof org.springframework.ldap.CommunicationException communicationException) {
34+
cause = communicationException.getCause();
35+
if (cause instanceof javax.naming.CommunicationException namingCommunicationException) {
36+
String message = namingCommunicationException.toString();
37+
LOGGER.warn("Communication problem: {}; {}", HttpStatus.GATEWAY_TIMEOUT, message);
38+
response.sendError(HttpServletResponse.SC_GATEWAY_TIMEOUT, message);
39+
response.flushBuffer();
40+
}
41+
}
42+
}
3043
}
3144
}

0 commit comments

Comments
 (0)