Skip to content

Commit c17059a

Browse files
authored
Open authentication popup window when in a web browser (#292)
An authentication popup window is displayed when an endpoint requiring authenication is accessed from a web browser.
1 parent 0ec8e8b commit c17059a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
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.InsufficientAuthenticationException;
1314
import org.springframework.security.authentication.InternalAuthenticationServiceException;
1415
import org.springframework.security.core.AuthenticationException;
1516
import org.springframework.security.web.AuthenticationEntryPoint;
@@ -24,8 +25,11 @@ public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint
2425
@Override
2526
public void commence(HttpServletRequest request, HttpServletResponse response,
2627
AuthenticationException authException) throws IOException, ServletException {
27-
if (authException instanceof BadCredentialsException) {
28+
if (authException instanceof BadCredentialsException ||
29+
authException instanceof InsufficientAuthenticationException) {
2830
LOGGER.warn("Bad Credentials {}", HttpStatus.UNAUTHORIZED);
31+
// Ensure pop-up window is opened when request comes from a web browser.
32+
response.setHeader("WWW-Authenticate", "Basic");
2933
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid credentials");
3034
}
3135
else if (authException instanceof InternalAuthenticationServiceException) {

0 commit comments

Comments
 (0)