search for Shiro exception in SerializationException message to improve error response to client

Change-Id: Id7925ce44ee4737c15d5c765a2bbf8de6bdeb8b0
This commit is contained in:
Axel Uhl committed 2016-05-12 13:35:56 +02:00
1 parent e3a5ab9957
commit e6ca196556
1 file changed
+5 -3
@@ -6,6 +6,7 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.server.rpc.RPCServletUtils;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.gwt.user.server.rpc.SerializationPolicy;
@@ -38,7 +39,8 @@ public abstract class ProxiedRemoteServiceServlet extends RemoteServiceServlet {
@Override
protected void doUnexpectedFailure(Throwable e) {
if (e.getCause().getClass().getName().matches("org\\.apache\\.shiro\\.authz\\..*[Aa]uth.*Exception")) {
if ((e.getCause() != null && e.getCause().getClass().getName().matches("org\\.apache\\.shiro\\.authz\\..*[Aa]uth.*Exception")) ||
(e instanceof SerializationException && e.getMessage().matches("Type 'org\\.apache\\.shiro\\.authz\\..*[Aa]uth.*Exception' was not included in the set of types which can be serialized.*"))) {
final HttpServletResponse servletResponse = getThreadLocalResponse();
try {
servletResponse.reset();
@@ -47,12 +49,12 @@ public abstract class ProxiedRemoteServiceServlet extends RemoteServiceServlet {
}
ServletContext servletContext = getServletContext();
RPCServletUtils.writeResponseForUnexpectedFailure(servletContext, servletResponse, e);
servletContext.log("Exception while dispatching incoming RPC call", e.getCause());
servletContext.log("Exception while dispatching incoming RPC call", e.getCause()==null?e:e.getCause());
try {
servletResponse.setContentType("text/plain");
servletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
try {
servletResponse.getOutputStream().write(e.getCause().getLocalizedMessage().getBytes("UTF-8"));
servletResponse.getOutputStream().write((e.getCause()==null?e:e.getCause()).getLocalizedMessage().getBytes("UTF-8"));
} catch (IllegalStateException ex) {
// Handle the (unexpected) case where getWriter() was previously used
servletResponse.getWriter().write("Couldn't write exception");