[IOT-2133] Adding missing updateIndividualAcl API
authorsaurabh.s9 <saurabh.s9@samsung.com>
Sat, 20 May 2017 09:15:43 +0000 (14:45 +0530)
committerRandeep Singh <randeep.s@samsung.com>
Sun, 21 May 2017 08:28:34 +0000 (08:28 +0000)
Change-Id: I0b2f2db077a77b586e0799ec4d2ea3551fc363ca
Signed-off-by: saurabh.s9 <saurabh.s9@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19897
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: dongik Lee <dongik.lee@samsung.com>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
12 files changed:
java/common/src/main/java/org/iotivity/base/OcCloudProvisioning.java
java/common/src/main/java/org/iotivity/base/OicSecCloudAce.java [new file with mode: 0644]
java/examples-android/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/CloudProvisioningClient.java
java/examples-android/cloudprovisioningclient/src/main/res/layout/main_activity.xml [changed mode: 0755->0644]
java/jni/JniOcCloudProvisioning.cpp
java/jni/JniOcCloudProvisioning.h
java/jni/JniOcCloudResultListener.cpp
java/jni/JniOcCloudResultListener.h
java/jni/JniOcStack.cpp
java/jni/JniOcStack.h
resource/include/OCCloudProvisioning.hpp
resource/provisioning/src/OCCloudProvisioning.cpp

index eff499b..cbe9938 100644 (file)
@@ -86,6 +86,10 @@ public class  OcCloudProvisioning {
         public void postCRLListener(int result);
     }
 
+    public interface UpdateIndividualACLListener  {
+        public void updateIndividualACLListener(int result);
+    }
+
    /**
     * Method to Request a certificate from the cloud
     * @param certificateIssueRequestListener function called by the stack on completion of request.
@@ -126,6 +130,24 @@ public class  OcCloudProvisioning {
     public native void getIndividualAclInfo(String aclId,
             GetIndividualAclInfoListener cloudAclIndividualGetInfoHandler) throws OcException;
 
+        /**
+    * Method to update Individual ACL info
+    * @param aclId ACL ID
+    * @param cloudAces List of cloud Aces for updation.
+    * @param updateIndividualACLHandler function called by the stack on completion of request.
+    * @throws OcException Indicates failure to get ACL information.
+    *                     Use OcException.GetErrorCode() for more details.
+    */
+    public void updateIndividualACL(String aclId, List<OicSecCloudAce> cloudAces,
+            UpdateIndividualACLListener updateIndividualACLHandler) throws OcException
+    {
+        this.updateIndividualACL0(aclId,
+                cloudAces.toArray(new OicSecCloudAce[cloudAces.size()]), updateIndividualACLHandler);
+    }
+
+    public native void updateIndividualACL0(String aclId, OicSecCloudAce[] aces,
+            UpdateIndividualACLListener updateIndividualACLHandler) throws OcException;
+
    /**
     * Method to get certificate revocation list
     * @param cloudGetCRLHandler function called by the stack on completion of request.
diff --git a/java/common/src/main/java/org/iotivity/base/OicSecCloudAce.java b/java/common/src/main/java/org/iotivity/base/OicSecCloudAce.java
new file mode 100644 (file)
index 0000000..dd13ff1
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ *******************************************************************
+ *
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+ */
+
+package org.iotivity.base;
+
+import java.util.List;
+public class OicSecCloudAce {
+        private String aclID;
+        private String subjectID;
+        private int stype;
+        private int permission;
+        private List<OicSecResr> resources;
+        private List<OicSecValidity> validities;
+
+        public OicSecCloudAce(String aclID, String subjectID, int stype, int permission,
+                List<OicSecResr> resources, List<OicSecValidity> validities) {
+            super();
+            this.subjectID = subjectID;
+            this.permission = permission;
+            this.resources = resources;
+            this.validities = validities;
+        }
+
+        public String getAclID() {
+            return aclID;
+        }
+
+        public String getSubjectID() {
+            return subjectID;
+        }
+
+        public void setAclID(String aclID) {
+            this.aclID = aclID;
+        }
+
+        public void setSubjectID(String subjectID) {
+            this.subjectID = subjectID;
+        }
+
+        public int getStype() {
+            return stype;
+        }
+
+        public void setStype(int stype) {
+            this.stype = stype;
+        }
+
+
+        public int getPermission() {
+            return permission;
+        }
+
+        public void setPermission(int permission) {
+            this.permission = permission;
+        }
+
+        public List<OicSecResr> getResourcesList() {
+            return resources;
+        }
+
+        public OicSecResr[] getResources() {
+            return resources.toArray(new OicSecResr[resources.size()]);
+        }
+        public void setResources(List<OicSecResr> resources) {
+            this.resources = resources;
+        }
+
+        public List<OicSecValidity> getValiditiesList() {
+            return validities;
+        }
+
+        public OicSecValidity[] getValidities() {
+            return validities.toArray(new OicSecValidity[validities.size()]);
+        }
+
+        public void setValidities(List<OicSecValidity> validities) {
+            this.validities = validities;
+        }
+}
index dcff8f7..a5ebb9c 100644 (file)
@@ -54,7 +54,7 @@ import org.iotivity.base.PlatformConfig;
 import org.iotivity.base.QualityOfService;
 import org.iotivity.base.ServiceType;
 import org.iotivity.base.examples.cloudprovisioningclient.R;
