Fixed issue 26566:Error returned when calling to websevices
authorGuillermo Gil <guillermo.gil@openbravo.com>
Fri, 16 May 2014 12:35:09 +0200
changeset 23051 a2b35719f45a
parent 23050 dbc986ded642
child 23053 e70995bb0b5c
child 23355 4924c096aadd
Fixed issue 26566:Error returned when calling to websevices

error is returned when a call to web service is done and the role used don't have permission to Role and User window
Added isWebServiceEnabled to OBContext
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonRestServlet.java
src/org/openbravo/dal/core/OBContext.java
src/org/openbravo/service/web/BaseWebServiceServlet.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonRestServlet.java	Fri May 16 10:44:04 2014 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonRestServlet.java	Fri May 16 12:35:09 2014 +0200
@@ -84,12 +84,12 @@
               + OBContext.getOBContext().getRole()
               + " is trying to access to non granted web service " + request.getRequestURL());
           throw new OBSecurityException("Web Services are not granted to Portal roles");
-        } else if (!OBContext.getOBContext().getRole().isWebServiceEnabled()) {
+        } else if (!OBContext.getOBContext().isWebServiceEnabled()) {
           log.error("User " + OBContext.getOBContext().getUser() + " with role "
               + OBContext.getOBContext().getRole()
               + " is trying to access to non granted web service " + request.getRequestURL());
           throw new OBSecurityException("Web Services are not granted to "
-              + OBContext.getOBContext().getRole().getName() + " role");
+              + OBContext.getOBContext().getRole() + " role");
         }
       }
       callServiceInSuper(request, response);
--- a/src/org/openbravo/dal/core/OBContext.java	Fri May 16 10:44:04 2014 +0200
+++ b/src/org/openbravo/dal/core/OBContext.java	Fri May 16 12:35:09 2014 +0200
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2008-2013 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2014 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -484,6 +484,8 @@
 
   private boolean isPortalRole = false;
 
+  private boolean isWebServiceEnabled = false;
+
   private Set<String> additionalWritableOrganizations = new HashSet<String>();
 
   // support storing the context in a persistent tomcat session
@@ -952,6 +954,7 @@
   public void setRole(Role role) {
     isAdministrator = ((String) DalUtil.getId(role)).equals("0");
     isPortalRole = role.isForPortalUsers();
+    isWebServiceEnabled = role.isWebServiceEnabled();
     setUserLevel(role.getUserLevel());
     entityAccessChecker = null;
     writableOrganizations = null;
@@ -1134,6 +1137,10 @@
     return isPortalRole;
   }
 
+  public boolean isWebServiceEnabled() {
+    return isWebServiceEnabled;
+  }
+
   public void setRTL(boolean isRTL) {
     this.isRTL = isRTL;
   }
--- a/src/org/openbravo/service/web/BaseWebServiceServlet.java	Fri May 16 10:44:04 2014 +0200
+++ b/src/org/openbravo/service/web/BaseWebServiceServlet.java	Fri May 16 12:35:09 2014 +0200
@@ -100,12 +100,12 @@
               + OBContext.getOBContext().getRole()
               + " is trying to access to non granted web service " + request.getRequestURL());
           throw new OBSecurityException("Web Services are not granted to Portal roles");
-        } else if (!OBContext.getOBContext().getRole().isWebServiceEnabled()) {
+        } else if (!OBContext.getOBContext().isWebServiceEnabled()) {
           log.error("User " + OBContext.getOBContext().getUser() + " with role "
               + OBContext.getOBContext().getRole()
               + " is trying to access to non granted web service " + request.getRequestURL());
           throw new OBSecurityException("Web Services are not granted to "
-              + OBContext.getOBContext().getRole().getName() + " role");
+              + OBContext.getOBContext().getRole() + " role");
         }
       }
       super.service(request, response);