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; ...@@ -73,6 +73,7 @@ import org.ofbiz.entity.util.EntityUtil;
73 import org.ofbiz.entity.condition.EntityOperator; 73 import org.ofbiz.entity.condition.EntityOperator;
74 import org.ofbiz.entity.condition.EntityCondition; 74 import org.ofbiz.entity.condition.EntityCondition;
75 import org.ofbiz.service.DispatchContext; 75 import org.ofbiz.service.DispatchContext;
76 import org.ofbiz.service.GenericServiceException;
76 import org.ofbiz.service.LocalDispatcher; 77 import org.ofbiz.service.LocalDispatcher;
77 import org.ofbiz.service.ModelService; 78 import org.ofbiz.service.ModelService;
78 import org.ofbiz.service.ServiceAuthException; 79 import org.ofbiz.service.ServiceAuthException;
...@@ -245,13 +246,23 @@ public class DirectControlServlet extends HttpServlet { ...@@ -245,13 +246,23 @@ public class DirectControlServlet extends HttpServlet {
245 tmpOut.close(); 246 tmpOut.close();
246 247
247 try { 248 try {
248 processRequest(); 249 try {
250 processRequest();
251 } catch (GenericServiceException e) {
252 Throwable cause = e;
253 while ((cause = cause.getCause()) != null) {
254 if (cause instanceof ServiceAuthException) {
255 throw (ServiceAuthException) cause;
256 }
257 }
258 throw e;
259 }
249 } catch (IOException e) { 260 } catch (IOException e) {
250 throw e; 261 throw e;
251 } catch (ServiceAuthException e) { 262 } catch (ServiceAuthException e) {
252 e.printStackTrace(); 263 e.printStackTrace();
253 Debug.logError(e, "ServiceAuthException", module); 264 Debug.logError(e, "ServiceAuthException(setting status to 401)", module);
254 response.setStatus(401); 265 response.sendError(401, e.getMessage());
255 setResponseNoCache(); 266 setResponseNoCache();
256 } catch (Exception e) { 267 } catch (Exception e) {
257 e.printStackTrace(); 268 e.printStackTrace();
......