-
+import org.iotivity.base.*;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -68,6 +68,51 @@ import java.util.List;
 public class CloudProvisioningClient extends Activity implements OcAccountManager.OnPostListener {
 
     private static final String TAG = "Cloud Provisioning Client: ";
+    private List<OicSecCloudAce> generateAce(String aclid)
+    {
+        String type1 = "type1";
+        String type2 = "type2";
+        int typeLen = 2;
+        String interface1 = "interface1";
+        String interface2 = "interface2";
+        int interfaceLen = 2;
+
+
+        ArrayList<String> types = new ArrayList<String>();
+        types.add(type1);
+        types.add(type2);
+
+        ArrayList<String> interfaces = new ArrayList<String>();
+        interfaces.add(interface1);
+        interfaces.add(interface2);
+        OicSecResr res = new OicSecResr("/oic/a", "testrel", types, typeLen,interfaces, 2);
+        OicSecResr res1 =  new OicSecResr("/oic/b", "testrel", types, typeLen,interfaces, 2);
+        List<OicSecResr> resources = new ArrayList<OicSecResr>();
+        resources.add(res);
+        resources.add(res1);
+
+        List<String> recurrences = new ArrayList<String>();
+        recurrences.add("1");
+        recurrences.add("2");
+        OicSecValidity validity1 = new  OicSecValidity("1", recurrences,2);
+        OicSecValidity validity2 = new  OicSecValidity("2", recurrences,2);
+        List<OicSecValidity> validities = new ArrayList<OicSecValidity>();
+        validities.add(validity1);
+        validities.add(validity2);
+
+        OicSecCloudAce ace1 = new OicSecCloudAce(aclid,"72616E64-5069-6E44-6576-557569643030", 0,
+                31,resources, validities);
+        OicSecCloudAce ace2 = new OicSecCloudAce(aclid, "72616E64-5069-6E44-6576-557569643030", 0,
+                8, resources, validities);
+
+        List<OicSecCloudAce> aces = new ArrayList<OicSecCloudAce>();
+        aces.add(ace1);
+        aces.add(ace2);
+        logMessage("out--generate ace");
+        return aces;
+    }
+
+
     OcAccountManager.OnPostListener onSignUp = new OcAccountManager.OnPostListener() {
         @Override
             public synchronized void onPostCompleted(List<OcHeaderOption> list,
@@ -229,14 +274,14 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
         };
     private static final int BUFFER_SIZE = 1024;
     private final int REQUEST_LOGIN = 1;
-    Button signUp, signIn, signOut, getAclId, getAclInfo, requestCert, postCrl, getCrl;
+    Button signUp, signIn, signOut, getAclId, getAclInfo, requestCert, postCrl, getCrl, updateAce;
     TextView userid;
     LinearLayout lyt1, lyt2, signupLyt, signinLyt;
     // private TextView eventView;
     SharedPreferences settingPreference;
     OcCloudProvisioning ocCloudProvisioning;
-    String acl_Id;
     String createacl_Id = null;
+    String acl_Id = null;
     OcCloudProvisioning.GetAclIdByDeviceListener getAclIdByDeviceListener =
         new OcCloudProvisioning.GetAclIdByDeviceListener() {
             @Override
@@ -258,16 +303,28 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
                     Log.d(TAG, "Inside createAclIdListener ");
                     if (result == 0) {
                         createacl_Id = aclId;
+                        acl_Id = aclId;
                         logMessage("Acl Id by create aclid !!" + createacl_Id);
                     } else {
                         logMessage("Error: Acl Id by create aclid failed !!");
                     }
                 }
         };
+    OcCloudProvisioning.UpdateIndividualACLListener updateIndividualACLListener =
+        new OcCloudProvisioning.UpdateIndividualACLListener(){
+              public void updateIndividualACLListener(int result)
+              {
+                  Log.d(TAG, "Inside UpdateIndividualACLListener ");
+                  if (result == 4) {
+                      logMessage("Success UpdateIndividualACLListener");
+                  } else {
+                      logMessage("Error:UpdateIndividualACLListener = "+result);
+                  }
+              }
+    };
     private OcAccountManager mAccountManager;
     private String filePath = "";
     private TextView mEventsTextView;
-
     @Override
         protected void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
@@ -282,6 +339,7 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
             postCrl = (Button) findViewById(R.id.postCRL);
             getCrl = (Button) findViewById(R.id.getCRL);
 
+            updateAce = (Button) findViewById(R.id.updateAce);
             lyt1 = (LinearLayout) findViewById(R.id.lyt1);
             lyt2 = (LinearLayout) findViewById(R.id.lyt2);
             signupLyt = (LinearLayout) findViewById(R.id.signupLyt);
@@ -375,6 +433,12 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
                     getCrl();
                     }
                     });
