Skip to content

Open authentication popup window when in a web browser #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.InsufficientAuthenticationException;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
Expand All @@ -24,8 +25,11 @@ public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {
if (authException instanceof BadCredentialsException) {
if (authException instanceof BadCredentialsException ||
authException instanceof InsufficientAuthenticationException) {
LOGGER.warn("Bad Credentials {}", HttpStatus.UNAUTHORIZED);
// Ensure pop-up window is opened when request comes from a web browser.
response.setHeader("WWW-Authenticate", "Basic");
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid credentials");
}
else if (authException instanceof InternalAuthenticationServiceException) {
Expand Down