问题
Is it possible to intercept sending response to client, and send modified response in final ? I want to remove "WWW-Authenticate" header from Basic Auth response or change error code from 401 to 403 in wrong authentication case. P.S. I have the same problem: http://www.java.net/forum/topic/glassfish/glassfish/suppress-www-authenticate-header-if-basic-auth-fails
回答1:
I tried use Filter with HttpServletResponseWrapper but my Filter was never called before JAAS Basic HTTP Authentication. I solved my problems with annoying popup window by next code
In web.xml:
<error-page>
<error-code>401</error-code>
<location>/error.jsp</location>
</error-page>
error.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<%
int status = response.getStatus();
if (status == 401) {
response.setStatus(403);
}
%>
</body>
</html>
来源:https://stackoverflow.com/questions/10158877/how-to-change-response-before-send