082deae3 by Adam Heath

Unwrap nested ServiceAuthExceptions(this happens when one service calls

another and the inner call fails authentication).

Refs: #7817
1 parent d58580c3
......@@ -73,6 +73,7 @@ import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
import org.ofbiz.service.ServiceAuthException;
......@@ -245,13 +246,23 @@ public class DirectControlServlet extends HttpServlet {
tmpOut.close();
try {
try {
processRequest();
} catch (GenericServiceException e) {
Throwable cause = e;
while ((cause = cause.getCause()) != null) {
if (cause instanceof ServiceAuthException) {
throw (ServiceAuthException) cause;
}
}
throw e;
}
} catch (IOException e) {
throw e;
} catch (ServiceAuthException e) {
e.printStackTrace();
Debug.logError(e, "ServiceAuthException", module);
response.setStatus(401);
Debug.logError(e, "ServiceAuthException(setting status to 401)", module);
response.sendError(401, e.getMessage());
setResponseNoCache();
} catch (Exception e) {
e.printStackTrace();
......