+            updateAce.setOnClickListener(new View.OnClickListener() {
+                    @Override
+                    public void onClick(View v) {
+                    updateAces();
+                    }
+                    });
         }
 
 
@@ -434,6 +498,7 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
 
     private void getAclId() {
         try {
+            logMessage("getAclId");
             if(createacl_Id == null)
             {
                 ocCloudProvisioning.createAclId(settingPreference.getString("OWNERID", ""),
@@ -451,7 +516,6 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
     private void getAclInfo() {
         try {
             logMessage("getAclInfo");
-            logMessage("\taclid="+acl_Id);
             ocCloudProvisioning.getIndividualAclInfo(acl_Id, getIndividualAclInfoListener);
 
         } catch (OcException e) {
@@ -477,7 +541,8 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
             ArrayList<String> arrayList = new ArrayList<>();
             arrayList.add(settingPreference.getString("SERIALNUMBER", "1234"));
 
-            ocCloudProvisioning.postCRL("20160727000000", "20161027000000", null, arrayList, postCRLListener);
+            ocCloudProvisioning.postCRL("20160727000000", "20161027000000", null,
+                    arrayList, postCRLListener);
 
         } catch (OcException e) {
             e.printStackTrace();
@@ -494,6 +559,17 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
         }
     }
 
+    private void updateAces()
+    {
+        try {
+            logMessage("updateAce");
+            ocCloudProvisioning.updateIndividualACL(acl_Id, generateAce(acl_Id),
+                    updateIndividualACLListener);
+
+        } catch (OcException e) {
+            e.printStackTrace();
+        }
+    }
     private void signUp() {
         try {
             mAccountManager = OcPlatform.constructAccountManagerObject(
@@ -636,7 +712,6 @@ public class CloudProvisioningClient extends Activity implements OcAccountManage
         sendBroadcast(intent);
     }
 
-
     private void setDefualtSettings() {
         View setingLayout = getLayoutInflater().inflate(R.layout.setting_layout, null);
 
old mode 100755 (executable)
new mode 100644 (file)
index 3ce36d2..915e7a5
                         android:text="Get CRL" />
                 </LinearLayout>
 
-
+                <LinearLayout
+                      android:layout_width="0dp"
+                      android:layout_height="wrap_content"
+                      android:layout_weight="0.33"
+                      android:gravity="center_horizontal">
+
+                      <Button
+                          android:id="@+id/updateAce"
+                          android:layout_width="wrap_content"
+                          android:layout_height="wrap_content"
+                          android:text="Update ACE" />
+                </LinearLayout>
             </LinearLayout>
 
 
index fb53d7d..842547c 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "JniOcStack.h"
 #include "JniOcCloudProvisioning.h"
+#include "srmutility.h"
 #include "oic_malloc.h"
 
 namespace PH = std::placeholders;
@@ -340,6 +341,255 @@ OCStackResult JniOcCloudProvisioning::createAclId(JNIEnv* env, std::string owner
 
     return m_sharedCloudObject->createAclId(ownerId, deviceID, aclIdResponseCallBack);
 }
+
+static OicSecValidity_t* getValiditiesList(JNIEnv *env, jobject validityObject)
+{
+    jstring jData;
+    jobjectArray  valList = (jobjectArray)env->CallObjectMethod(validityObject,
+            g_mid_OcOicSecCloudAcl_ace_get_validities);
+    if (!valList || env->ExceptionCheck())
+    {
+        return nullptr;
+    }
+    int nr_validities = env->GetArrayLength(valList);
+
+    OicSecValidity_t *valHead = NULL;
+
+    for (int i = 0 ; i < nr_validities; i++)
+    {
+        OicSecValidity_t *tmp = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t));
+        jobject element = env->GetObjectArrayElement(valList, i);
+        if (!element || env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+
+        jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_validity_get_getPeriod);
+        if (!jData || env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        tmp->period = (char*)env->GetStringUTFChars(jData, 0);
+
+        jint jrecurrenceLen = (jint) env->CallIntMethod(element,
+                g_mid_OcOicSecAcl_validity_get_recurrenceLen);
+        tmp->recurrenceLen = (int)jrecurrenceLen;
+
+        if (jrecurrenceLen > 0)
+        {
+            jvalue argv[1];
+            tmp->recurrences = (char**)OICCalloc(jrecurrenceLen, sizeof(char*));
+
+            for (int i = 0 ; i < jrecurrenceLen; i++)
+            {
+                argv[0].i = i;
+                jData = (jstring)env->CallObjectMethodA(element,
+                        g_mid_OcOicSecAcl_validity_get_recurrences, argv);
+                if (!jData || env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
+                tmp->recurrences[i] = (char*)env->GetStringUTFChars(jData, 0);
+            }
+        }
+        if (NULL == valHead)
+        {
+            valHead = tmp;
+        }
+        else
+        {
+            OicSecValidity_t *ptr = valHead;
+            while(ptr->next != NULL) ptr = ptr->next;
+            ptr->next = tmp;
+            tmp->next = NULL;
+        }
+        env->DeleteLocalRef(element);
+    }
+    return valHead;
+}
+
+static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject)
+{
+    jstring jData;
+
+    jobjectArray rescList = (jobjectArray)env->CallObjectMethod(resourceObject,
+            g_mid_OcOicSecCloudAcl_ace_get_resources);
+    if (!rescList || env->ExceptionCheck())
+    {
+        return nullptr;
+    }
+
+    int nr_resc = env->GetArrayLength(rescList);
+    OicSecRsrc_t *rescHead = NULL;
+
+    for (int i = 0 ; i < nr_resc; i++)
+    {
+        OicSecRsrc_t *tmp = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t));
+        jobject element = env->GetObjectArrayElement(rescList, i);
+        if (!element || env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_resr_get_href);
+        if (!jData || env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        tmp->href = (char*)env->GetStringUTFChars(jData, 0);
+
+        jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_resr_get_rel);
+        if (!jData || env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        tmp->rel = (char*)env->GetStringUTFChars(jData, 0);
+
+        jint len = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_resr_get_typeLen);
+        tmp->typeLen = (int)len;
+        if (len > 0)
+        {
+            jvalue argv[1];
+            tmp->types = (char**)OICCalloc(len, sizeof(char*));
+
+            for (int i = 0 ; i < len; i++)
+            {
+                argv[0].i = i;
+                jData = (jstring)env->CallObjectMethodA(element,
+                        g_mid_OcOicSecAcl_resr_get_types, argv);
+                if (!jData || env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
+                tmp->types[i] = (char*)env->GetStringUTFChars(jData, 0);
+            }
+        }
+
+        len = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_resr_get_interfaceLen);
+        tmp->interfaceLen = len;
+        if (len > 0)
+        {
+            jvalue argv[1];
+            tmp->interfaces = (char**)OICCalloc(len, sizeof(char*));
+
+            for (int i = 0 ; i < len; i++)
+            {
+                argv[0].i = i;
+                jData = (jstring)env->CallObjectMethodA(element,
+                        g_mid_OcOicSecAcl_resr_get_interfaces, argv);
+                if (!jData || env->ExceptionCheck())
+                {
+                    return nullptr;
+                }
+                tmp->interfaces[i] = (char*)env->GetStringUTFChars(jData, 0);
+            }
+        }
+
+        if (NULL == rescHead)
+        {
+            rescHead = tmp;
+        }
+        else
+        {
+            OicSecRsrc_t *ptr = rescHead;
+            while(ptr->next != NULL) ptr = ptr->next;
+            ptr->next = tmp;
+            tmp->next = NULL;
+        }
+        env->DeleteLocalRef(element);
+    }
+    return rescHead;
+}
+
+cloudAce_t * ConvertJavaCloudAcestoOCAces(JNIEnv* env, jobjectArray jcloudAces)
+{
+    char *str;
+    jstring jData;
+    cloudAce_t *acesHead = NULL;
+    const jsize arrayLen = env->GetArrayLength(jcloudAces);
+
+    for (int i = 0 ; i < arrayLen; i++)
+    {
+        cloudAce_t *aces = (cloudAce_t*)OICCalloc(1, sizeof(cloudAce_t));
+        jobject element = env->GetObjectArrayElement(jcloudAces, i);
+        if (!element || env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        //get aclID
+        jData = (jstring) env->CallObjectMethod(element, g_mid_OcOicSecCloudAcl_ace_get_aclId);
+        if (!jData || env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        str = (char*) env->GetStringUTFChars(jData, 0);
+        aces->aceId = strdup(str);
+        env->ReleaseStringUTFChars(jData, str);
+
+        //get subjectID
+        jData = (jstring) env->CallObjectMethod(element, g_mid_OcOicSecCloudAcl_ace_get_subjectID);
+        if (!jData || env->ExceptionCheck())
+        {
+            return nullptr;
+        }
+        str = (char*) env->GetStringUTFChars(jData, 0);
+        if (OC_STACK_OK == ConvertStrToUuid(str, &aces->subjectuuid))
+        {
+            env->ReleaseStringUTFChars(jData, str);
+        }
+        else
+        {
+            return nullptr;
+        }
+        //get permission
+        jint permType = (jint)env->CallIntMethod(element, g_mid_OcOicSecCloudAcl_ace_get_permission);
+        aces->permission = (uint16_t)permType;
+        //get stype
+        permType = (jint)env->CallIntMethod(element, g_mid_OcOicSecCloudAcl_ace_get_stype);
+        aces->stype = (uint16_t)permType;
+        //get resources List
+        if (nullptr == (aces->resources = getResourcesList(env, element)))
+        {
+            return nullptr;
+        }
+        aces->validities = NULL;
+        //get validities
+        if (nullptr == (aces->validities = getValiditiesList(env, element)))
+        {
+            return nullptr;
+        }
+        // create list
+        if (NULL == acesHead)
+        {
+            acesHead = aces;
+        }
+        else
+        {
+            cloudAce_t *ptr = acesHead;
+            while(ptr->next != NULL) ptr = ptr->next;
+            ptr->next = aces;
+            aces->next = NULL;
+        }
+    }
+    return acesHead;
+}
+
+OCStackResult JniOcCloudProvisioning::updateIndividualACL(JNIEnv* env, jobject jListener,
+        std::string aclID, jobjectArray jcloudAces)
+{
+    JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener);
+
+    cloudAce_t *aces = NULL;
+    aces = ConvertJavaCloudAcestoOCAces(env, jcloudAces);
+
+    ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data)
+    {
+        resultListener->CloudResultListenerCB(result, data, ListenerFunc::UPDATE_IND_ACL);
+
+    };
+
+    return m_sharedCloudObject->updateIndividualACL(aces, aclID, responseCallBack);
+}
+
 /*
  * Class:     org_iotivity_base_OcCloudProvisioning
  * Method:    requestCertificate
@@ -572,6 +822,60 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getIndividualA
     }
     return;
 }
+/*
+ * Class:     org_iotivity_base_OcCloudProvisioning
+ * Method:    updateIndividualACL
+ * Signature: (Ljava/lang/String;Ljava/lang/Object;Lorg/iotivity/base/OcCloudProvisioning/UpdateIndividualACLListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_updateIndividualACL0
+  (JNIEnv *env, jobject thiz, jstring jaclID, jobjectArray jcloudAces, jobject jListener)
+{
+    LOGD("OcCloudProvisioning_updateIndividualACL");
+    if (!jListener)
+    {
+        ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null");
+        return;
+    }
+    if (!jaclID)
+    {
+        ThrowOcException(OC_STACK_INVALID_PARAM, "aclID cannot be null");
+        return;
+    }
+
+    JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz);
+    if (!cloud)
+    {
+        LOGD("OcCloudProvisioning_updateIndividualACL, No native object, creating now");
+        cloud = Create_native_object(env, thiz);
+        if (!cloud)
+        {
+            ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_updateIndividualACL,"
+                    "Can not Create Native object");
+            return;
+        }
+    }
+
+    const char *str = env->GetStringUTFChars(jaclID, NULL);
+    std::string aclID(str);
+    env->ReleaseStringUTFChars(jaclID, str);
+
+    try
+    {
+        OCStackResult result = cloud->updateIndividualACL(env, jListener, aclID, jcloudAces);
+        if (OC_STACK_OK != result)
+        {
+            ThrowOcException(result, "OcCloudProvisioning_updateIndividualACL");
+            return;
+        }
+    }
+    catch (OCException& e)
+    {
+        LOGE("%s", e.reason().c_str());
+        ThrowOcException(e.code(), e.reason().c_str());
+    }
+    return;
+}
+
 
 /*
  * Class:     org_iotivity_base_OcCloudProvisioning
index 3ab08f1..9bad7f2 100644 (file)
@@ -54,6 +54,8 @@ class JniOcCloudProvisioning
         OCStackResult postCRL(JNIEnv* env, const std::string& thisUpdate,
                                   const std::string& nextUpdate, const OCByteString *crl,
                                    const stringArray_t *serialNumbers, jobject jListener);
+        OCStackResult updateIndividualACL(JNIEnv* env, jobject jListener,
+                        std::string aclID, jobjectArray jcloudAces);
 
     private:
         std::map<jobject, std::pair<JniOcCloudResultListener*, int>> resultMap;
@@ -112,6 +114,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getCRL
 
 /*
  * Class:     org_iotivity_base_OcCloudProvisioning
+ * Method:    updateIndividualACL
+ * Signature: (Ljava/lang/String;Ljava/lang/Object;Lorg/iotivity/base/OcCloudProvisioning/UpdateIndividualACLListener;)V
+ */
+JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_updateIndividualACL0
+  (JNIEnv *, jobject, jstring, jobjectArray, jobject);
+
+/*
+ * Class:     org_iotivity_base_OcCloudProvisioning
  * Method:    postCRL0
  * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/ArrayList;Lorg/iotivity/base/OcCloudProvisioning/PostCRLListener;)V
  */
index b952e61..d94544a 100644 (file)
@@ -103,6 +103,11 @@ void JniOcCloudResultListener::CloudResultListenerCB(int result, void *data,
                 calledFunc = "postCRLListener";
             }
             break;
+        case ListenerFunc::UPDATE_IND_ACL:
+            {
+                calledFunc = "updateIndividualACLListener";
+            }
+            break;
         default:
             {
                 checkExAndRemoveListener(env);
index 3cb826a..96c4176 100644 (file)
@@ -32,7 +32,8 @@ enum class ListenerFunc
     REQUEST_CERTIFICATE = 1,
     GET_ACLINFO,
     GET_CRL,
-    POST_CRL
+    POST_CRL,
+    UPDATE_IND_ACL
 };
 
 class JniOcCloudResultListener
index 0f2df49..89c835c 100644 (file)
@@ -87,6 +87,7 @@ jclass g_cls_OcDirectPairDevice = nullptr;
 jclass g_cls_OcAccountManager = nullptr;
 #ifdef __WITH_TLS__
 jclass g_cls_OcCloudProvisioning = nullptr;
+jclass g_cls_OcOicSecCloudAcl_ace = nullptr;
 #endif
 #endif
 
@@ -153,6 +154,13 @@ jmethodID g_mid_OcOicSecAcl_get_rownerID = nullptr;
 
 #ifdef WITH_CLOUD
 #ifdef __WITH_TLS__
+jmethodID g_mid_OcOicSecCloudAcl_ace_get_aclId = nullptr;
+jmethodID g_mid_OcOicSecCloudAcl_ace_get_subjectID = nullptr;
+jmethodID g_mid_OcOicSecCloudAcl_ace_get_stype = nullptr;
+jmethodID g_mid_OcOicSecCloudAcl_ace_get_permission = nullptr;
+jmethodID g_mid_OcOicSecCloudAcl_ace_get_resources = nullptr;
+jmethodID g_mid_OcOicSecCloudAcl_ace_get_validities = nullptr;
+
 jmethodID g_mid_OcCloudProvisioning_getIP = nullptr;
 jmethodID g_mid_OcCloudProvisioning_getPort = nullptr;
 #endif
@@ -619,16 +627,46 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved)
 #ifdef SECURED
 #ifdef WITH_CLOUD
 #ifdef __WITH_TLS__
+
+    //OicSecCloudAce
+    clazz = env->FindClass("org/iotivity/base/OicSecCloudAce");
+    VERIFY_VARIABLE_NULL(clazz);
+    g_cls_OcOicSecCloudAcl_ace =  (jclass)env->NewGlobalRef(clazz);
+    env->DeleteLocalRef(clazz);
+
+    g_mid_OcOicSecCloudAcl_ace_get_aclId = env->GetMethodID(g_cls_OcOicSecCloudAcl_ace, "getSubjectID","()Ljava/lang/String;");
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecCloudAcl_ace_get_aclId);
+
+    g_mid_OcOicSecCloudAcl_ace_get_subjectID = env->GetMethodID(g_cls_OcOicSecCloudAcl_ace, "getSubjectID","()Ljava/lang/String;");
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecCloudAcl_ace_get_subjectID);
+
+    g_mid_OcOicSecCloudAcl_ace_get_stype = env->GetMethodID(g_cls_OcOicSecCloudAcl_ace, "getStype","()I");
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecCloudAcl_ace_get_stype);
+
+    g_mid_OcOicSecCloudAcl_ace_get_permission = env->GetMethodID(g_cls_OcOicSecCloudAcl_ace, "getPermission","()I");
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecCloudAcl_ace_get_permission);
+
+    g_mid_OcOicSecCloudAcl_ace_get_resources = env->GetMethodID(g_cls_OcOicSecCloudAcl_ace,
+            "getResources","()[Lorg/iotivity/base/OicSecResr;");
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecCloudAcl_ace_get_resources);
+
+    g_mid_OcOicSecCloudAcl_ace_get_validities = env->GetMethodID(g_cls_OcOicSecCloudAcl_ace,
+            "getValidities","()[Lorg/iotivity/base/OicSecValidity;");
+    VERIFY_VARIABLE_NULL(g_mid_OcOicSecCloudAcl_ace_get_validities);
+
+
     //OcCloudProvisioning
     clazz = env->FindClass("org/iotivity/base/OcCloudProvisioning");
     VERIFY_VARIABLE_NULL(clazz);
     g_cls_OcCloudProvisioning =  (jclass)env->NewGlobalRef(clazz);
     env->DeleteLocalRef(clazz);
 
