From: George Nash Date: Fri, 13 Jan 2017 00:54:58 +0000 (-0800) Subject: Add ACLs to java SimpleService so examples run when SECURED=1 X-Git-Tag: 1.3.0~789 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=472fbac69a762a9e2ddd0a396aec0ae58cfbaef9;p=platform%2Fupstream%2Fiotivity.git Add ACLs to java SimpleService so examples run when SECURED=1 The ModeType in SimpleClient is changed to CLIENT_SERVER This is a work around for IOT-693 the ioc_svr_db_server ACL file is a copy of the ACL file from resource/examples. The example will run against the simpleservice simpleclient in resource. Build: scons BUILD_JAVA=1 Run examples: export LD_LIBRARY_PATH=/out/linux/x86_64/release/ java -cp java/examples-java/simpleserver/build/libs/simpleserver.jar:\ java/iotivity-linux/build/libs/iotivity-linux.jar \ org.iotivity.base.examples.SimpleServer java -cp java/examples-java/simpleclient/build/libs/simpleclient.jar:\ java/iotivity-linux/build/libiotivity-linux.jar \ org.iotivity.base.examples.SimpleClient Change-Id: I56b627a5edfac823934b5966a06e4bbd8ac561e2 Signed-off-by: George Nash Reviewed-on: https://gerrit.iotivity.org/gerrit/16363 Reviewed-by: Phil Coval Tested-by: jenkins-iotivity Reviewed-by: Larry Sachs Reviewed-by: Rick Bell --- diff --git a/java/SConscript b/java/SConscript index dae4979..45d9e5c 100644 --- a/java/SConscript +++ b/java/SConscript @@ -101,5 +101,9 @@ jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' b #cmdBuildExamples=jdk_env.Gradle(target="../examples-%s/devicediscoveryclient/apk" % (examples_target, ), source="examples-%s/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java" % (examples_target, )) cmdBuildExamples=jdk_env.Gradle(target="examples-%s/simpleclient/jar" % (examples_target, ), source="examples-%s/simpleclient/src/main/java/org/iotivity/base/examples/SimpleClient.java" % (examples_target, )) +exampleAclFiles = jdk_env.Install('#java/examples-java/simpleserver/build/libs/', 'examples-java/simpleserver/src/main/assets/oic_svr_db_server.dat') + +Depends(cmdBuildExamples, exampleAclFiles) Depends(cmdBuildExamples, cmdBuildApi) + env.AppendUnique(baseAAR = cmdBuildApi) diff --git a/java/examples-java/simpleclient/src/main/java/org/iotivity/base/examples/SimpleClient.java b/java/examples-java/simpleclient/src/main/java/org/iotivity/base/examples/SimpleClient.java index 6a7cc1f..ef94e9b 100644 --- a/java/examples-java/simpleclient/src/main/java/org/iotivity/base/examples/SimpleClient.java +++ b/java/examples-java/simpleclient/src/main/java/org/iotivity/base/examples/SimpleClient.java @@ -66,7 +66,7 @@ public class SimpleClient implements PlatformConfig platformConfig = new PlatformConfig( ServiceType.IN_PROC, - ModeType.CLIENT, + ModeType.CLIENT_SERVER, "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces 0, // Uses randomly available port QualityOfService.LOW diff --git a/java/examples-java/simpleserver/src/main/assets/oic_svr_db_server.dat b/java/examples-java/simpleserver/src/main/assets/oic_svr_db_server.dat new file mode 100644 index 0000000..9e4d7fa Binary files /dev/null and b/java/examples-java/simpleserver/src/main/assets/oic_svr_db_server.dat differ diff --git a/java/examples-java/simpleserver/src/main/assets/oic_svr_db_server.json b/java/examples-java/simpleserver/src/main/assets/oic_svr_db_server.json old mode 100755 new mode 100644 index 729138c..f6d3dca --- a/java/examples-java/simpleserver/src/main/assets/oic_svr_db_server.json +++ b/java/examples-java/simpleserver/src/main/assets/oic_svr_db_server.json @@ -1,56 +1,101 @@ -{ - "acl": [ - { - "sub": "Kg==", - "rsrc": [ - "/oic/res", - "/oic/d", - "/oic/p", - "/oic/res/types/d", - "/oic/ad", - "/oic/sec/acl" - ], - "perms": 2, - "ownrs" : ["MTExMTExMTExMTExMTExMQ=="] - }, - { - "sub": "Kg==", - "rsrc": [ - "/oic/sec/doxm", - "/oic/sec/pstat" - ], - "perms": 2, - "ownrs" : ["MTExMTExMTExMTExMTExMQ=="] - }, - { - "sub": "Kg==", - "rsrc": ["/light0", "/light1", "/a/light"], - "perms": 6, - "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="] - } - ], - "pstat": { - "isop": true, - "deviceid": "ZGV2aWNlaWQAAAAAABhanw==", - "ch": 0, - "cm": 0, - "tm": 0, - "om": 3, - "sm": [3] - }, - "doxm": { - "oxm": [0], - "oxmsel": 0, - "sct": 1, - "owned": true, - "deviceid": "MTExMTExMTExMTExMTExMQ==", - "ownr": "MjIyMjIyMjIyMjIyMjIyMg==" - }, - "cred": [{ - "credid": 1, - "sub": "MjIyMjIyMjIyMjIyMjIyMg==", - "credtyp": 1, - "pvdata": "QUFBQUFBQUFBQUFBQUFBQQ==", - "ownrs" : ["MjIyMjIyMjIyMjIyMjIyMg=="] - }] -} +{ + "acl": { + "aclist": { + "aces": [ + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/res", + "rel": "", + "rt": ["oic.wk.res"], + "if": ["oic.if.ll"] + }, + { + "href": "/oic/d", + "rel": "", + "rt": ["oic.wk.d"], + "if": ["oic.if.baseline", "oic.if.r"] + }, + { + "href": "/oic/p", + "rel": "", + "rt": ["oic.wk.p"], + "if": ["oic.if.baseline", "oic.if.r"] + }, + { + "href": "/oic/sec/acl", + "rel": "", + "rt": ["oic.r.acl"], + "if": ["oic.if.baseline"] + } + ], + "permission": 2 + }, + { + "subjectuuid": "*", + "resources": [ + { + "href": "/oic/sec/doxm", + "rel": "", + "rt": ["oic.r.doxm"], + "if": ["oic.if.baseline"] + }, + { + "href": "/oic/sec/pstat", + "rel": "", + "rt": ["oic.r.pstat"], + "if": ["oic.if.baseline"] + } + ], + "permission": 2 + }, + { + "subjectuuid": "*", + "resources": [ + { + "href": "/a/light", + "rel": "", + "rt": ["oic.core"], + "if": ["oic.if.baseline"] + } + ], + "permission": 7 + } + ] + }, + "rowneruuid" : "31313131-3131-3131-3131-313131313131" + }, + "pstat": { + "isop": true, + "deviceuuid": "31313131-3131-3131-3131-313131313131", + "rowneruuid": "31313131-3131-3131-3131-313131313131", + "cm": 0, + "tm": 0, + "om": 4, + "sm": 4 + }, + "doxm": { + "oxms": [0], + "oxmsel": 0, + "sct": 1, + "owned": true, + "deviceuuid": "31313131-3131-3131-3131-313131313131", + "devowneruuid": "32323232-3232-3232-3232-323232323232", + "rowneruuid": "31313131-3131-3131-3131-313131313131" + }, + "cred": { + "creds": [ + { + "credid": 1, + "subjectuuid": "32323232-3232-3232-3232-323232323232", + "credtype": 1, + "privatedata": { + "data": "AAAAAAAAAAAAAAAA", + "encoding": "oic.sec.encoding.raw" + } + } + ], + "rowneruuid": "31313131-3131-3131-3131-313131313131" + } +} \ No newline at end of file diff --git a/java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java b/java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java index 446fb8a..e84d678 100644 --- a/java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java +++ b/java/examples-java/simpleserver/src/main/java/org/iotivity/base/examples/SimpleServer.java @@ -29,6 +29,7 @@ import org.iotivity.base.PlatformConfig; import org.iotivity.base.QualityOfService; import org.iotivity.base.ServiceType; +import java.net.URISyntaxException; import java.util.LinkedList; import java.util.List; @@ -47,13 +48,22 @@ public class SimpleServer { * A local method to configure and initialize platform, and then create a light resource. */ private static void startSimpleServer() { + String path = ""; + // This assumes the oic_svr_db_server.dat file is in the same location as the SimpleServer.jar file + try { + path = SimpleServer.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); + path = path.substring(0, path.lastIndexOf('/')); + } catch (URISyntaxException e) { + msg(e.getMessage() + " unable to find local file path."); + } PlatformConfig platformConfig = new PlatformConfig( ServiceType.IN_PROC, ModeType.SERVER, "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces 0, // Uses randomly available port - QualityOfService.LOW + QualityOfService.LOW, + path + "/oic_svr_db_server.dat" ); msg("Configuring platform.");