Added new OCStack Error Code for Unauthorized Req (IOT-609)
authorSachin Agrawal <sachin.agrawal@intel.com>
Thu, 16 Jul 2015 05:28:30 +0000 (22:28 -0700)
committerErich Keane <erich.keane@intel.com>
Thu, 16 Jul 2015 18:06:55 +0000 (18:06 +0000)
A Server can deny a REST request from a Client if
'Access Control List' does not authorize the request.
Server returns CoAP 401 error code to Client originating the
request. RI layer at client incorrectly translates it to
OC_STACK_ERROR which does not provide specific failure reason
to Client Application.

Change-Id: I127060d186a021c676c36bc6148e264bdcb60fde
Signed-off-by: Sachin Agrawal <sachin.agrawal@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1684
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/stack/include/octypes.h
resource/csdk/stack/samples/linux/SimpleClientServer/common.cpp
resource/csdk/stack/samples/linux/secure/common.cpp
resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp
resource/csdk/stack/src/ocstack.c
resource/include/StringConstants.h
resource/src/OCException.cpp
resource/unittests/OCExceptionTest.cpp

index cd4c13b..3ff3933 100644 (file)
@@ -373,6 +373,7 @@ typedef enum
     OC_STACK_INVALID_REQUEST_HANDLE,
     OC_STACK_INVALID_DEVICE_INFO,
     OC_STACK_INVALID_JSON,
+    OC_STACK_UNAUTHORIZED_REQ,          /**< Request is not authorized by Resource Server. */
     /* NOTE: Insert all new error codes here!*/
     #ifdef WITH_PRESENCE
     OC_STACK_PRESENCE_STOPPED = 128,
index 0ea86ae..3ebf005 100644 (file)
@@ -60,6 +60,8 @@ const char *getResult(OCStackResult result)
             return "OC_STACK_SLOW_RESOURCE";
         case OC_STACK_NO_OBSERVERS:
             return "OC_STACK_NO_OBSERVERS";
+        case OC_STACK_UNAUTHORIZED_REQ:
+            return "OC_STACK_UNAUTHORIZED_REQ";
 #ifdef WITH_PRESENCE
         case OC_STACK_PRESENCE_STOPPED:
             return "OC_STACK_PRESENCE_STOPPED";
index 8137da0..6eb7521 100644 (file)
@@ -64,6 +64,8 @@ const char *getResult(OCStackResult result) {
         return "OC_STACK_SLOW_RESOURCE";
     case OC_STACK_NO_OBSERVERS:
         return "OC_STACK_NO_OBSERVERS";
+    case OC_STACK_UNAUTHORIZED_REQ:
+        return "OC_STACK_UNAUTHORIZED_REQ";
     #ifdef WITH_PRESENCE
     case OC_STACK_PRESENCE_STOPPED:
         return "OC_STACK_PRESENCE_STOPPED";
index 1cde32b..92dbfdf 100644 (file)
@@ -122,6 +122,7 @@ OCStackApplicationResult putReqCB(void* ctx, OCDoHandle handle, OCClientResponse
 
     if(clientResponse)
     {
+        OC_LOG_V(INFO, TAG, "StackResult: %s",  getResult(clientResponse->result));
         OC_LOG_PAYLOAD(INFO, TAG, clientResponse->payload);
         OC_LOG(INFO, TAG, PCF("=============> Put Response"));
     }
index 0714b53..ab31608 100644 (file)
@@ -563,6 +563,9 @@ OCStackResult CAToOCStackResult(CAResponseResult_t caCode)
         case CA_BAD_REQ:
             ret = OC_STACK_INVALID_QUERY;
             break;
+        case CA_UNAUTHORIZED_REQ:
+            ret = OC_STACK_UNAUTHORIZED_REQ;
+            break;
         case CA_BAD_OPT:
             ret = OC_STACK_INVALID_OPTION;
             break;
@@ -605,6 +608,9 @@ CAResponseResult_t OCToCAStackResult(OCStackResult ocCode)
         case OC_STACK_COMM_ERROR:
             ret = CA_RETRANSMIT_TIMEOUT;
             break;
+        case OC_STACK_UNAUTHORIZED_REQ:
+            ret = CA_UNAUTHORIZED_REQ;
+            break;
         default:
             break;
     }
index 3c1588b..b7b0a62 100644 (file)
@@ -104,6 +104,7 @@ namespace OC
         static const char INVALID_JSON_TYPE_TAG[]      = "Invalid JSON Type Tag";
         static const char INVALID_ATTRIBUTE[]          = "Invalid Attribute: ";
         static const char INVALID_DEVICE_INFO[]        = "Invalid Device Information";
+        static const char UNAUTHORIZED_REQUEST[]       = "Unauthorized Request";
 
     }
 
index af90961..76893f1 100644 (file)
@@ -95,6 +95,8 @@ std::string OC::OCException::reason(const OCStackResult sr)
             return OC::Exception::INVALID_DEVICE_INFO;
         case OC_STACK_INVALID_JSON:
             return OC::Exception::INVALID_REPRESENTATION;
+        case OC_STACK_UNAUTHORIZED_REQ:
+            return OC::Exception::UNAUTHORIZED_REQUEST;
     }
 
     return OC::Exception::UNKNOWN_ERROR;
index 7ab265c..0c71f02 100644 (file)
@@ -63,6 +63,7 @@ namespace OC
                 OC_STACK_INVALID_REQUEST_HANDLE,
                 OC_STACK_INVALID_DEVICE_INFO,
                 OC_STACK_INVALID_JSON,
+                OC_STACK_UNAUTHORIZED_REQ,
                 OC_STACK_PRESENCE_STOPPED,
                 OC_STACK_PRESENCE_TIMEOUT,
                 OC_STACK_PRESENCE_DO_NOT_HANDLE,
@@ -101,6 +102,7 @@ namespace OC
                 OC::Exception::INVALID_REQUEST_HANDLE,
                 OC::Exception::INVALID_DEVICE_INFO,
                 OC::Exception::INVALID_REPRESENTATION,
+                OC::Exception::UNAUTHORIZED_REQUEST,
                 OC::Exception::PRESENCE_STOPPED,
                 OC::Exception::PRESENCE_TIMEOUT,
                 OC::Exception::PRESENCE_NOT_HANDLED,