-    g_mid_OcCloudProvisioning_getIP = env->GetMethodID(g_cls_OcCloudProvisioning, "getIP", "()Ljava/lang/String;");
+    g_mid_OcCloudProvisioning_getIP = env->GetMethodID(g_cls_OcCloudProvisioning,
+            "getIP", "()Ljava/lang/String;");
     VERIFY_VARIABLE_NULL(g_mid_OcCloudProvisioning_getIP);
 
-    g_mid_OcCloudProvisioning_getPort = env->GetMethodID(g_cls_OcCloudProvisioning, "getPort", "()I");
+    g_mid_OcCloudProvisioning_getPort = env->GetMethodID(g_cls_OcCloudProvisioning,
+            "getPort", "()I");
     VERIFY_VARIABLE_NULL(g_mid_OcCloudProvisioning_getPort);
 #endif
 #endif
@@ -691,6 +729,7 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
         env->DeleteGlobalRef(g_cls_OcAccountManager);
 #ifdef __WITH_TLS__
         env->DeleteGlobalRef(g_cls_OcCloudProvisioning);
+                               env->DeleteGlobalRef(g_cls_OcOicSecCloudAcl_ace);
 #endif
 #endif
         env->DeleteGlobalRef(g_cls_OcOicSecAcl);
index 7ba3367..1123912 100644 (file)
@@ -105,6 +105,7 @@ extern jclass g_cls_OcAccountManager;
 #endif
 #ifdef __WITH_TLS__
 extern jclass g_cls_OcCloudProvisioning;
+extern jclass g_cls_OcOicSecCloudAcl_ace;
 #endif
 
 extern jclass g_cls_OcOicSecAcl_ace;
@@ -150,6 +151,12 @@ extern jmethodID g_mid_OcAccountManager_ctor;
 #ifdef __WITH_TLS__
 extern jmethodID g_mid_OcCloudProvisioning_getIP;
 extern jmethodID g_mid_OcCloudProvisioning_getPort;
+extern jmethodID g_mid_OcOicSecCloudAcl_ace_get_aclId;
+extern jmethodID g_mid_OcOicSecCloudAcl_ace_get_subjectID;
+extern jmethodID g_mid_OcOicSecCloudAcl_ace_get_stype;
+extern jmethodID g_mid_OcOicSecCloudAcl_ace_get_permission;
+extern jmethodID g_mid_OcOicSecCloudAcl_ace_get_resources;
+extern jmethodID g_mid_OcOicSecCloudAcl_ace_get_validities;
 #endif
 
 extern jmethodID g_mid_OcOicSecAcl_get_rownerID;
index de10aca..b5b1034 100644 (file)
@@ -116,6 +116,15 @@ namespace OC
             OCStackResult getCRL(ResponseCallBack callback);
 
             /**
+             * API for updation of Individual Acl
+             * @param aces is the list of Access control entities for updation.
+             * @param callback function called by the stack on completion of request
+             * @return ::OC_STACK_OK on Success and other values otherwise
+             */
+            OCStackResult updateIndividualACL(const cloudAce_t *aces, std::string &aclId,
+                    ResponseCallBack callback);
+
+            /**
              * API to post the  certificate revocation list to cloud
              * @param thisUpdate thisUpdate [mandatory param]
              * @param nextUpdate nextUpdate [mandatory param]
index 07b8c1f..d1f2a47 100644 (file)
@@ -204,6 +204,37 @@ namespace OC
         return result;
     }
 
+    OCStackResult OCCloudProvisioning::updateIndividualACL(const cloudAce_t *aces, std::string& aclId, ResponseCallBack callback)
+    {
+        if (!callback)
+        {
+            oclog() <<"Result callback can't be null";
+            return OC_STACK_INVALID_CALLBACK;
+        }
+        if (!aces)
+        {
+            oclog() <<"Aces List can not be empty";
+            return OC_STACK_INVALID_CALLBACK;
+        }
+        OCStackResult result;
+        auto cLock = OCPlatform_impl::Instance().csdkLock().lock();
+
+        if (cLock)
+        {
+            CloudProvisionContext *context = new CloudProvisionContext(callback);
+
+            std::lock_guard<std::recursive_mutex> lock(*cLock);
+            result = OCCloudAclIndividualAclUpdate(static_cast<void*>(context), aclId.c_str(),
+                    aces, &m_devAddr, &OCCloudProvisioning::callbackWrapper);
+        }
+        else
+        {
+            oclog() <<"Mutex not found";
+            result = OC_STACK_ERROR;
+        }
+        return result;
+    }
+
     OCStackResult OCCloudProvisioning::postCRL(const std::string& thisUpdate,
                                               const std::string& nextUpdate,
                                               const OCByteString *crl,