NIFI-12293 Standardized HTTP error response messages (#7957)

- Updated ExceptionFilter and AuthenticationFilter with standard messages

This closes #7957
This commit is contained in:
exceptionfactory 2023-11-03 09:09:47 -05:00 committed by GitHub
parent 168b3e205a
commit 97dd543c6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 18 deletions

View File

@ -49,7 +49,7 @@ public class ListenerHandleResult {
if (failureCause == null) { if (failureCause == null) {
return getDescriptor() + " successfully handled the configuration change"; return getDescriptor() + " successfully handled the configuration change";
} else { } else {
return getDescriptor() + " FAILED to handle the configuration change due to: '" + failureCause.getMessage() + "'"; return getDescriptor() + " FAILED to handle the configuration change";
} }
} }
} }

View File

@ -17,8 +17,6 @@
package org.apache.nifi.web.filter; package org.apache.nifi.web.filter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
@ -44,20 +42,12 @@ public class ExceptionFilter implements Filter {
try { try {
filterChain.doFilter(req, resp); filterChain.doFilter(req, resp);
} catch (RequestRejectedException e) { } catch (final RequestRejectedException e) {
if (logger.isDebugEnabled()) { logger.warn("Client request rejected", e);
logger.debug("An exception was caught performing the HTTP request security filter check and the stacktrace has been suppressed from the response");
}
HttpServletResponse filteredResponse = (HttpServletResponse) resp; final HttpServletResponse filteredResponse = (HttpServletResponse) resp;
filteredResponse.setStatus(500); filteredResponse.setStatus(500);
filteredResponse.getWriter().write(e.getMessage()); filteredResponse.getWriter().write("Client request rejected");
StringWriter sw = new StringWriter();
sw.write("Exception caught by ExceptionFilter:\n");
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
logger.error(sw.toString());
} }
} }

View File

@ -138,14 +138,14 @@ public abstract class NiFiAuthenticationFilter extends GenericFilterBean {
// use the type of authentication exception to determine the response code // use the type of authentication exception to determine the response code
if (ae instanceof InvalidAuthenticationException) { if (ae instanceof InvalidAuthenticationException) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
out.println(ae.getMessage()); out.println("Authentication credentials invalid");
} else if (ae instanceof UntrustedProxyException) { } else if (ae instanceof UntrustedProxyException) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setStatus(HttpServletResponse.SC_FORBIDDEN);
out.println(ae.getMessage()); out.println("Authentication Proxy Server not trusted");
} else if (ae instanceof AuthenticationServiceException) { } else if (ae instanceof AuthenticationServiceException) {
log.error("Authentication Service Failed: {}", ae.getMessage(), ae); log.error("Authentication Service Failed: {}", ae.getMessage(), ae);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
out.println(String.format("Unable to authenticate: %s", ae.getMessage())); out.println("Authentication service processing failed");
} else { } else {
log.error("Authentication Exception: {}", ae.getMessage(), ae); log.error("Authentication Exception: {}", ae.getMessage(), ae);
response.setStatus(HttpServletResponse.SC_FORBIDDEN); response.setStatus(HttpServletResponse.SC_FORBIDDEN);