I used freakman's suggestion of creating a custom BasicAuthenticationEntryPoint class. Here is my code in case anyone else needs to do something similar:
// See https://github.com/spring-projects/spring-security/blob/3.2.x/web/src/main/java/org/springframework/security/web/authentication/www/BasicAuthenticationEntryPoint.java
public class CustomBasicAuthenticationEntryPoint extends BasicAuthenticationEntryPoint {
private static Logger logger = loggerFactory.getLogger(CustomBasicAuthenticationEntryPoint.class);
@Value("${crm.integration.sso.login.form.url}")
private String loginFormUrl;
/**
* This method is called when authentication fails.
*/
@Override
public void commence(HttpServletRequest request,
HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
String path = request.getRequestURI().substring(request.getContextPath().length());
logger.info(String.format("CustomBasicAuthenticationEntryPoint.commence() - %s", path));
if ("GET".equals(request.getMethod().toUpperCase())
&& path.startsWith("/manage")
) {
response.sendRedirect(loginFormUrl);
} else {
super.commence(request, response, authException);
}
}
}