Commit 32af9585 authored by Sachin Agrawal's avatar Sachin Agrawal Committed by Erich Keane

Added new OCStack Error Code for Unauthorized Req (IOT-609)

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: default avatarSachin Agrawal <sachin.agrawal@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1684Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarSakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-by: default avatarErich Keane <erich.keane@intel.com>
parent c37642db
......@@ -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,
......
......@@ -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";
......
......@@ -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";
......
......@@ -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"));
}
......
......@@ -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;
}
......
......@@ -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";
}
......
......@@ -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;
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment