Updated account server
authorAndriy Gudz <a.gudz@samsung.com>
Wed, 7 Jun 2017 13:41:45 +0000 (16:41 +0300)
committerAndriy Gudz <a.gudz@samsung.com>
Wed, 7 Jun 2017 13:41:45 +0000 (16:41 +0300)
34 files changed:
cloud/account/README
cloud/account/certificate/iotivitycloud.crt [new file with mode: 0644]
cloud/account/certificate/iotivitycloud.key [new file with mode: 0644]
cloud/account/certificate/rootca.crt [new file with mode: 0644]
cloud/account/pom.xml
cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServer.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/Constants.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/AccountDBManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/MongoDB.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/OAuthProviderFactory.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupAclManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupBrokerManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/Ace.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/AceResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/Acl.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/AclResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/verify/AclVerifyResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/verify/Permission.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/crl/CrlManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/crl/CrlResource.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/AccountResourceTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/session/SessionResourceTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/tokenrefresh/TokenRefreshResourceTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupAclManagerTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupBrokerTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupResourceTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/acl/id/AclIdResourceTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteResourceTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/acl/verify/AclVerifyResourceTest.java

index c5cd318..1c8bc45 100644 (file)
@@ -23,8 +23,8 @@ Build and Run
 5) Run .jar file
 
        go to "target" folder
-       $ java -jar CloudAccount-0.0.1-SNAPSHOT.jar arg1(AccountServer CoAP Server Port) arg2(TLS mode required)
-       e.g. java -jar CloudAccount-0.0.1-SNAPSHOT.jar 5685 0
+       $ java -jar CloudAccount-0.0.1-SNAPSHOT.jar arg1(AccountServer CoAP Server Port) arg2(MongoDB IP Address) arg3(MongoDB Port) arg4(TLS mode required)
+       e.g. java -jar CloudAccount-0.0.1-SNAPSHOT.jar 5685 127.0.0.1 27017 0
 
         - If you want to operate on TLS mode, "CLOUD_CERT_FILE(iotivitycloud.crt)" and "CLOUD_KEY_FILE(iotivitycloud.key)" files
           should be placed in the "target" folder.
@@ -33,6 +33,6 @@ Build and Run
        - Before you run a Accout server, You need to set up following steps.
           1) Install MongoDB
           2) Install Github certificates for github.com and *.github.com.
-5) Please download: file from http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html: Java Cryptography Extension
-         1.Extract files from zip. 
-         2.Place local_policy.jar and US_export_policy.jar files in/usr/lib/jvm/PATH_TO_JDK/jre/lib/security 
+6) Please download: file from http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html: Java Cryptography Extension
+         1.Extract files from zip.
+         2.Place local_policy.jar and US_export_policy.jar files in/usr/lib/jvm/PATH_TO_JDK/jre/lib/security
diff --git a/cloud/account/certificate/iotivitycloud.crt b/cloud/account/certificate/iotivitycloud.crt
new file mode 100644 (file)
index 0000000..f8435c0
--- /dev/null
@@ -0,0 +1,22 @@
+-----BEGIN CERTIFICATE-----
+MIIDkjCCAnoCCQCHJBxvNqehJzANBgkqhkiG9w0BAQsFADCBizELMAkGA1UEBhMC
+S1IxDjAMBgNVBAgMBVNlb3VsMQ8wDQYDVQQHDAZVbXllb24xETAPBgNVBAoMCFNh
+bXN1bmcgMRQwEgYDVQQLDAtPQ0YgUm9vdCBDQTEyMDAGA1UEAwwpdXVpZDozMTMx
+MzEzMS0zMTMxLTMxMzEtMzEzMS0zMTMxMzEzMTMxMzEwHhcNMTYxMDI4MDQyOTI2
+WhcNMjExMDI3MDQyOTI2WjCBiTELMAkGA1UEBhMCS1IxDjAMBgNVBAgMBVNlb3Vs
+MQ8wDQYDVQQHDAZVbXllb24xEDAOBgNVBAoMB1NhbXN1bmcxEzARBgNVBAsMCk9D
+RiBTdWIgQ0ExMjAwBgNVBAMMKXV1aWQ6MzEzMTMxMzEtMzEzMS0zMTMxLTMxMzEt
+MzEzMTMxMzEzMTMyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0zIb
+fR8AOJ8mptGOjWUiN0Eua6VghHuc4FWCDTpVe1Bq7cjt/CWinDTjslRTeY8MgSni
+juT0baweHVkxyner89OAWo36vGwmjupTmC8B/x0rafDprQ64HQym5VwRXYi6X3S8
+lws5GtcotGrfBBdNiEzbKo4pdSPmeabRu/CEQmCA6OwnsIEK52wDk6llm6zkI6sS
+lhDhtdjg5Q5d9JlH2M3RaybAouyiHSbqZsZbykl3wdxF/X843n1fNyrUTsfPr6fe
+cTKhaOkpUIjWF1Ex/RfLRDGoG7XVCml4DWpLOhaGonIEP3BLBhXQ1QUedDLyQq6Y
+6LJzTIFqXYZUoQtoNwIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBbZzw65+2sw3Qc
+9Gh2VXmMoeDaKNvmgQinxjeAJzJc3rMCCwuZEJWNitub6AgdXycIYTtTGmmeObeE
+uLwilo17rvVx9KQ+D8psxQu7gZwE897UQIm+s3vQ/M42CK6/Kn9CmaOTBea1GWdn
+1IEAWi3QtjDT6JhP5QQ8sOs2zOFMp3ADUS/83yd3jMoOrDYNZ60gJtgHmOewq1Pu
+oJFxB4OruOfSThjLMCjvuX0ThNPoR/KWwIaz90aQoI1siRFOPh26SD9Bg3VewOQk
+atmutT1MJ1TsnnB5uPQxy/vfERK77R8uSMIb/WFu/poDyafXsbFoUGq9Pif5boKX
+LRzF7PfZ
+-----END CERTIFICATE-----
diff --git a/cloud/account/certificate/iotivitycloud.key b/cloud/account/certificate/iotivitycloud.key
new file mode 100644 (file)
index 0000000..a40da3f
--- /dev/null
@@ -0,0 +1,28 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDTMht9HwA4nyam
+0Y6NZSI3QS5rpWCEe5zgVYINOlV7UGrtyO38JaKcNOOyVFN5jwyBKeKO5PRtrB4d
+WTHKd6vz04Bajfq8bCaO6lOYLwH/HStp8OmtDrgdDKblXBFdiLpfdLyXCzka1yi0
+at8EF02ITNsqjil1I+Z5ptG78IRCYIDo7CewgQrnbAOTqWWbrOQjqxKWEOG12ODl
+Dl30mUfYzdFrJsCi7KIdJupmxlvKSXfB3EX9fzjefV83KtROx8+vp95xMqFo6SlQ
+iNYXUTH9F8tEMagbtdUKaXgNaks6FoaicgQ/cEsGFdDVBR50MvJCrpjosnNMgWpd
+hlShC2g3AgMBAAECggEAHtsYRwyLdLpT5FWDlUbsW9RLGvEbi9+fiOsVSCd4q76R
+ENKlaox5GIdlqP1HAOCUfB6JekUbLRbTg4gvjRw05DfHbfOGaZcHfyPfOMHNcd9q
+I11OVrlqztu1Wpc79kVurVmZ4BuEqVY8HTfsA2YALuTDtJD2n6WyG53y0JmQST4a
+DfSFY2J+NLfSWEamvRzvI/jWYN3VYVXaFh6IVQFjs3dr/NQuLBYISF2CuB539kL8
+qHLhDnyc0x4vaiFlU1EnGy6FYFg0kBxvJGgRXR7PSI+JBE6DDIOSR0OJxIYlnTVN
+P89QAIffjvgugdL3BxF6AT38a8uK083umxWsTHB8IQKBgQD76CfqjH+8EwIMJlQI
+uQOMm2f3ofX9lnOok75jcpBfweGheU654YS07PaIVf0ujmBPJ152fpx8tdC9F2kW
+yWWaen4AOuiiQzcZzJ18Vs3RG15qxA/TJdTgo1b9/fvkby7V0gk9q/Q867loozSm
+Y+8qLwCa671uxlAxm2AuRr2lhwKBgQDWoJuCoXtRCw/qwGBgtwlfNUX06mu8LJH3
+G8vqeoCqkrwu+boAYpf2NufD2Z+039vtIVyXLeIxIyqZuG0UvhQZjauvPXBWx8Vi
+WT4bBgy2RH4q2FIwNfL0Kpl+hgklwqwp2Kfg3LEfzn2FQbyN7tS3j7Wl0VMPLsVi
+HnZEqy/T0QKBgBsTRNcM6t3IHTw5Emctm5gNTAttuQbcmOnRl3EQ6zuflyTH6RJJ
+jv3zSjw1IdVTMD7RuHF8Ak3VLO5mCcGNPAJykABuVHq8RrvbJkIrAkwraOaI1DqZ
+olvSspLyLZTL7njE7oFWbhXuMCty/0GzFA2wp5v/Iok5f30Veiz/JXsZAoGBANJy
+1ylGt8kmpKvViGss7paZgQf+mDcCKPn5GoDHL8SRbs5M9fIMut6kxarHiA7t9hLV
+RJnEVudBiTMDoInXO5Q20uJYxv+AkO23fes3il1qWaAfTq+RJrH911Y1jWCmOvQp
+Sat2GoOKkI+Kfp1ZUuDOnBmEYAIiJU7peaQpixMRAoGAF75yG66vC7JSmy83BHEN
+HWfYNQ8knfAIER9SOFRxnyS99z5HfoSS5EoEi60kZ7X2ddRkZxRZeOtzA9opLpWY
+5z9SmI3Mg4ZVtL0FddseA10CYc8kgBUHTahpPsYQD8ptkn2K6I0dHtNe5B2XmC5U
+z5NqBCackqTQwVrZIByLjM8=
+-----END PRIVATE KEY-----
diff --git a/cloud/account/certificate/rootca.crt b/cloud/account/certificate/rootca.crt
new file mode 100644 (file)
index 0000000..ee80fa4
--- /dev/null
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDjDCCAnQCAQEwDQYJKoZIhvcNAQELBQAwgYsxCzAJBgNVBAYTAktSMQ4wDAYD
+VQQIDAVTZW91bDEPMA0GA1UEBwwGVW15ZW9uMREwDwYDVQQKDAhTYW1zdW5nIDEU
+MBIGA1UECwwLT0NGIFJvb3QgQ0ExMjAwBgNVBAMMKXV1aWQ6MzEzMTMxMzEtMzEz
+MS0zMTMxLTMxMzEtMzEzMTMxMzEzMTMxMB4XDTE2MTAyODA0MjEyMloXDTI2MTAy
+NjA0MjEyMlowgYsxCzAJBgNVBAYTAktSMQ4wDAYDVQQIDAVTZW91bDEPMA0GA1UE
+BwwGVW15ZW9uMREwDwYDVQQKDAhTYW1zdW5nIDEUMBIGA1UECwwLT0NGIFJvb3Qg
+Q0ExMjAwBgNVBAMMKXV1aWQ6MzEzMTMxMzEtMzEzMS0zMTMxLTMxMzEtMzEzMTMx
+MzEzMTMxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3EJwn+NfeW9Y
+RLDoOUSg45AvkqsMeNBv8ZTqWyY5nAeyESQsDejacm6dSpzMP/p5y1KBWYszKOXr
+CUtrkch8VxOtt4egiv3Tschl16W1W7ril8EEbX8zoEcuExfoLdPZhDtRl8ROdG3t
+NE0r/Fv5ubTEwW0K3JgIwykB4OAsO2aQtCuZ32cZlg5UcW3LAXpxJ7cEkMR2xhcN
+xbg0dgbyy5BiWit3grXXJBkopq/ADCRUIVzpLjxeFTVshWw9+AA1IUZaG64fkbLG
+pzdYFVsuRvMlyEwWrMm23/hT8x0eywvPX5k/N1s6I0KiE8FitVi5bgUph3iCNLE/
+1a/oLrtWyQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQDHq9X9YofW3IN8R61r0raN
+tacYMumZFZfPOEcHHGvTkPrMygUNfTM+g6XEzOvlBB4dd6UE5EsVnRkQP0wvaaJx
+3Js/zQMkAXeVRzDg/YowynuG+t4VvoQl/1uNDUKjU9z+yv+vQjNctzeKhvAJxWGO
+ZtpgIslUhMtGBjWQDNd2APf8yOcD50yVwUpcp4WGbqaaKxn+rixu8jk1NEas0EHD
+XBytAgEdOeBQplv6W+W1fG3j0PMolkWaPIvjSvMk0m11h4GR5Kyx3gRQS74gurG/
+DboAZ+DJMe7hMh4coOwnOuS8euPtxEPD3IkYVAT4aFPIvTkiri0EYimgtQd+M45f
+-----END CERTIFICATE-----
index 77acc5b..0f166ac 100644 (file)
                        <version>1.7.0</version>
                </dependency>
                <dependency>
+                       <groupId>org.reflections</groupId>
+                       <artifactId>reflections</artifactId>
+                       <version>0.9.11</version>
+               </dependency>
+               <dependency>
                        <groupId>org.powermock</groupId>
                        <artifactId>powermock-api-mockito</artifactId>
                        <version>1.6.5</version>
index f2830e5..220e058 100644 (file)
@@ -24,16 +24,18 @@ package org.iotivity.cloud.accountserver;
 import java.net.InetSocketAddress;
 import java.util.Scanner;
 
+import org.iotivity.cloud.accountserver.db.AccountDBManager;
 import org.iotivity.cloud.accountserver.resources.account.AccountResource;
 import org.iotivity.cloud.accountserver.resources.account.session.SessionResource;
 import org.iotivity.cloud.accountserver.resources.account.tokenrefresh.TokenRefreshResource;
 import org.iotivity.cloud.accountserver.resources.acl.group.GroupResource;
 import org.iotivity.cloud.accountserver.resources.acl.id.AclResource;
-import org.iotivity.cloud.accountserver.resources.acl.verify.AclVerifyResource;
 import org.iotivity.cloud.accountserver.resources.acl.invite.InviteResource;
+import org.iotivity.cloud.accountserver.resources.acl.verify.AclVerifyResource;
 import org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateResource;
 import org.iotivity.cloud.accountserver.resources.credprov.crl.CrlResource;
 import org.iotivity.cloud.base.ServerSystem;
+import org.iotivity.cloud.base.resource.CloudPingResource;
 import org.iotivity.cloud.base.server.CoapServer;
 import org.iotivity.cloud.util.Log;
 
@@ -44,42 +46,43 @@ import org.iotivity.cloud.util.Log;
  */
 public class AccountServer {
 
-    public static void main(String[] args) throws Exception {
-        Log.Init();
+    private static int     coapServerPort;
+    private static boolean tlsMode;
+    private static String  databaseHost;
+    private static String  webLogHost;
 
+    public static void main(String[] args) throws Exception {
         System.out.println("-----Account SERVER-----");
+        Log.Init();
 
-        if (args.length != 2) {
-            Log.e("coap server port and TLS mode required\n" + "ex) 5685 0\n");
+        if (!parseConfiguration(args)) {
+            Log.e("\nCoAP-server <Port> Database <Address> <Port> TLS-mode <0|1> are required. WebSocketLog-Server <Addres> <Port> is optional.\n"
+                    + "ex) " + Constants.DEFAULT_COAP_PORT
+                    + " 127.0.0.1 27017 0\n");
             return;
         }
+        if (webLogHost != null)
+            Log.InitWebLog(webLogHost,
+                    AccountServer.class.getSimpleName().toString());
+
+        AccountDBManager.createInstance(databaseHost);
 
         ServerSystem serverSystem = new ServerSystem();
 
+        serverSystem.addResource(new CloudPingResource());
         serverSystem.addResource(new AccountResource());
-
         serverSystem.addResource(new SessionResource());
-
         serverSystem.addResource(new TokenRefreshResource());
-
         serverSystem.addResource(new GroupResource());
-
         serverSystem.addResource(new AclResource());
-
         serverSystem.addResource(new AclVerifyResource());
-
         serverSystem.addResource(new CertificateResource());
-
         serverSystem.addResource(new CrlResource());
-
         serverSystem.addResource(new AclResource());
-
         serverSystem.addResource(new InviteResource());
 
-        serverSystem.addServer(new CoapServer(
-                new InetSocketAddress(Integer.parseInt(args[0]))));
-
-        boolean tlsMode = Integer.parseInt(args[1]) == 1;
+        serverSystem.addServer(
+                new CoapServer(new InetSocketAddress(coapServerPort)));
 
         serverSystem.startSystem(tlsMode);
 
@@ -97,4 +100,27 @@ public class AccountServer {
 
         System.out.println("Terminated");
     }
+
+    private static boolean parseConfiguration(String[] args) {
+        // configuration provided by arguments
+        if (args.length == 4 || args.length == 6) {
+            coapServerPort = Integer.parseInt(args[0]);
+            databaseHost = args[1] + ":" + args[2];
+            tlsMode = Integer.parseInt(args[3]) == 1;
+            if (args.length == 6)
+                webLogHost = args[4] + ":" + args[5];
+            return true;
+        }
+        // configuration provided by docker env
+        String tlsModeEnv = System.getenv("TLS_MODE");
+        if (tlsModeEnv != null) {
+
+            coapServerPort = Constants.DEFAULT_COAP_PORT;
+            databaseHost = System.getenv("MONGODB_ADDRESS") + ":"
+                    + System.getenv("MONGODB_PORT");
+            tlsMode = Integer.parseInt(tlsModeEnv) == 1;
+            return true;
+        }
+        return false;
+    }
 }
index c8ca7dc..d684f2a 100644 (file)
@@ -27,6 +27,8 @@ import org.iotivity.cloud.base.OICConstants;
 
 public class Constants extends OICConstants {
 
+    public static final int    DEFAULT_COAP_PORT          = 5685;
+
     public static final String PROPERTIES_FILE_NAME       = "properties"
             + File.separator + "config.properties";
 
@@ -58,6 +60,8 @@ public class Constants extends OICConstants {
 
     // Database table key
 
+    public static final String RESP_GROUP_PERMISSION      = "gp";
+
     public static final String KEYFIELD_SN                = "serialNumber";
 
     public static final String KEYFIELD_NA                = "notAfter";
@@ -266,12 +270,8 @@ public class Constants extends OICConstants {
 
     public static final int    TOKEN_INFINITE             = -1;
 
-    // auth servers
-
-    public static final String GITHUB                     = "Github";
-
-    public static final String SAMSUNG                    = "Samsung";
+    // oauth
 
-    public static final String GOOGLE                     = "Google";
+    public static final String OAUTH_LIBRARIES_PATH       = "oauth/";
 
 }
index ef7f33f..d10b845 100644 (file)
@@ -21,6 +21,7 @@
  */
 package org.iotivity.cloud.accountserver.db;
 
+import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -39,24 +40,20 @@ import org.iotivity.cloud.base.exception.ServerException.InternalServerErrorExce
  */
 public class AccountDBManager {
 
-    private static AccountDBManager            accoutDBManager = new AccountDBManager();
-
+    private static AccountDBManager            accountDBManager;
     private MongoDB                            mongoDB;
-
     private HashMap<String, ArrayList<String>> keyField        = new HashMap<String, ArrayList<String>>();
 
-    private AccountDBManager() {
-
-        createDatabase();
+    private AccountDBManager(String dbHost) {
+        createDatabase(dbHost);
         createTables();
         createIndexes();
     }
 
-    private void createDatabase() {
+    private void createDatabase(String dbHost) {
 
         try {
-
-            mongoDB = new MongoDB(Constants.DB_NAME);
+            mongoDB = new MongoDB(dbHost, Constants.DB_NAME);
         } catch (Exception e) {
             e.printStackTrace();
             throw new InternalServerErrorException(
@@ -151,8 +148,20 @@ public class AccountDBManager {
      * @return account DB manager
      */
     public static AccountDBManager getInstance() {
+        if (accountDBManager == null)
+            accountDBManager = new AccountDBManager("127.0.0.1");
+        return accountDBManager;
+    }
 
-        return accoutDBManager;
+    /**
+     * API to create DBManager instance with specific host
+     *
+     * @return created DB manager
+     */
+    public static AccountDBManager createInstance(String dbHost) {
+        if (accountDBManager == null)
+            accountDBManager = new AccountDBManager(dbHost);
+        return accountDBManager;
     }
 
     /**
index a79d027..83dfb78 100644 (file)
  */
 package org.iotivity.cloud.accountserver.db;
 
-import java.util.List;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -52,13 +52,14 @@ public class MongoDB {
     /**
      * API creating MongoClient and initializing MongoDatabase
      *
+     * @param host
+     *            host of MongoDatabase
      * @param dbname
      *            database name to create MongoDatabase
      * @throws Exception
      */
-    public MongoDB(String dbname) throws Exception {
-
-        mongoClient = new MongoClient();
+    public MongoDB(String host, String dbname) throws Exception {
+        mongoClient = new MongoClient(host);
         mongoClient.dropDatabase(dbname);
         db = mongoClient.getDatabase(dbname);
     }
@@ -276,7 +277,7 @@ public class MongoDB {
             Document doc) {
 
         if (tableName == null || doc == null)
-            return null;
+            return new ArrayList<>();
 
         MongoCollection<Document> collection = db.getCollection(tableName);
         MongoCursor<Document> cursor = collection.find(doc).iterator();
@@ -306,7 +307,8 @@ public class MongoDB {
 
         while (entryIter.hasNext()) {
 
-            Map.Entry<String, Object> entry = (Map.Entry<String, Object>) entryIter.next();
+            Map.Entry<String, Object> entry = (Map.Entry<String, Object>) entryIter
+                    .next();
 
             String entryKey = entry.getKey();
 
@@ -314,13 +316,15 @@ public class MongoDB {
             if (entry.getValue() != null && !entryKey.equals("_id")) {
 
                 // if value is Array
-                if (entry.getValue() instanceof List && !((List) entry.getValue()).isEmpty()
+                if (entry.getValue() instanceof List
+                        && !((List) entry.getValue()).isEmpty()
                         && ((List) entry.getValue()).get(0) instanceof Document)
 
                 {
                     List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
 
-                    for (Document document : (List<Document>) entry.getValue()) {
+                    for (Document document : (List<Document>) entry
+                            .getValue()) {
                         list.add(convertDocumentToHashMap(document));
                     }
                     resourceMap.put(entry.getKey(), list);
index 5933c5f..52f3148 100644 (file)
@@ -26,11 +26,17 @@ import java.io.IOException;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.Set;
 
+import org.iotivity.cloud.accountserver.Constants;
 import org.iotivity.cloud.accountserver.db.TokenTable;
 import org.iotivity.cloud.accountserver.db.UserTable;
 import org.iotivity.cloud.base.exception.ServerException.InternalServerErrorException;
 import org.iotivity.cloud.util.Log;
+import org.reflections.Reflections;
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
 
 /**
  *
@@ -128,27 +134,31 @@ public class OAuthProviderFactory {
 
     /**
      * API for creating OAuth server object
-     * 
-     * @param authServer
-     *            authorization server
+     *
+     * @param authProviderName
+     *            Valid name of auth server.
      * @return OAuthServer - object to handle authorization
      * @throws Exception
      */
-    public boolean load(String authProvider) {
+    public boolean load(String authProviderName) {
 
-        String fileName = authProvider + ".jar";
-        File jarFile = new File(fileName);
+        File jarFile = new File(Constants.OAUTH_LIBRARIES_PATH + authProviderName + ".jar");
         URLClassLoader classLoader = null;
 
         try {
-            URL urls = new URL("jar:" + jarFile.toURI() + "!/");
+            URL jarUrl = new URL("jar:" + jarFile.toURI() + "!/");
+            URL[] urls = new URL[] { jarUrl, ClasspathHelper.forClass(this.getClass()) };
+            classLoader = new URLClassLoader(urls);
 
-            Log.d("urls: " + urls.toString());
+            String authProvider = this.getClass().getPackage().getName() + "." + authProviderName;
+            Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(urls)
+                    .setScanners(new SubTypesScanner(false)));
+            for (String type : reflections.getAllTypes())
+                if (type.equalsIgnoreCase(authProvider))
+                    authProvider = type;
 
-            classLoader = new URLClassLoader(new URL[] { urls });
             Class<?> authProviderClass = classLoader
-                    .loadClass(this.getClass().getPackage().getName() + "."
-                            + authProvider);
+                    .loadClass(authProvider);
 
             this.authProviderClass = authProviderClass;
             Object object = authProviderClass.newInstance();
index cc3f055..fd2da9d 100644 (file)
@@ -21,6 +21,7 @@
  */
 package org.iotivity.cloud.accountserver.resources.account;
 
+import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -72,7 +73,7 @@ public class AccountManager {
      * @param authCode
      *            Unique identifier of the resource which is obtained from an
      *            auth provider or a single sign-on (SSO) client
-     * @param authProvider
+     * @param authProviderName
      *            Provider name user for authentication (e.g., "Github")
      * @param options
      *            Optional field (e.g., region authserver url, apiserver url)
@@ -81,22 +82,20 @@ public class AccountManager {
      */
 
     public HashMap<String, Object> signUp(String did, String authCode,
-            String authProvider, Object options) {
-        boolean res = false;
+            String authProviderName, Object options) {
 
-        // check auth provider name not to be case-sensitive
-        authProvider = checkAuthProviderName(authProvider);
-        res = loadAuthProviderLibrary(authProvider);
+        authProviderName = checkAuthProviderName(authProviderName);
+        boolean res = loadAuthProviderLibrary(authProviderName);
 
         if (!res) {
             throw new InternalServerErrorException(
-                    authProvider + " library is not loaded");
+                    authProviderName + " library is not loaded");
         }
         String userUuid = null;
         // set token data
         TokenTable tokenInfo = requestAccessToken(authCode, options);
         tokenInfo.setDid(did);
-        tokenInfo.setProvider(authProvider);
+        tokenInfo.setProvider(authProviderName);
         Date currentTime = new Date();
         DateFormat transFormat = new SimpleDateFormat("yyyyMMddkkmm");
         tokenInfo.setIssuedtime(transFormat.format(currentTime));
@@ -104,10 +103,10 @@ public class AccountManager {
         // set user data
         UserTable userInfo = requestUserInfo(tokenInfo.getAccesstoken(),
                 options);
-        userInfo.setProvider(authProvider);
+        userInfo.setProvider(authProviderName);
 
         // check uuid
-        userUuid = findUuid(userInfo.getUserid(), authProvider);
+        userUuid = findUuid(userInfo.getUserid(), authProviderName);
 
         // store token information and user information to the DB
         // private group creation and store group information to the DB
@@ -239,21 +238,27 @@ public class AccountManager {
         return userUuid;
     }
 
-    private String checkAuthProviderName(String authProvider) {
+    private String checkAuthProviderName(String authProviderName) {
+        String libraryFileName = getValidFileName(Constants.OAUTH_LIBRARIES_PATH, authProviderName + ".jar");
+        if (libraryFileName == null) {
+            Log.w("OAuth 3rd party library " + authProviderName + " does not exist.");
+            return authProviderName;
+        }
+        return libraryFileName.substring(0, libraryFileName.length() - 4);
+    }
 
-        String authProviderName = null;
+    private String getValidFileName(String path, String filename) {
+        File file = new File(path + filename);
+        if(file.exists())
+            return filename;
 
-        if (authProvider.equalsIgnoreCase(Constants.GITHUB)) {
-            authProviderName = Constants.GITHUB;
-        } else if (authProvider.equalsIgnoreCase(Constants.SAMSUNG)) {
-            authProviderName = Constants.SAMSUNG;
-        } else if (authProvider.equalsIgnoreCase(Constants.GOOGLE))
-            authProviderName = Constants.GOOGLE;
-        else {
-            Log.w("Unsupported oauth provider : " + authProvider);
-        }
+        File parentFile = file.getAbsoluteFile().getParentFile();
+        if (parentFile.exists())
+            for (String directoryFile : parentFile.list())
+                if (directoryFile.equalsIgnoreCase(file.getName()))
+                    return directoryFile;
 
-        return authProviderName;
+        return null;
     }
 
     private String findUuid(String userId, String authProvider) {
@@ -335,10 +340,10 @@ public class AccountManager {
         return byteRootCert;
     }
 
-    private Boolean loadAuthProviderLibrary(String authProvider) {
+    private Boolean loadAuthProviderLibrary(String authProviderName) {
         mFactory = new OAuthProviderFactory();
 
-        return mFactory.load(authProvider);
+        return mFactory.load(authProviderName);
     }
 
     private TokenTable requestAccessToken(String authCode, Object options) {
@@ -475,17 +480,15 @@ public class AccountManager {
     }
 
     private TokenTable requestRefreshToken(String refreshToken,
-            String provider) {
+            String authProviderName) {
 
         if (mFactory == null) {
-
-            boolean res = false;
-            String authProvider = checkAuthProviderName(provider);
-            res = loadAuthProviderLibrary(authProvider);
+            authProviderName = checkAuthProviderName(authProviderName);
+            boolean res = loadAuthProviderLibrary(authProviderName);
 
             if (!res) {
                 throw new InternalServerErrorException(
-                        authProvider + " library is not loaded");
+                        authProviderName + " library is not loaded");
             }
         }
 
index 811fbbc..5f67c93 100644 (file)
@@ -125,10 +125,6 @@ public class AccountResource extends Resource {
 
     private IResponse handleGetSearch(IRequest request) {
 
-        if (!request.getUriPath().equals(Constants.ACCOUNT_SEARCH_FULL_URI)) {
-            throw new BadRequestException("invalid request uri");
-        }
-
         HashMap<String, List<String>> queryData = request.getUriQueryMap();
 
         if (queryData == null) {
@@ -137,9 +133,11 @@ public class AccountResource extends Resource {
 
         HashMap<String, Object> responsePayload = null;
 
+        String uriQuery = request.getUriQuery();
+
         // AND or OR operation to find users
-        if (request.getUriQuery().contains(",")) {
-            queryData = mAsManager.getQueryMap(request.getUriQuery(), ",");
+        if (uriQuery != null && uriQuery.contains(",")) {
+            queryData = mAsManager.getQueryMap(uriQuery, ",");
             responsePayload = (mAsManager.searchUserUsingCriteria(queryData,
                     SearchOperation.AND));
         } else {
index 42a8935..c302c83 100644 (file)
@@ -274,9 +274,6 @@ public class GroupAclManager {
         ArrayList<AceTable> getAceTableList = new ArrayList<>();
         ArrayList<HashMap<String, Object>> getAceList = AccountDBManager
                 .getInstance().selectRecord(Constants.ACE_TABLE, condition);
-        if (getAceList == null) {
-            return null;
-        }
         for (HashMap<String, Object> getAce : getAceList) {
             AceTable getAceTable = new AceTable();
             getAceTable = mTypeAceTable.convertMaptoObject(getAce, getAceTable);
index 820f62e..f675585 100644 (file)
@@ -51,7 +51,7 @@ public class GroupBrokerManager {
         return mGroupBrokerMgr;
     }
 
-    private class GroupSubscriber {
+    private static class GroupSubscriber {
         GroupSubscriber(Device subscriber, IRequest request) {
             mSubscriber = subscriber;
             mRequest = request;
index 1a005e7..79aa494 100644 (file)
@@ -567,6 +567,9 @@ public class GroupManager {
         if (groupTable == null) {
             throw new BadRequestException("group " + gid + " does not exist");
         }
+        if (groupTable.getMembers() == null) {
+            throw new BadRequestException("there are no members in the group");
+        }
         if (!groupTable.getMembers().contains(mid)) {
             throw new BadRequestException("uid is not a member of the group");
         }
index 5601ce3..a401cd1 100644 (file)
@@ -193,6 +193,9 @@ public class GroupResource extends Resource {
 
     private IResponse handleGroupPostRequest(IRequest request)
             throws ServerException {
+        if (request.getPayload() == null) {
+            throw new BadRequestException("payload is null");
+        }
         HashMap<String, Object> payloadData = mCbor
                 .parsePayloadFromCbor(request.getPayload(), HashMap.class);
 
@@ -400,6 +403,12 @@ public class GroupResource extends Resource {
                 Constants.KEYFIELD_GROUP_MEMBERS), queryMap);
 
         String uid = queryMap.get(Constants.REQ_UUID_ID).get(0);
+
+        if (uid == null || uid.isEmpty()) {
+            throw new BadRequestException(
+                    Constants.REQ_UUID_ID + " is null or empty");
+        }
+
         if (!uid.equals(
                 queryMap.get(Constants.KEYFIELD_GROUP_MEMBERS).get(0))) {
             throw new BadRequestException(
@@ -407,11 +416,6 @@ public class GroupResource extends Resource {
                             + Constants.KEYFIELD_GROUP_MEMBERS + "query value");
         }
 
-        if (uid == null || uid.isEmpty()) {
-            throw new BadRequestException(
-                    Constants.REQ_UUID_ID + " is null or empty");
-        }
-
         String gid = request.getUriPathSegments()
                 .get(getUriPathSegments().size());
 
@@ -444,6 +448,12 @@ public class GroupResource extends Resource {
                 Constants.KEYFIELD_GROUP_OWNER), queryMap);
 
         String uid = queryMap.get(Constants.REQ_UUID_ID).get(0);
+
+        if (uid == null || uid.isEmpty()) {
+            throw new BadRequestException(
+                    Constants.REQ_UUID_ID + " is null or empty");
+        }
+
         if (!uid.equals(queryMap.get(Constants.KEYFIELD_GROUP_OWNER).get(0))) {
             throw new BadRequestException(
                     Constants.REQ_UUID_ID + "query value should be equal to "
@@ -451,11 +461,6 @@ public class GroupResource extends Resource {
                             + "query value to delete group");
         }
 
-        if (uid == null || uid.isEmpty()) {
-            throw new BadRequestException(
-                    Constants.REQ_UUID_ID + " is null or empty");
-        }
-
         String gid = request.getUriPathSegments()
                 .get(getUriPathSegments().size());
 
index 4a8581a..d54ed0c 100644 (file)
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 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.cloud.accountserver.resources.acl.id;
-
-import java.util.List;
-
-/**
- *
- * This class holds Ace of Acl.
- *
- */
-
-public class Ace {
-
-    String aceid;
-    String subjectuuid;
-    int stype;
-    int permission;
-    List<AceResource> resources;
-    List<String> validity;
-
-    public Ace() {
-
-    }
-
-    public Ace(String aceid, String subjectuuid, int stype, int permission,
-            List<AceResource> resources, List<String> validity) {
-
-        this.aceid = aceid;
-        this.subjectuuid = subjectuuid;
-        this.stype = stype;
-        this.permission = permission;
-        this.resources = resources;
-        this.validity = validity;
-    }
-
-    public String getAceid() {
-        return aceid;
-    }
-
-    public void setAceid(String aceid) {
-        this.aceid = aceid;
-    }
-
-    public String getSubjectuuid() {
-        return subjectuuid;
-    }
-
-    public void setSubjectuuid(String subjectuuid) {
-        this.subjectuuid = subjectuuid;
-    }
-
-    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<AceResource> getResources() {
-        return resources;
-    }
-
-    public void setResources(List<AceResource> resources) {
-        this.resources = resources;
-    }
-
-    public List<String> getValidity() {
-        return validity;
-    }
-
-    public void setValidity(List<String> validity) {
-        this.validity = validity;
-    }
-
-}
+/*\r
+ * //******************************************************************\r
+ * //\r
+ * // Copyright 2016 Samsung Electronics All Rights Reserved.\r
+ * //\r
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ * //\r
+ * // Licensed under the Apache License, Version 2.0 (the "License");\r
+ * // you may not use this file except in compliance with the License.\r
+ * // You may obtain a copy of the License at\r
+ * //\r
+ * //      http://www.apache.org/licenses/LICENSE-2.0\r
+ * //\r
+ * // Unless required by applicable law or agreed to in writing, software\r
+ * // distributed under the License is distributed on an "AS IS" BASIS,\r
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * // See the License for the specific language governing permissions and\r
+ * // limitations under the License.\r
+ * //\r
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ */\r
+package org.iotivity.cloud.accountserver.resources.acl.id;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ *\r
+ * This class holds Ace of Acl.\r
+ *\r
+ */\r
+\r
+public class Ace {\r
+\r
+    String aceid;\r
+    String subjectuuid;\r
+    int stype;\r
+    int permission;\r
+    List<AceResource> resources;\r
+    List<String> validity;\r
+\r
+    public Ace() {\r
+\r
+    }\r
+\r
+    public Ace(String aceid, String subjectuuid, int stype, int permission,\r
+            List<AceResource> resources, List<String> validity) {\r
+\r
+        this.aceid = aceid;\r
+        this.subjectuuid = subjectuuid;\r
+        this.stype = stype;\r
+        this.permission = permission;\r
+        this.resources = resources;\r
+        this.validity = validity;\r
+    }\r
+\r
+    public String getAceid() {\r
+        return aceid;\r
+    }\r
+\r
+    public void setAceid(String aceid) {\r
+        this.aceid = aceid;\r
+    }\r
+\r
+    public String getSubjectuuid() {\r
+        return subjectuuid;\r
+    }\r
+\r
+    public void setSubjectuuid(String subjectuuid) {\r
+        this.subjectuuid = subjectuuid;\r
+    }\r
+\r
+    public int getStype() {\r
+        return stype;\r
+    }\r
+\r
+    public void setStype(int stype) {\r
+        this.stype = stype;\r
+    }\r
+\r
+    public int getPermission() {\r
+        return permission;\r
+    }\r
+\r
+    public void setPermission(int permission) {\r
+        this.permission = permission;\r
+    }\r
+\r
+    public List<AceResource> getResources() {\r
+        return resources;\r
+    }\r
+\r
+    public void setResources(List<AceResource> resources) {\r
+        this.resources = resources;\r
+    }\r
+\r
+    public List<String> getValidity() {\r
+        return validity;\r
+    }\r
+\r
+    public void setValidity(List<String> validity) {\r
+        this.validity = validity;\r
+    }\r
+\r
+}\r
index d51c402..fb36c35 100644 (file)
@@ -1,71 +1,71 @@
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 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.cloud.accountserver.resources.acl.id;
-
-import java.util.List;
-
-/**
- *
- * This class holds resource of Ace.
- *
- */
-public class AceResource {
-
-    String href;
-    List<String> rt;
-    List<String> oicif;
-
-    public AceResource() {
-
-    }
-
-    public AceResource(String href, List<String> rt, List<String> oicif) {
-        this.href = href;
-        this.rt = rt;
-        this.oicif = oicif;
-    }
-
-    public String getHref() {
-        return href;
-    }
-
-    public void setHref(String href) {
-        this.href = href;
-    }
-
-    public List<String> getRt() {
-        return rt;
-    }
-
-    public void setRt(List<String> rt) {
-        this.rt = rt;
-    }
-
-    public List<String> getOicif() {
-        return oicif;
-    }
-
-    public void setOicif(List<String> oicif) {
-        this.oicif = oicif;
-    }
-
-}
+/*\r
+ * //******************************************************************\r
+ * //\r
+ * // Copyright 2016 Samsung Electronics All Rights Reserved.\r
+ * //\r
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ * //\r
+ * // Licensed under the Apache License, Version 2.0 (the "License");\r
+ * // you may not use this file except in compliance with the License.\r
+ * // You may obtain a copy of the License at\r
+ * //\r
+ * //      http://www.apache.org/licenses/LICENSE-2.0\r
+ * //\r
+ * // Unless required by applicable law or agreed to in writing, software\r
+ * // distributed under the License is distributed on an "AS IS" BASIS,\r
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * // See the License for the specific language governing permissions and\r
+ * // limitations under the License.\r
+ * //\r
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ */\r
+package org.iotivity.cloud.accountserver.resources.acl.id;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ *\r
+ * This class holds resource of Ace.\r
+ *\r
+ */\r
+public class AceResource {\r
+\r
+    String href;\r
+    List<String> rt;\r
+    List<String> oicif;\r
+\r
+    public AceResource() {\r
+\r
+    }\r
+\r
+    public AceResource(String href, List<String> rt, List<String> oicif) {\r
+        this.href = href;\r
+        this.rt = rt;\r
+        this.oicif = oicif;\r
+    }\r
+\r
+    public String getHref() {\r
+        return href;\r
+    }\r
+\r
+    public void setHref(String href) {\r
+        this.href = href;\r
+    }\r
+\r
+    public List<String> getRt() {\r
+        return rt;\r
+    }\r
+\r
+    public void setRt(List<String> rt) {\r
+        this.rt = rt;\r
+    }\r
+\r
+    public List<String> getOicif() {\r
+        return oicif;\r
+    }\r
+\r
+    public void setOicif(List<String> oicif) {\r
+        this.oicif = oicif;\r
+    }\r
+\r
+}\r
index 62dfc3e..3f06327 100644 (file)
 package org.iotivity.cloud.accountserver.resources.acl.id;
 
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
-import java.util.UUID;
 import java.util.ListIterator;
+import java.util.UUID;
 
 import org.iotivity.cloud.accountserver.Constants;
 import org.iotivity.cloud.accountserver.db.AccountDBManager;
@@ -48,11 +45,11 @@ import org.iotivity.cloud.util.Log;
 
 public class Acl {
 
-    private Cbor<HashMap<String, Object>>  mCbor      = new Cbor<>();
-    private String                         mAclid     = null;
-    private String                         mOid       = null;
-    private String                         mDi        = null;
-    private TypeCastingManager<AclTable> mTypeAcl = new TypeCastingManager<>();
+    private Cbor<HashMap<String, Object>> mCbor    = new Cbor<>();
+    private String                        mAclid   = null;
+    private String                        mOid     = null;
+    private String                        mDi      = null;
+    private TypeCastingManager<AclTable>  mTypeAcl = new TypeCastingManager<>();
 
     public Acl(String aclid) {
         mAclid = aclid;
@@ -64,138 +61,140 @@ public class Acl {
         mDi = di;
     }
 
-    private class AclSubscriber {
+    private static class AclSubscriber {
         AclSubscriber(Device subscriber, IRequest request) {
             mSubscriber = subscriber;
             mRequest = request;
         }
 
-        public Device mSubscriber;
+        public Device   mSubscriber;
         public IRequest mRequest;
     }
 
-    private HashMap<String, AclSubscriber> mSubscribers  = new HashMap<>();
+    private HashMap<String, AclSubscriber> mSubscribers = new HashMap<>();
 
     public static String valueOf(Object object) {
         return (object == null) ? "" : object.toString();
     }
 
     @SuppressWarnings("unchecked")
-        public static AclTable convertMaptoAclObject(HashMap<String, Object> aclMap) {
-            AclTable aclTable = new AclTable();
-            try {
-                aclTable.setAclid(valueOf(aclMap.get(Constants.KEYFIELD_ACLID)));
-                aclTable.setDi(valueOf(aclMap.get(Constants.KEYFIELD_DI)));
-                aclTable.setOid(valueOf(aclMap.get(Constants.REQ_OWNER_ID)));
-                aclTable.setRowneruuid(valueOf(aclMap.get(Constants.REQ_ROWNER_ID)));
-
-                List<Ace> aceList = new ArrayList<Ace>();
-
-                List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) aclMap
+    public static AclTable convertMaptoAclObject(
+            HashMap<String, Object> aclMap) {
+        AclTable aclTable = new AclTable();
+        try {
+            aclTable.setAclid(valueOf(aclMap.get(Constants.KEYFIELD_ACLID)));
+            aclTable.setDi(valueOf(aclMap.get(Constants.KEYFIELD_DI)));
+            aclTable.setOid(valueOf(aclMap.get(Constants.REQ_OWNER_ID)));
+            aclTable.setRowneruuid(
+                    valueOf(aclMap.get(Constants.REQ_ROWNER_ID)));
+
+            List<Ace> aceList = new ArrayList<Ace>();
+
+            List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) aclMap
                     .get(Constants.REQ_ACL_LIST);
 
-                if (aclist == null) {
-                    return aclTable;
-                }
+            if (aclist == null) {
+                return aclTable;
+            }
 
-                for (HashMap<String, Object> eachAce : aclist) {
+            for (HashMap<String, Object> eachAce : aclist) {
 
-                    Ace ace = new Ace();
+                Ace ace = new Ace();
 
-                    ace.setAceid(valueOf(eachAce.get(Constants.REQ_ACE_ID)));
-                    ace.setSubjectuuid(valueOf(eachAce
-                                .get(Constants.KEYFIELD_ACE_SUBJECT_ID)));
-                    ace.setStype(Integer.valueOf(eachAce.get(
-                                    Constants.KEYFIELD_ACE_SUBJECT_TYPE).toString()));
-                    ace.setPermission(Integer.valueOf(eachAce.get(
-                                    Constants.KEYFIELD_ACE_PERMISSION).toString()));
+                ace.setAceid(valueOf(eachAce.get(Constants.REQ_ACE_ID)));
+                ace.setSubjectuuid(valueOf(
+                        eachAce.get(Constants.KEYFIELD_ACE_SUBJECT_ID)));
+                ace.setStype(Integer.valueOf(eachAce
+                        .get(Constants.KEYFIELD_ACE_SUBJECT_TYPE).toString()));
+                ace.setPermission(Integer.valueOf(eachAce
+                        .get(Constants.KEYFIELD_ACE_PERMISSION).toString()));
 
-                    Object validity = eachAce.get(Constants.KEYFIELD_ACE_VALIDITY);
-                    if (validity != null) {
-                        ace.setValidity((List<String>) validity);
-                    }
+                Object validity = eachAce.get(Constants.KEYFIELD_ACE_VALIDITY);
+                if (validity != null) {
+                    ace.setValidity((List<String>) validity);
+                }
 
-                    List<AceResource> resourceLst = new ArrayList<AceResource>();
-                    List<HashMap<String, Object>> resourceList = (List<HashMap<String, Object>>) eachAce
+                List<AceResource> resourceLst = new ArrayList<AceResource>();
+                List<HashMap<String, Object>> resourceList = (List<HashMap<String, Object>>) eachAce
                         .get(Constants.KEYFIELD_ACE_RESOURCE);
-                    for (HashMap<String, Object> resrouce : resourceList) {
+                for (HashMap<String, Object> resrouce : resourceList) {
 
-                        AceResource aceResource = new AceResource();
-                        aceResource.setHref(valueOf(resrouce
-                                    .get(Constants.KEYFIELD_ACE_RESOURCE_HREF)));
-                        List<String> rtList = (List<String>) resrouce
+                    AceResource aceResource = new AceResource();
+                    aceResource.setHref(valueOf(resrouce
+                            .get(Constants.KEYFIELD_ACE_RESOURCE_HREF)));
+                    List<String> rtList = (List<String>) resrouce
                             .get(Constants.KEYFIELD_ACE_RESOURCE_RT);
-                        aceResource.setRt(rtList);
-                        List<String> ifList = (List<String>) resrouce
+                    aceResource.setRt(rtList);
+                    List<String> ifList = (List<String>) resrouce
                             .get(Constants.KEYFIELD_ACE_RESOURCE_IF);
-                        aceResource.setOicif(ifList);
+                    aceResource.setOicif(ifList);
 
-                        resourceLst.add(aceResource);
-                    }
-                    ace.setResources(resourceLst);
+                    resourceLst.add(aceResource);
+                }
+                ace.setResources(resourceLst);
 
-                    aceList.add(ace);
+                aceList.add(ace);
 
-                }
-                aclTable.setAclist(aceList);
-            } catch (Exception e) {
-                throw new InternalServerErrorException(
-                        "Map to Acl Object casting error " + e.getMessage());
             }
-            return aclTable;
-
+            aclTable.setAclist(aceList);
+        } catch (Exception e) {
+            throw new InternalServerErrorException(
+                    "Map to Acl Object casting error " + e.getMessage());
         }
+        return aclTable;
+
+    }
 
     @SuppressWarnings("unchecked")
 
-        public List<HashMap<String, Object>> addACE(List<HashMap<String, Object>> aclist) {
-            Log.v("IN addACE");
-            HashMap<String, Object> hashmap = AccountDBManager.getInstance()
+    public List<HashMap<String, Object>> addACE(
+            List<HashMap<String, Object>> aclist) {
+        Log.v("IN addACE");
+        HashMap<String, Object> hashmap = AccountDBManager.getInstance()
                 .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
-            if (hashmap == null) {
-                throw new BadRequestException("aclid is invalid");
-            }
-            List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
+        if (hashmap == null) {
+            throw new BadRequestException("aclid is invalid");
+        }
+        List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
                 .get(Constants.REQ_ACL_LIST);
 
-
-            ListIterator<HashMap<String, Object>> iterator = aclist.listIterator();
-            while (iterator.hasNext()) {
-                HashMap<String, Object> aceMap = iterator.next();
-                if (aceMap.get(Constants.KEYFIELD_ACE_SUBJECT_ID)
-                        .equals(hashmap.get(Constants.REQ_OWNER_ID))) {
-                    // remove current iterator
-                    iterator.remove();
-                    continue;
-                }
-                aceMap.put(Constants.REQ_ACE_ID, UUID.randomUUID().toString());
+        ListIterator<HashMap<String, Object>> iterator = aclist.listIterator();
+        while (iterator.hasNext()) {
+            HashMap<String, Object> aceMap = iterator.next();
+            if (aceMap.get(Constants.KEYFIELD_ACE_SUBJECT_ID)
+                    .equals(hashmap.get(Constants.REQ_OWNER_ID))) {
+                // remove current iterator
+                iterator.remove();
+                continue;
             }
+            aceMap.put(Constants.REQ_ACE_ID, UUID.randomUUID().toString());
+        }
 
-            List<HashMap<String, Object>> newAcList = new ArrayList<HashMap<String, Object>>(
-                    aclist);
+        List<HashMap<String, Object>> newAcList = new ArrayList<HashMap<String, Object>>(
+                aclist);
 
-            if (aclDbList != null) {
-                newAcList.addAll(aclDbList);
-            }
-            hashmap.put(Constants.REQ_ACL_LIST, newAcList);
-            AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE,
-                    hashmap);
-            notifyToSubscriber(getResponsePayload(true));
-            Log.v("OUT addACE");
-            return aclist;
+        if (aclDbList != null) {
+            newAcList.addAll(aclDbList);
         }
+        hashmap.put(Constants.REQ_ACL_LIST, newAcList);
+        AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE,
+                hashmap);
+        notifyToSubscriber(getResponsePayload(true));
+        Log.v("OUT addACE");
+        return aclist;
+    }
 
     public HashMap<String, Object> getACE(String aceid) {
         HashMap<String, Object> hashmap = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
         if (hashmap == null) {
             throw new BadRequestException("aclid is invalid");
         }
 
         List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
-            .get(Constants.REQ_ACL_LIST);
+                .get(Constants.REQ_ACL_LIST);
         ListIterator<HashMap<String, Object>> iterator = aclDbList
-            .listIterator();
+                .listIterator();
         while (iterator.hasNext()) {
             HashMap<String, Object> aceMap = iterator.next();
             if (aceMap.get(Constants.REQ_ACE_ID).equals(aceid)) {
@@ -205,17 +204,18 @@ public class Acl {
         }
         throw new BadRequestException("aceid is invalid");
     }
+
     public boolean isValidAceId(String aceid) {
         HashMap<String, Object> hashmap = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
         if (hashmap == null) {
             return false;
         }
 
         List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
-            .get(Constants.REQ_ACL_LIST);
+                .get(Constants.REQ_ACL_LIST);
         ListIterator<HashMap<String, Object>> iterator = aclDbList
-            .listIterator();
+                .listIterator();
         while (iterator.hasNext()) {
             HashMap<String, Object> aceMap = iterator.next();
             if (aceMap.get(Constants.REQ_ACE_ID).equals(aceid)) {
@@ -224,17 +224,20 @@ public class Acl {
         }
         return false;
     }
+
     public void updateACE(String aceid, HashMap<String, Object> ace) {
         Log.v("IN updateACE");
 
         HashMap<String, Object> hashmap = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
 
-        List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap.get(Constants.REQ_ACL_LIST);
+        List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
+                .get(Constants.REQ_ACL_LIST);
 
         ace.put(Constants.REQ_ACE_ID, aceid);
 
-        ListIterator<HashMap<String, Object>> iterator = aclDbList.listIterator();
+        ListIterator<HashMap<String, Object>> iterator = aclDbList
+                .listIterator();
         while (iterator.hasNext()) {
             HashMap<String, Object> aceMap = iterator.next();
             if (aceMap.get(Constants.REQ_ACE_ID).equals(aceid)) {
@@ -245,7 +248,8 @@ public class Acl {
         }
 
         hashmap.put(Constants.REQ_ACL_LIST, aclDbList);
-        AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE, hashmap);
+        AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE,
+                hashmap);
         notifyToSubscriber(getResponsePayload(true));
         Log.v("OUT updateACE");
 
@@ -254,13 +258,13 @@ public class Acl {
     public void deleteACE(String aceid) {
 
         HashMap<String, Object> hashmap = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
 
         List<HashMap<String, Object>> aclDbList = (List<HashMap<String, Object>>) hashmap
-            .get(Constants.REQ_ACL_LIST);
-
+                .get(Constants.REQ_ACL_LIST);
 
-        ListIterator<HashMap<String, Object>> iterator = aclDbList.listIterator();
+        ListIterator<HashMap<String, Object>> iterator = aclDbList
+                .listIterator();
         while (iterator.hasNext()) {
             HashMap<String, Object> aceMap = iterator.next();
             if (aceMap.get(Constants.REQ_ACE_ID).equals(aceid)) {
@@ -280,7 +284,7 @@ public class Acl {
         AclTable aclTable = getAclTable();
         aclTable.setAclist(null);
         AccountDBManager.getInstance().updateRecord(Constants.ACL_TABLE,
-            mTypeAcl.convertObjectToMap(aclTable));
+                mTypeAcl.convertObjectToMap(aclTable));
         notifyToSubscriber(getResponsePayload(true));
     }
 
@@ -314,7 +318,7 @@ public class Acl {
         String mDi = aclTable.getDi();
         if (!mDi.equals(di)) {
             throw new UnAuthorizedException(
-                di + "is not Device ID of this ACL");
+                    di + "is not Device ID of this ACL");
         }
     }
 
@@ -323,31 +327,30 @@ public class Acl {
         synchronized (mSubscribers) {
 
             Iterator<String> iterator = mSubscribers.keySet().iterator();
-            while(iterator.hasNext()) {
+            while (iterator.hasNext()) {
                 String key = iterator.next();
                 AclSubscriber aclSubscriber = mSubscribers.get(key);
                 aclSubscriber.mSubscriber.sendResponse(
-                    MessageBuilder.createResponse(aclSubscriber.mRequest,
-                        ResponseStatus.CONTENT,
-                        ContentFormat.APPLICATION_CBOR,
-                        mCbor.encodingPayloadToCbor(
-                            notifyBytePayloadData)));
+                        MessageBuilder.createResponse(aclSubscriber.mRequest,
+                                ResponseStatus.CONTENT,
+                                ContentFormat.APPLICATION_CBOR,
+                                mCbor.encodingPayloadToCbor(
+                                        notifyBytePayloadData)));
             }
         }
     }
 
     private AclTable getAclTable() {
         AclTable getAclTable = new AclTable();
-        getAclTable = convertMaptoAclObject(
-                AccountDBManager.getInstance().selectRecord(
-                    Constants.ACL_TABLE, getCondition()).get(0));
+        getAclTable = convertMaptoAclObject(AccountDBManager.getInstance()
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0));
         return getAclTable;
     }
 
     private HashMap<String, Object> getAclTablePayLoad() {
         HashMap<String, Object> aclPayload = new HashMap<>();
         aclPayload = AccountDBManager.getInstance()
-            .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
+                .selectRecord(Constants.ACL_TABLE, getCondition()).get(0);
         return aclPayload;
     }
 
@@ -361,5 +364,4 @@ public class Acl {
         return condition;
     }
 
-
 }
index f212d62..a7e4215 100644 (file)
@@ -88,10 +88,14 @@ public class AclResource extends Resource {
             throws ServerException {
 
         if (getUriPathSegments().containsAll(request.getUriPathSegments())) {
-            String oid = request.getUriQueryMap().get(Constants.REQ_OWNER_ID)
-                    .get(0);
-            String di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID)
-                    .get(0);
+            HashMap<String, List<String>> queryMap = request.getUriQueryMap();
+
+            checkQueryException(Arrays.asList(Constants.REQ_OWNER_ID,
+                    Constants.REQ_DEVICE_ID), queryMap);
+
+            String oid = queryMap.get(Constants.REQ_OWNER_ID).get(0);
+            String di = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
+
             if (mAclManager.getAclid(di) == null) {
                 return MessageBuilder.createResponse(request,
                         ResponseStatus.CREATED, ContentFormat.APPLICATION_CBOR,
@@ -107,37 +111,57 @@ public class AclResource extends Resource {
     }
 
     private IResponse handlePostRequest(IRequest request)
-        throws ServerException {
+            throws ServerException {
 
-            HashMap<String, Object> payloadData = mCbor
+        if (request.getPayload() == null) {
+            throw new BadRequestException("payload is null");
+        }
+
+        HashMap<String, Object> payloadData = mCbor
                 .parsePayloadFromCbor(request.getPayload(), HashMap.class);
 
-            if (null !=request.getUriQueryMap()) {
-                String aclid = request.getUriPathSegments().get(getUriPathSegments().size());
-                String aceid = request.getUriQueryMap().get(Constants.REQ_ACE_ID).get(0);
-                List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) payloadData
+        HashMap<String, List<String>> queryMap = request.getUriQueryMap();
+
+        if (null != queryMap) {
+            String aclid = request.getUriPathSegments()
+                    .get(getUriPathSegments().size());
+
+            checkQueryException(Constants.REQ_ACE_ID, queryMap);
+
+            String aceid = queryMap.get(Constants.REQ_ACE_ID).get(0);
+
+            checkPayloadException(Constants.REQ_ACL_LIST, payloadData);
+
+            List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) payloadData
                     .get(Constants.REQ_ACL_LIST);
-                mAclManager.updateACE(aclid, aceid, aclist.get(0));
-                return MessageBuilder.createResponse(request, ResponseStatus.CHANGED);
+
+            if (aclist == null) {
+                throw new BadRequestException(
+                        Constants.REQ_ACL_LIST + " payload value is null");
             }
-            else if (!getUriPathSegments().containsAll(request.getUriPathSegments())) {
-                String aclid = request.getUriPathSegments().get(getUriPathSegments().size());
-
-                List<HashMap<String, Object>> aclist = null;
-                if (!payloadData.containsKey(Constants.REQ_ACL_LIST)) {
-                    throw new BadRequestException("aclist not included in payload");
-                }
-                aclist = (List<HashMap<String, Object>>) payloadData
-                    .get(Constants.REQ_ACL_LIST);
-                aclist= mAclManager.addAclACE(aclid, aclist);
-                payloadData.put(Constants.REQ_ACL_LIST, aclist);
-                return MessageBuilder.createResponse(request, ResponseStatus.CHANGED,
-                        ContentFormat.APPLICATION_CBOR,
-                        mCbor.encodingPayloadToCbor(payloadData));
+
+            mAclManager.updateACE(aclid, aceid, aclist.get(0));
+            return MessageBuilder.createResponse(request,
+                    ResponseStatus.CHANGED);
+        } else if (!getUriPathSegments()
+                .containsAll(request.getUriPathSegments())) {
+            String aclid = request.getUriPathSegments()
+                    .get(getUriPathSegments().size());
+
+            List<HashMap<String, Object>> aclist = null;
+            if (!payloadData.containsKey(Constants.REQ_ACL_LIST)) {
+                throw new BadRequestException("aclist not included in payload");
             }
-            throw new BadRequestException("uriPath is invalid");
+            aclist = (List<HashMap<String, Object>>) payloadData
+                    .get(Constants.REQ_ACL_LIST);
+            aclist = mAclManager.addAclACE(aclid, aclist);
+            payloadData.put(Constants.REQ_ACL_LIST, aclist);
+            return MessageBuilder.createResponse(request,
+                    ResponseStatus.CHANGED, ContentFormat.APPLICATION_CBOR,
+                    mCbor.encodingPayloadToCbor(payloadData));
         }
-
+        throw new BadRequestException("uriPath is invalid");
+    }
 
     @SuppressWarnings("unchecked")
 
@@ -146,8 +170,10 @@ public class AclResource extends Resource {
 
         HashMap<String, Object> responsePayload = null;
         String di = null;
-
+        HashMap<String, List<String>> queryMap = request.getUriQueryMap();
         if (getUriPathSegments().containsAll(request.getUriPathSegments())) {
+            checkQueryException(Arrays.asList(Constants.REQ_DEVICE_ID),
+                    queryMap);
             di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID).get(0);
             if (di == null) {
                 throw new PreconditionFailedException("di is invalid");
@@ -161,14 +187,16 @@ public class AclResource extends Resource {
                     responsePayload = mAclManager.getAclInfo(aclid);
                     break;
                 case SUBSCRIBE:
-                    di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID)
-                            .get(0);
+                    checkQueryException(Arrays.asList(Constants.REQ_DEVICE_ID),
+                            queryMap);
+                    di = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
                     responsePayload = mAclManager.addAclSubscriber(aclid, di,
                             srcDevice, request);
                     break;
                 case UNSUBSCRIBE:
-                    di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID)
-                            .get(0);
+                    checkQueryException(Arrays.asList(Constants.REQ_DEVICE_ID),
+                            queryMap);
+                    di = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
                     responsePayload = mAclManager.removeAclSubscriber(aclid,
                             di);
                     break;
@@ -200,17 +228,14 @@ public class AclResource extends Resource {
             aclid = request.getUriPathSegments()
                     .get(getUriPathSegments().size());
 
-            if (request.getUriQueryMap() == null)
-            {
+            if (request.getUriQueryMap() == null) {
                 mAclManager.deleteAclAclist(aclid);
-            }
-            else if (request.getUriQueryMap()
+            } else if (request.getUriQueryMap()
                     .containsKey(Constants.REQ_ACE_ID)) {
-                String aceid = request.getUriQueryMap().get(Constants.REQ_ACE_ID)
-                        .get(0);
+                String aceid = request.getUriQueryMap()
+                        .get(Constants.REQ_ACE_ID).get(0);
                 mAclManager.deleteAclACE(aclid, aceid);
-            }
-            else {
+            } else {
                 throw new BadRequestException("uriPath is invalid");
             }
         }
index afcc6aa..1e46db8 100644 (file)
@@ -48,7 +48,7 @@ public class InviteManager {
 
     private TypeCastingManager<InviteTable> mTypeInvite = new TypeCastingManager<>();
 
-    private class InviteSubscriber {
+    private static class InviteSubscriber {
         InviteSubscriber(Device subscriber, IRequest request) {
             mSubscriber = subscriber;
             mRequest = request;
@@ -110,6 +110,10 @@ public class InviteManager {
         List<HashMap<String, Object>> getInviteList = AccountDBManager
                 .getInstance().selectRecord(Constants.INVITE_TABLE, condition);
 
+        if (getInviteList == null || getInviteList.isEmpty()) {
+            throw new BadRequestException("mid or gid is not valid");
+        }
+
         ArrayList<String> uidList = new ArrayList<>();
         for (HashMap<String, Object> getInvite : getInviteList) {
             getInviteTable = mTypeInvite.convertMaptoObject(getInvite,
index 50e0720..bc83ef3 100644 (file)
@@ -32,11 +32,9 @@ import org.iotivity.cloud.accountserver.db.AclTable;
 import org.iotivity.cloud.accountserver.resources.acl.id.Ace;
 import org.iotivity.cloud.accountserver.resources.acl.id.AceResource;
 import org.iotivity.cloud.accountserver.resources.acl.id.Acl;
-import org.iotivity.cloud.accountserver.util.TypeCastingManager;
 import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.exception.ServerException;
 import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
-import org.iotivity.cloud.base.exception.ServerException.PreconditionFailedException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
@@ -51,119 +49,123 @@ public class AclVerifyResource extends Resource {
 
     public AclVerifyResource() {
         super(Arrays.asList(Constants.PREFIX_OIC, Constants.ACL_URI,
-                    Constants.VERIFY_URI));
+                Constants.VERIFY_URI));
     }
 
     @Override
-        public void onDefaultRequestReceived(Device srcDevice, IRequest request)
-        throws ServerException {
-
-            IResponse response = null;
-
-            switch (request.getMethod()) {
-                case GET:
-                    response = handleGetRequest(request);
-                    break;
-                default:
-                    throw new BadRequestException(request.getMethod()
-                            + " request type is not supported");
-            }
-
-            srcDevice.sendResponse(response);
+    public void onDefaultRequestReceived(Device srcDevice, IRequest request)
+            throws ServerException {
+
+        IResponse response = null;
+
+        switch (request.getMethod()) {
+            case GET:
+                response = handleGetRequest(request);
+                break;
+            default:
+                throw new BadRequestException(
+                        request.getMethod() + " request type is not supported");
         }
 
+        srcDevice.sendResponse(response);
+    }
+
     private boolean checkPermission(int permissionValue, String rme)
-        throws ServerException {
-            Permission per = null;
-            int rm_value = 0;
-            if (rme.equals("get")) {
-                per = Permission.Read;
-            } else if (rme.equals("post")) {
-                per = Permission.Update;
-            } else if (rme.equals("delete")) {
-                per = Permission.Delete;
-            }
-            if (per != null) {
-                rm_value = per.getValue();
-            }
-            // bit and operation
-            return ((permissionValue & rm_value) == rm_value);
+            throws ServerException {
+        Permission per = null;
+        int rm_value = 0;
+        if (rme.equals("get")) {
+            per = Permission.Read;
+        } else if (rme.equals("post")) {
+            per = Permission.Update;
+        } else if (rme.equals("delete")) {
+            per = Permission.Delete;
+        }
+        if (per != null) {
+            rm_value = per.getValue();
         }
+        // bit and operation
+        return ((permissionValue & rm_value) == rm_value);
+    }
 
     private boolean checkResourceUri(List<AceResource> aceResources, String uri)
-        throws ServerException {
-            for (AceResource aceResource : aceResources) {
-                if (aceResource.getHref().trim().equals("*") || aceResource.getHref().equals(uri)) {
-                    return true;
-                }
+            throws ServerException {
+        for (AceResource aceResource : aceResources) {
+            if (aceResource.getHref().trim().equals("*")
+                    || aceResource.getHref().equals(uri)) {
+                return true;
             }
-            return false;
         }
+        return false;
+    }
 
     private boolean verifyAcl(String sid, String di, String rm, String uri)
-        throws ServerException {
+            throws ServerException {
 
-            HashMap<String, Object> condition = new HashMap<>();
-            condition.put(Constants.KEYFIELD_DI, di);
+        HashMap<String, Object> condition = new HashMap<>();
+        condition.put(Constants.KEYFIELD_DI, di);
 
-            // Query AclTable with condition deviceId(di)
-            ArrayList<HashMap<String, Object>> aclResult = AccountDBManager
+        // Query AclTable with condition deviceId(di)
+        ArrayList<HashMap<String, Object>> aclResult = AccountDBManager
                 .getInstance().selectRecord(Constants.ACL_TABLE, condition);
 
-            // if aclResult size is zero then (di) does not exist
-            if (aclResult == null || aclResult.size() == 0) {
-                return false;
-            }
+        // if aclResult size is zero then (di) does not exist
+        if (aclResult == null || aclResult.size() == 0) {
+            return false;
+        }
 
-            for (HashMap<String, Object> eachAclMap : aclResult) {
+        for (HashMap<String, Object> eachAclMap : aclResult) {
 
-                AclTable aclTable = Acl.convertMaptoAclObject(eachAclMap);
-                if (aclTable.getOid().equals(sid)) {
-                    return true;
-                }
-                if (aclTable.getAclist() == null) {
-                    return false;
-                }
+            AclTable aclTable = Acl.convertMaptoAclObject(eachAclMap);
+            if (aclTable.getOid().equals(sid)) {
+                return true;
+            }
+            if (aclTable.getAclist() == null) {
+                return false;
+            }
 
-                for (Ace ace : aclTable.getAclist()) {
-                    if (ace.getSubjectuuid().equals(sid)) {
-                        // check permission matches
-                        if (checkPermission(ace.getPermission(), rm.toLowerCase())) {
-                            // check resource uri matches
-                            if (checkResourceUri(ace.getResources(), uri)) {
-                                return true;
-                            }
+            for (Ace ace : aclTable.getAclist()) {
+                if (ace.getSubjectuuid().equals(sid)) {
+                    // check permission matches
+                    if (checkPermission(ace.getPermission(),
+                            rm.toLowerCase())) {
+                        // check resource uri matches
+                        if (checkResourceUri(ace.getResources(), uri)) {
+                            return true;
                         }
                     }
                 }
             }
-            return false;
         }
+        return false;
+    }
 
-    private IResponse handleGetRequest(IRequest request) throws ServerException {
+    private IResponse handleGetRequest(IRequest request)
+            throws ServerException {
 
         String sid = null;
         String di = null;
         String rm = null;
         String uri = null;
 
-        if (getUriPathSegments().containsAll(request.getUriPathSegments())) {
-            sid = request.getUriQueryMap().get(Constants.REQ_SEARCH_USER_ID)
-                .get(0);
-            di = request.getUriQueryMap().get(Constants.REQ_DEVICE_ID).get(0);
-            rm = request.getUriQueryMap().get(Constants.REQ_REQUEST_METHOD)
-                .get(0);
-            uri = request.getUriQueryMap().get(Constants.REQ_REQUEST_URI)
-                .get(0);
-        } else {
-            throw new BadRequestException("uriPath is invalid");
-        }
+        HashMap<String, List<String>> queryMap = request.getUriQueryMap();
+
+        checkQueryException(Arrays.asList(Constants.REQ_SEARCH_USER_ID,
+                Constants.REQ_DEVICE_ID, Constants.REQ_REQUEST_METHOD,
+                Constants.REQ_REQUEST_URI), queryMap);
+
+        sid = queryMap.get(Constants.REQ_SEARCH_USER_ID).get(0);
+        di = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
+        rm = queryMap.get(Constants.REQ_REQUEST_METHOD).get(0);
+        uri = queryMap.get(Constants.REQ_REQUEST_URI).get(0);
 
         HashMap<String, Object> responsePayload = new HashMap<>();
         if (verifyAcl(sid, di, rm, uri)) {
-            responsePayload.put("gp", Constants.RESP_ACL_ALLOWED);
+            responsePayload.put(Constants.RESP_GROUP_PERMISSION,
+                    Constants.RESP_ACL_ALLOWED);
         } else {
-            responsePayload.put("gp", Constants.RESP_ACL_DENIED);
+            responsePayload.put(Constants.RESP_GROUP_PERMISSION,
+                    Constants.RESP_ACL_DENIED);
         }
 
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
index ce37111..96e3bcb 100644 (file)
@@ -1,40 +1,40 @@
-/*
- * //******************************************************************
- * //
- * // Copyright 2016 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.cloud.accountserver.resources.acl.verify;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public enum Permission {
-    Create(1), Read(2), Update(4), Delete(8), Notify(16);
-
-    private int value;
-
-    Permission(int val) {
-        value = val;
-    }
-
-    public int getValue() {
-        return value;
-    }
-
-}
+/*\r
+ * //******************************************************************\r
+ * //\r
+ * // Copyright 2016 Samsung Electronics All Rights Reserved.\r
+ * //\r
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ * //\r
+ * // Licensed under the Apache License, Version 2.0 (the "License");\r
+ * // you may not use this file except in compliance with the License.\r
+ * // You may obtain a copy of the License at\r
+ * //\r
+ * //      http://www.apache.org/licenses/LICENSE-2.0\r
+ * //\r
+ * // Unless required by applicable law or agreed to in writing, software\r
+ * // distributed under the License is distributed on an "AS IS" BASIS,\r
+ * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * // See the License for the specific language governing permissions and\r
+ * // limitations under the License.\r
+ * //\r
+ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+ */\r
+package org.iotivity.cloud.accountserver.resources.acl.verify;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+public enum Permission {\r
+    Create(1), Read(2), Update(4), Delete(8), Notify(16);\r
+\r
+    private int value;\r
+\r
+    Permission(int val) {\r
+        value = val;\r
+    }\r
+\r
+    public int getValue() {\r
+        return value;\r
+    }\r
+\r
+}\r
index ca61263..32b6ce9 100644 (file)
  */
 package org.iotivity.cloud.accountserver.resources.credprov.crl;
 
-import org.bouncycastle.operator.OperatorCreationException;
-import org.bson.types.Binary;
-import org.iotivity.cloud.accountserver.Constants;
-import org.iotivity.cloud.accountserver.db.CRLTable;
-import org.iotivity.cloud.accountserver.util.TypeCastingManager;
-import org.iotivity.cloud.base.exception.ServerException;
-import org.iotivity.cloud.util.Log;
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.ACCOUNT_DB_MANAGER;
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.CERTIFICATE_FACTORY;
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.DER;
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.NEXT_UPDATE_INTERVAL;
+import static org.iotivity.cloud.accountserver.x509.crl.CrlIssuer.CRL_ISSUER;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.security.cert.CRLException;
 import java.security.cert.X509CRL;
 import java.text.ParseException;
-import java.util.*;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
-import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.*;
-import static org.iotivity.cloud.accountserver.x509.crl.CrlIssuer.CRL_ISSUER;
+import org.bouncycastle.operator.OperatorCreationException;
+import org.bson.types.Binary;
+import org.iotivity.cloud.accountserver.Constants;
+import org.iotivity.cloud.accountserver.db.CRLTable;
+import org.iotivity.cloud.accountserver.util.TypeCastingManager;
+import org.iotivity.cloud.base.exception.ServerException;
+import org.iotivity.cloud.util.Log;
 
 /**
- * Class is used to manage CRLs. It helps to create,
- * update CRLS, revoke certificates.
+ * Class is used to manage CRLs. It helps to create, update CRLS, revoke
+ * certificates.
  */
 public final class CrlManager {
 
@@ -53,12 +62,12 @@ public final class CrlManager {
     /**
      * X509 CRL presentation.
      */
-    private X509CRL x509CRL;
+    private X509CRL                             x509CRL;
 
     /**
      * Static manager for CRLs.
      */
-    public static final CrlManager CRL_MANAGER = new CrlManager();
+    public static final CrlManager              CRL_MANAGER    = new CrlManager();
 
     /**
      * Private constructor to make this class non-instantiable.
@@ -69,9 +78,11 @@ public final class CrlManager {
             Date thisUpdate = calendar.getTime();
             calendar.add(Calendar.DAY_OF_MONTH,
                     Integer.parseInt(NEXT_UPDATE_INTERVAL));
-            byte[] data = CRL_ISSUER.generate(thisUpdate, calendar.getTime(), Collections.emptyList());
+            byte[] data = CRL_ISSUER.generate(thisUpdate, calendar.getTime(),
+                    Collections.emptyList());
             ACCOUNT_DB_MANAGER.insertRecord(Constants.CRL_TABLE,
-                    castingManager.convertObjectToMap(new CRLTable(thisUpdate, new Binary(data))));
+                    castingManager.convertObjectToMap(
+                            new CRLTable(thisUpdate, new Binary(data))));
             setX509CRL(data);
         } catch (CRLException | IOException | OperatorCreationException e) {
             Log.e(e.getMessage());
@@ -81,43 +92,53 @@ public final class CrlManager {
     /**
      * Revokes specified serial numbers. Puts them to database.
      *
-     * @param serialNumbers specified var args serial numbers from 0.
+     * @param serialNumbers
+     *            specified var args serial numbers from 0.
      */
-    public void revoke(String... serialNumbers) throws CRLException, IOException, OperatorCreationException {
+    public void revoke(String... serialNumbers)
+            throws CRLException, IOException, OperatorCreationException {
         if (x509CRL != null) {
             update(x509CRL.getThisUpdate(),
-                    CRL_ISSUER.generate(x509CRL.getThisUpdate(), x509CRL.getNextUpdate(),
+                    CRL_ISSUER.generate(x509CRL.getThisUpdate(),
+                            x509CRL.getNextUpdate(),
                             x509CRL.getRevokedCertificates(), serialNumbers));
         }
     }
 
     /**
-     * Checks last update less than crl this update and returns response payload,
-     * including this update, next update, and CRL in DER encoding.
+     * Checks last update less than crl this update and returns response
+     * payload, including this update, next update, and CRL in DER encoding.
      */
-    Map<String, Object> getPayload(String lastUpdate) throws ServerException.PreconditionFailedException, CRLException {
+    Map<String, Object> getPayload(String lastUpdate)
+            throws ServerException.PreconditionFailedException, CRLException {
         if (checkLastUpdate(lastUpdate) && x509CRL != null) {
             Map<String, Object> responsePayload = new HashMap<>();
-            responsePayload.put(Constants.REQ_THIS_UPDATE, DATE_FORMAT.format(x509CRL.getThisUpdate()));
-            responsePayload.put(Constants.REQ_NEXT_UPDATE, DATE_FORMAT.format(x509CRL.getNextUpdate()));
-            responsePayload.put(Constants.REQ_CRL, new CRL(DER, x509CRL.getEncoded()));
+            responsePayload.put(Constants.REQ_THIS_UPDATE,
+                    new SimpleDateFormat("yyyyMMddHHmmss")
+                            .format(x509CRL.getThisUpdate()));
+            responsePayload.put(Constants.REQ_NEXT_UPDATE,
+                    new SimpleDateFormat("yyyyMMddHHmmss")
+                            .format(x509CRL.getNextUpdate()));
+            responsePayload.put(Constants.REQ_CRL,
+                    new CRL(DER, x509CRL.getEncoded()));
             return responsePayload;
         }
         return Collections.emptyMap();
     }
 
-
     /**
      * Checks if last update is before CRL this update.
      *
-     * @param lastUpdate specified last update;
+     * @param lastUpdate
+     *            specified last update;
      * @return true if before and false - otherwise.
      */
     private boolean checkLastUpdate(String lastUpdate) {
         boolean checkCondition = false;
         try {
             if (x509CRL != null) {
-                checkCondition = DATE_FORMAT.parse(lastUpdate).before(x509CRL.getThisUpdate());
+                checkCondition = new SimpleDateFormat("yyyyMMddHHmmss")
+                        .parse(lastUpdate).before(x509CRL.getThisUpdate());
             }
         } catch (ParseException e) {
             Log.e(e.getMessage());
@@ -125,18 +146,19 @@ public final class CrlManager {
         return checkCondition;
     }
 
-
     /**
      * Updates CRLTable with specified this update and binary CRL data.
      */
     void update(Date thisUpdate, byte[] data) throws CRLException {
-        ArrayList<HashMap<String, Object>> crlList = ACCOUNT_DB_MANAGER.selectRecord(Constants.CRL_TABLE,
-                new HashMap<>());
+        ArrayList<HashMap<String, Object>> crlList = ACCOUNT_DB_MANAGER
+                .selectRecord(Constants.CRL_TABLE, new HashMap<>());
         if (crlList != null && !crlList.isEmpty()) {
-            CRLTable crlTable = castingManager.convertMaptoObject(crlList.get(0), new CRLTable());
+            CRLTable crlTable = castingManager
+                    .convertMaptoObject(crlList.get(0), new CRLTable());
             crlTable.setThisUpdate(thisUpdate);
             crlTable.setBinaryData(new Binary(data));
-            ACCOUNT_DB_MANAGER.updateRecord(Constants.CRL_TABLE, castingManager.convertObjectToMap(crlTable));
+            ACCOUNT_DB_MANAGER.updateRecord(Constants.CRL_TABLE,
+                    castingManager.convertObjectToMap(crlTable));
             setX509CRL(data);
         }
     }
@@ -145,7 +167,8 @@ public final class CrlManager {
      * Updates currect x509 CRL state by parsing specified data.
      */
     private void setX509CRL(byte[] data) throws CRLException {
-        x509CRL = (X509CRL) CERTIFICATE_FACTORY.generateCRL(new ByteArrayInputStream(data));
+        x509CRL = (X509CRL) CERTIFICATE_FACTORY
+                .generateCRL(new ByteArrayInputStream(data));
     }
 
     /**
index 13a51a2..fa75701 100644 (file)
  */
 package org.iotivity.cloud.accountserver.resources.credprov.crl;
 
+import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.BASE_64;
+import static org.iotivity.cloud.accountserver.resources.credprov.crl.CrlManager.CRL_MANAGER;
+
+import java.io.IOException;
+import java.security.cert.CRLException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import org.bouncycastle.operator.OperatorCreationException;
 import org.bouncycastle.util.encoders.Base64;
@@ -37,18 +49,8 @@ import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.util.Cbor;
 import org.iotivity.cloud.util.Log;
 
-import java.io.IOException;
-import java.security.cert.CRLException;
-import java.text.ParseException;
-import java.util.*;
-
-import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.BASE_64;
-import static org.iotivity.cloud.accountserver.resources.credprov.cert.CertificateConstants.DATE_FORMAT;
-import static org.iotivity.cloud.accountserver.resources.credprov.crl.CrlManager.CRL_MANAGER;
-
 /**
- * Class is used working with POST and GET requests and
- * handles CRL requests.
+ * Class is used working with POST and GET requests and handles CRL requests.
  */
 public class CrlResource extends Resource {
 
@@ -61,8 +63,8 @@ public class CrlResource extends Resource {
      * Creates resource for handling CRL requests(GET and POST)
      */
     public CrlResource() {
-        super(Arrays.asList(Constants.PREFIX_OIC,
-                Constants.CREDPROV_URI, Constants.REQ_CRL));
+        super(Arrays.asList(Constants.PREFIX_OIC, Constants.CREDPROV_URI,
+                Constants.REQ_CRL));
 
     }
 
@@ -78,39 +80,37 @@ public class CrlResource extends Resource {
                 response = handleGetRequest(request);
                 break;
             default:
-                response = MessageBuilder.createResponse(request, ResponseStatus.BAD_REQUEST);
+                response = MessageBuilder.createResponse(request,
+                        ResponseStatus.BAD_REQUEST);
         }
         srcDevice.sendResponse(response);
     }
 
     /**
-     * Method handles GET requests with specified format:
-     * GET /oic/credprov/crl?lu=20170701000000
-     * Checks if “lu” value is not after the latest update.
-     * If so, response with the latest CRL, otherwise response error (e.g. 4.04 Not Found)
-     * And response of next format:
-     * 2.05 CONTENTS
-     * {
-     *      “tu” : “20160711000000”,
-     *      “nu” : “20161011000000”,
-     *      “crl” : {
-     *          “encoding” : “oic.sec.encoding.base64”,
-     *          “data” : “<Base64 encoded CRL Binary>”
-     *       }
-     * }
+     * Method handles GET requests with specified format: GET
+     * /oic/credprov/crl?lu=20170701000000 Checks if “lu” value is not after the
+     * latest update. If so, response with the latest CRL, otherwise response
+     * error (e.g. 4.04 Not Found) And response of next format: 2.05 CONTENTS {
+     * “tu” : “20160711000000”, “nu” : “20161011000000”, “crl” : { “encoding” :
+     * “oic.sec.encoding.base64”, “data” : “<Base64 encoded CRL Binary>” } }
      */
     private IResponse handleGetRequest(IRequest request)
             throws ServerException {
         HashMap<String, List<String>> queryData = request.getUriQueryMap();
-        IResponse iResponse = MessageBuilder.createResponse(request, ResponseStatus.NOT_FOUND);
+        IResponse iResponse = MessageBuilder.createResponse(request,
+                ResponseStatus.NOT_FOUND);
         if (queryData != null) {
-            List<String> lastUpdateList = queryData.get(Constants.REQ_LAST_UPDATE);
+            List<String> lastUpdateList = queryData
+                    .get(Constants.REQ_LAST_UPDATE);
             if (lastUpdateList != null && !lastUpdateList.isEmpty()) {
                 try {
-                    Map<String, Object> payload = CRL_MANAGER.getPayload(lastUpdateList.get(0));
+                    Map<String, Object> payload = CRL_MANAGER
+                            .getPayload(lastUpdateList.get(0));
                     if (!payload.isEmpty()) {
-                        iResponse = MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
-                                ContentFormat.APPLICATION_CBOR, MAP_CBOR.encodingPayloadToCbor(payload));
+                        iResponse = MessageBuilder.createResponse(request,
+                                ResponseStatus.CONTENT,
+                                ContentFormat.APPLICATION_CBOR,
+                                MAP_CBOR.encodingPayloadToCbor(payload));
                     }
                 } catch (CRLException e) {
                     Log.e(e.getMessage());
@@ -121,60 +121,63 @@ public class CrlResource extends Resource {
     }
 
     /**
-     * Handles POST requests of next formats:
-     * POST /oic/credprov/crl
-     * {
-     *      “tu” : “20160727000000”,
-     *      “nu” : “20161027000000”,
-     *      “rcsn” : “123456”
-     * }
-     * AND
-     * POST /oic/credprov/crl
-     * {
-     *      “tu” : “20160727000000”,
-     *      “nu” : “20161027000000”,
-     *      “crl” : {
-     *          “encoding” : “oic.sec.encoding.base64”,
-     *          “data” : “<Base64 encoded New CRL Binary>”
-     *       }
-     * }
-     * And responds back with 2.04 CHANGED if everything is ok, and PRECONDITION_FAILED - otherwise
+     * Handles POST requests of next formats: POST /oic/credprov/crl { “tu” :
+     * “20160727000000”, “nu” : “20161027000000”, “rcsn” : “123456” } AND POST
+     * /oic/credprov/crl { “tu” : “20160727000000”, “nu” : “20161027000000”,
+     * “crl” : { “encoding” : “oic.sec.encoding.base64”, “data” : “<Base64
+     * encoded New CRL Binary>” } } And responds back with 2.04 CHANGED if
+     * everything is ok, and PRECONDITION_FAILED - otherwise
      */
     private IResponse handlePostRequest(IRequest request)
             throws ServerException {
         byte[] requestPayload = request.getPayload();
-        IResponse response = MessageBuilder.createResponse(request, ResponseStatus.PRECONDITION_FAILED);
+        IResponse response = MessageBuilder.createResponse(request,
+                ResponseStatus.PRECONDITION_FAILED);
         if (requestPayload != null) {
             Map<String, Object> payloadData = MAP_CBOR
                     .parsePayloadFromCbor(request.getPayload(), HashMap.class);
             if (payloadData != null) {
                 Object thisUpdate = payloadData.get(Constants.REQ_THIS_UPDATE);
                 Object nextUpdate = payloadData.get(Constants.REQ_NEXT_UPDATE);
-                if (thisUpdate != null && thisUpdate instanceof String && nextUpdate != null && nextUpdate instanceof String) {
+                if (thisUpdate != null && thisUpdate instanceof String
+                        && nextUpdate != null && nextUpdate instanceof String) {
                     Date thisUpdateDate;
                     try {
-                        thisUpdateDate = DATE_FORMAT.parse(thisUpdate.toString());
-                        Object reqSerialNumber = payloadData.get(Constants.REQ_SERIAL_NUMBER);
+                        thisUpdateDate = new SimpleDateFormat("yyyyMMddHHmmss")
+                                .parse(thisUpdate.toString());
+                        Object reqSerialNumber = payloadData
+                                .get(Constants.REQ_SERIAL_NUMBER);
                         Object crl = payloadData.get(Constants.REQ_CRL);
-                        if (reqSerialNumber != null && reqSerialNumber instanceof List) {
-                            CRL_MANAGER.revoke(((List<String>) reqSerialNumber).toArray(new String[]{}));
-                            response = MessageBuilder.createResponse(request, ResponseStatus.CHANGED);
+                        if (reqSerialNumber != null
+                                && reqSerialNumber instanceof List) {
+                            CRL_MANAGER.revoke(((List<String>) reqSerialNumber)
+                                    .toArray(new String[] {}));
+                            response = MessageBuilder.createResponse(request,
+                                    ResponseStatus.CHANGED);
                         } else if (crl != null && crl instanceof Map) {
-                            Object encoding = ((Map<String, Object>) crl).get(Constants.ENCODING);
-                            Object crlData = ((Map<String, Object>) crl).get(Constants.DATA);
-                            if (encoding != null && encoding instanceof String && crlData != null && crlData instanceof byte[]) {
+                            Object encoding = ((Map<String, Object>) crl)
+                                    .get(Constants.ENCODING);
+                            Object crlData = ((Map<String, Object>) crl)
+                                    .get(Constants.DATA);
+                            if (encoding != null && encoding instanceof String
+                                    && crlData != null
+                                    && crlData instanceof byte[]) {
                                 try {
                                     if (encoding.equals(BASE_64)) {
-                                        crlData = Base64.decode((byte[]) crlData);
+                                        crlData = Base64
+                                                .decode((byte[]) crlData);
                                     }
-                                    CRL_MANAGER.update(thisUpdateDate, (byte[]) crlData);
-                                    response = MessageBuilder.createResponse(request, ResponseStatus.CHANGED);
+                                    CRL_MANAGER.update(thisUpdateDate,
+                                            (byte[]) crlData);
+                                    response = MessageBuilder.createResponse(
+                                            request, ResponseStatus.CHANGED);
                                 } catch (DecoderException e) {
                                     Log.e(e.getMessage() + e.getClass());
                                 }
                             }
                         }
-                    } catch (CRLException | IOException | OperatorCreationException | ParseException e) {
+                    } catch (CRLException | IOException
+                            | OperatorCreationException | ParseException e) {
                         Log.e(e.getMessage() + e.getClass());
                     }
                 }
index 06b8fbe..6fbc4f8 100644 (file)
@@ -66,7 +66,7 @@ public class AccountResourceTest {
     private static final String            REGISTER_URI              = Constants.ACCOUNT_FULL_URI;
     private static final String            GROUP_URI                 = Constants.GROUP_FULL_URI;
     private static final String            DEVICE_ID                 = "DEVICE";
-    private String                         mAuthProvider             = "Github";
+    private String                         mAuthProvider             = "github";
     private String                         mAuthCode                 = "3af038b49edc4ebdc45c";
     private CoapDevice                     mMockDevice               = mock(
             CoapDevice.class);
@@ -112,7 +112,7 @@ public class AccountResourceTest {
 
     @After
     public void resetAccountDatabase() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.createTable(Constants.USER_TABLE);
         mongoDB.createTable(Constants.TOKEN_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
index 5224f76..affb5b9 100644 (file)
@@ -106,7 +106,7 @@ public class SessionResourceTest {
 
     @After
     public void resetAccountDatabase() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.createTable(Constants.USER_TABLE);
         mongoDB.createTable(Constants.TOKEN_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
@@ -362,7 +362,7 @@ public class SessionResourceTest {
     }
 
     private void resetDB() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.deleteTable(Constants.GROUP_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
         mongoDB.deleteTable(Constants.USER_TABLE);
index 2d1df31..f9e0f35 100644 (file)
@@ -64,7 +64,7 @@ public class TokenRefreshResourceTest {
 
     @After
     public void resetAccountDatabase() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.createTable(Constants.USER_TABLE);
         mongoDB.createTable(Constants.TOKEN_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
index abc52cc..bf66e30 100644 (file)
@@ -83,7 +83,7 @@ public class GroupAclManagerTest {
         AclResource.getInstance().deleteAcl((String) AclResource.getInstance()
                 .getAclid(mDi2).get(Constants.KEYFIELD_ACLID));
 
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.deleteTable(Constants.GROUP_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
         mongoDB.deleteTable(Constants.ACL_TABLE);
index 72e2cf5..9ae1935 100644 (file)
@@ -78,7 +78,7 @@ public class GroupBrokerTest {
 
     @After
     public void resetAccountDatabase() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.createTable(Constants.USER_TABLE);
         mongoDB.createTable(Constants.TOKEN_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
@@ -189,7 +189,7 @@ public class GroupBrokerTest {
     }
 
     private void resetDB() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.deleteTable(Constants.GROUP_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
         mongoDB.deleteTable(Constants.USER_TABLE);
index 325a498..06304b1 100644 (file)
@@ -108,7 +108,7 @@ public class GroupResourceTest {
 
     @After
     public void resetAccountDatabase() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.deleteTable(Constants.USER_TABLE);
         mongoDB.createTable(Constants.USER_TABLE);
         mongoDB.deleteTable(Constants.TOKEN_TABLE);
@@ -824,7 +824,7 @@ public class GroupResourceTest {
     }
 
     public void resetDB() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.deleteTable(Constants.GROUP_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
         mongoDB.deleteTable(Constants.USER_TABLE);
index 0f0d203..70f835f 100644 (file)
@@ -53,24 +53,26 @@ import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
 public class AclIdResourceTest {
-    private static final String ACL_ID_URI = Constants.ACL_ID_FULL_URI;
-    final CountDownLatch mLatch = new CountDownLatch(1);
-    private final String mDeviceUuid = "9cfbeb8e-5a1e-4d1c-9d01-2ae6fdb";
-    private final String mOwnerUuid = "123e4567-e89b-12d3-a456-4266554";
-    private final String mSubjectUuid = "72616E64-5069-6E44-6576-5575696";
-    private final int mSubjectType = 0;
-    private final int mPermission = 6;
-    private final int mSubjectTypeUpdate = 1;
-    private final int mPermissionUpdate = 7;
-    private final String mResourceUri = "/a/light/0";
-    private final String mResourceType = "core.light";
-    private final String mResourceIf = "oic.if.baseline";
-    private String mAceId = "a0001";
-    private String mAclId = "987e6543-e21b-12d3-a456-4266554";
-    private CoapDevice mMockDevice = Mockito.mock(CoapDevice.class);
-    private Cbor<HashMap<String, Object>> mCbor = new Cbor<>();
-    private IResponse mResponse = null;
-    private AclResource mAclResource = new AclResource();
+    private static final String           ACL_ID_URI         = Constants.ACL_ID_FULL_URI;
+    final CountDownLatch                  mLatch             = new CountDownLatch(
+            1);
+    private final String                  mDeviceUuid        = "9cfbeb8e-5a1e-4d1c-9d01-2ae6fdb";
+    private final String                  mOwnerUuid         = "123e4567-e89b-12d3-a456-4266554";
+    private final String                  mSubjectUuid       = "72616E64-5069-6E44-6576-5575696";
+    private final int                     mSubjectType       = 0;
+    private final int                     mPermission        = 6;
+    private final int                     mSubjectTypeUpdate = 1;
+    private final int                     mPermissionUpdate  = 7;
+    private final String                  mResourceUri       = "/a/light/0";
+    private final String                  mResourceType      = "core.light";
+    private final String                  mResourceIf        = "oic.if.baseline";
+    private String                        mAceId             = "a0001";
+    private String                        mAclId             = "987e6543-e21b-12d3-a456-4266554";
+    private CoapDevice                    mMockDevice        = Mockito
+            .mock(CoapDevice.class);
+    private Cbor<HashMap<String, Object>> mCbor              = new Cbor<>();
+    private IResponse                     mResponse          = null;
+    private AclResource                   mAclResource       = new AclResource();
 
     @Before
     public void setUp() throws Exception {
@@ -79,14 +81,18 @@ public class AclIdResourceTest {
         resetDB();
         Mockito.doAnswer(new Answer<Object>() {
             @Override
-            public CoapResponse answer(InvocationOnMock invocation) throws Throwable {
+            public CoapResponse answer(InvocationOnMock invocation)
+                    throws Throwable {
                 Object[] args = invocation.getArguments();
                 CoapResponse resp = (CoapResponse) args[0];
-                System.out.println("\t----------payload : " + resp.getPayloadString());
+                System.out.println(
+                        "\t----------payload : " + resp.getPayloadString());
                 System.out.println("\t---------method : " + resp.getStatus());
                 mResponse = resp;
                 if (mAclId == null) {
-                    HashMap<String, Object> payloadData = mCbor.parsePayloadFromCbor(resp.getPayload(), HashMap.class);
+                    HashMap<String, Object> payloadData = mCbor
+                            .parsePayloadFromCbor(resp.getPayload(),
+                                    HashMap.class);
                     if (payloadData.containsKey("aclid")) {
                         mAclId = (String) payloadData.get("aclid");
                     }
@@ -99,7 +105,7 @@ public class AclIdResourceTest {
 
     @After
     public void resetAccountDatabase() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.createTable(Constants.USER_TABLE);
         mongoDB.createTable(Constants.ACL_TABLE);
         mongoDB.createTable(Constants.TOKEN_TABLE);
@@ -184,7 +190,8 @@ public class AclIdResourceTest {
         assertTrue(mLatch.await(2L, SECONDS));
     }
 
-    private void createAclId(CoapDevice device, String di, String oid) throws Exception {
+    private void createAclId(CoapDevice device, String di, String oid)
+            throws Exception {
         System.out.println("-----Create Acl Id");
         IRequest request = null;
         request = createAclIdRequest(oid, di);
@@ -212,21 +219,24 @@ public class AclIdResourceTest {
         mAclResource.onDefaultRequestReceived(device, request);
     }
 
-    private void addIndividualAce(CoapDevice device, String aclId) throws Exception {
+    private void addIndividualAce(CoapDevice device, String aclId)
+            throws Exception {
         System.out.println("-----Add Individual Ace");
         IRequest request = null;
         request = addIndividualAceRequest(aclId);
         mAclResource.onDefaultRequestReceived(device, request);
     }
 
-    private void updateIndividualAce(CoapDevice device, String aclId, String aceId) throws Exception {
+    private void updateIndividualAce(CoapDevice device, String aclId,
+            String aceId) throws Exception {
         System.out.println("-----Update Individual Acl Ace");
         IRequest request = null;
         request = updateIndividualAceRequest(aclId, aceId);
         mAclResource.onDefaultRequestReceived(device, request);
     }
 
-    private void deleteIndividualAclAce(CoapDevice device, String aclId, String aceId) throws Exception {
+    private void deleteIndividualAclAce(CoapDevice device, String aclId,
+            String aceId) throws Exception {
         System.out.println("-----Delete Individual Acl Ace");
         IRequest request = null;
         request = deleteIndividualAclAceRequest(aclId, aceId);
@@ -235,27 +245,32 @@ public class AclIdResourceTest {
 
     private IRequest getAclIdRequest(String deviceUuid) {
         IRequest request = null;
-        request = MessageBuilder.createRequest(RequestMethod.GET, ACL_ID_URI, "di=" + deviceUuid);
+        request = MessageBuilder.createRequest(RequestMethod.GET, ACL_ID_URI,
+                "di=" + deviceUuid);
         ((CoapRequest) request).setObserve(Observe.SUBSCRIBE);
         return request;
     }
 
     private IRequest createAclIdRequest(String oid, String di) {
         IRequest request = null;
-        String uriQuery = Constants.REQ_OWNER_ID + "=" + oid + ";" + Constants.REQ_DEVICE_ID + "=" + di;
-        request = MessageBuilder.createRequest(RequestMethod.PUT, ACL_ID_URI, uriQuery);
+        String uriQuery = Constants.REQ_OWNER_ID + "=" + oid + ";"
+                + Constants.REQ_DEVICE_ID + "=" + di;
+        request = MessageBuilder.createRequest(RequestMethod.PUT, ACL_ID_URI,
+                uriQuery);
         return request;
     }
 
     private IRequest deleteAclIdRequest(String aclId) {
         IRequest request = null;
-        request = MessageBuilder.createRequest(RequestMethod.DELETE, ACL_ID_URI, "aclid=" + aclId);
+        request = MessageBuilder.createRequest(RequestMethod.DELETE, ACL_ID_URI,
+                "aclid=" + aclId);
         return request;
     }
 
     private IRequest getIndividualAclRequest(String aclId) {
         IRequest request = null;
-        request = MessageBuilder.createRequest(RequestMethod.GET, ACL_ID_URI + "/" + aclId, null);
+        request = MessageBuilder.createRequest(RequestMethod.GET,
+                ACL_ID_URI + "/" + aclId, null);
         ((CoapRequest) request).setObserve(Observe.NOTHING);
         return request;
     }
@@ -283,8 +298,9 @@ public class AclIdResourceTest {
         HashMap<String, Object> payload = new HashMap<>();
         payload.put(Constants.REQ_ACL_LIST, Arrays.asList(acelist));
 
-        return MessageBuilder.createRequest(RequestMethod.POST, ACL_ID_URI + "/" + aclId, null,
-                ContentFormat.APPLICATION_CBOR, mCbor.encodingPayloadToCbor(payload));
+        return MessageBuilder.createRequest(RequestMethod.POST,
+                ACL_ID_URI + "/" + aclId, null, ContentFormat.APPLICATION_CBOR,
+                mCbor.encodingPayloadToCbor(payload));
     }
 
     private IRequest updateIndividualAceRequest(String aclId, String aceId) {
@@ -310,18 +326,22 @@ public class AclIdResourceTest {
         HashMap<String, Object> payload = new HashMap<>();
         payload.put(Constants.REQ_ACL_LIST, Arrays.asList(acelist));
 
-        return MessageBuilder.createRequest(RequestMethod.POST, ACL_ID_URI + "/" + aclId, "aceid=" + aceId,
-                ContentFormat.APPLICATION_CBOR, mCbor.encodingPayloadToCbor(payload));
+        return MessageBuilder.createRequest(RequestMethod.POST,
+                ACL_ID_URI + "/" + aclId, "aceid=" + aceId,
+                ContentFormat.APPLICATION_CBOR,
+                mCbor.encodingPayloadToCbor(payload));
     }
 
     private IRequest deleteIndividualAclAceRequest(String aclId, String aceId) {
         IRequest request = null;
-        request = MessageBuilder.createRequest(RequestMethod.DELETE, ACL_ID_URI + "/" + aclId, "aceid=" + aceId);
+        request = MessageBuilder.createRequest(RequestMethod.DELETE,
+                ACL_ID_URI + "/" + aclId, "aceid=" + aceId);
         return request;
     }
 
     private void hashmapGetAclId(IResponse response, String propertyName) {
-        HashMap<String, Object> payloadData = mCbor.parsePayloadFromCbor(response.getPayload(), HashMap.class);
+        HashMap<String, Object> payloadData = mCbor
+                .parsePayloadFromCbor(response.getPayload(), HashMap.class);
         if (payloadData.containsKey(propertyName)) {
 
             mAclId = (String) payloadData.get(propertyName);
@@ -330,16 +350,19 @@ public class AclIdResourceTest {
     }
 
     private void hashmapGetAceId(IResponse response, String propertyName) {
-        HashMap<String, Object> payloadData = mCbor.parsePayloadFromCbor(response.getPayload(), HashMap.class);
+        HashMap<String, Object> payloadData = mCbor
+                .parsePayloadFromCbor(response.getPayload(), HashMap.class);
         if (payloadData.containsKey("aclist")) {
-            List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) payloadData.get("aclist");
+            List<HashMap<String, Object>> aclist = (List<HashMap<String, Object>>) payloadData
+                    .get("aclist");
             mAceId = (String) aclist.get(0).get(propertyName);
             System.out.println("hashmapGetAceId getace " + mAceId);
         }
     }
 
     private boolean hashmapCheck(IResponse response, String propertyName) {
-        HashMap<String, Object> payloadData = mCbor.parsePayloadFromCbor(response.getPayload(), HashMap.class);
+        HashMap<String, Object> payloadData = mCbor
+                .parsePayloadFromCbor(response.getPayload(), HashMap.class);
         if (payloadData.containsKey(propertyName)) {
             return true;
         } else {
@@ -347,7 +370,8 @@ public class AclIdResourceTest {
         }
     }
 
-    private boolean methodCheck(IResponse response, ResponseStatus responseStatus) {
+    private boolean methodCheck(IResponse response,
+            ResponseStatus responseStatus) {
         if (responseStatus == response.getStatus()) {
             return true;
         } else {
@@ -362,7 +386,7 @@ public class AclIdResourceTest {
     }
 
     public void resetDB() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.deleteTable(Constants.GROUP_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
         mongoDB.deleteTable(Constants.ACL_TABLE);
index faa4cc1..080bddd 100644 (file)
@@ -85,7 +85,7 @@ public class InviteResourceTest {
         mResponse = null;
 
         // reset data base
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.deleteTable(Constants.INVITE_TABLE);
         mongoDB.createTable(Constants.INVITE_TABLE);
 
index acdcae3..820c777 100644 (file)
@@ -34,7 +34,6 @@ import org.iotivity.cloud.accountserver.Constants;
 import org.iotivity.cloud.accountserver.db.MongoDB;
 import org.iotivity.cloud.accountserver.resources.acl.id.AclResource;
 import org.iotivity.cloud.base.device.CoapDevice;
-
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
@@ -54,24 +53,26 @@ import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
 public class AclVerifyResourceTest {
-    private static final String ACL_ID_URI = Constants.ACL_ID_FULL_URI;
-    private static final String ACL_VERIFY_URI = Constants.ACL_VERIFY_FULL_URI;
-    final CountDownLatch mLatch = new CountDownLatch(1);
-    private final String mDeviceUuid = "9cfbeb8e-5a1e-4d1c-9d01-2ae6fdb";
-    private final String mOwnerUuid = "123e4567-e89b-12d3-a456-4266554";
-    private final String mSubjectUuid = "72616E64-5069-6E44-6576-5575696";
-    private final String mRmType = "POST";
-    private final int mSubjectType = 1;
-    private final int mPermission = 7;
-    private final String mResourceUri = "/a/light/0";
-    private final String mResourceType = "core.light";
-    private final String mResourceIf = "oic.if.baseline";
-    private String mAclId = "987e6543-e21b-12d3-a456-4266554";
-    private CoapDevice mMockDevice = Mockito.mock(CoapDevice.class);
-    private Cbor<HashMap<String, Object>> mCbor = new Cbor<>();
-    private IResponse mResponse = null;
-    private AclVerifyResource mAclVerifyResource = new AclVerifyResource();
-    private AclResource mAclResource = new AclResource();
+    private static final String           ACL_ID_URI         = Constants.ACL_ID_FULL_URI;
+    private static final String           ACL_VERIFY_URI     = Constants.ACL_VERIFY_FULL_URI;
+    final CountDownLatch                  mLatch             = new CountDownLatch(
+            1);
+    private final String                  mDeviceUuid        = "9cfbeb8e-5a1e-4d1c-9d01-2ae6fdb";
+    private final String                  mOwnerUuid         = "123e4567-e89b-12d3-a456-4266554";
+    private final String                  mSubjectUuid       = "72616E64-5069-6E44-6576-5575696";
+    private final String                  mRmType            = "POST";
+    private final int                     mSubjectType       = 1;
+    private final int                     mPermission        = 7;
+    private final String                  mResourceUri       = "/a/light/0";
+    private final String                  mResourceType      = "core.light";
+    private final String                  mResourceIf        = "oic.if.baseline";
+    private String                        mAclId             = "987e6543-e21b-12d3-a456-4266554";
+    private CoapDevice                    mMockDevice        = Mockito
+            .mock(CoapDevice.class);
+    private Cbor<HashMap<String, Object>> mCbor              = new Cbor<>();
+    private IResponse                     mResponse          = null;
+    private AclVerifyResource             mAclVerifyResource = new AclVerifyResource();
+    private AclResource                   mAclResource       = new AclResource();
 
     @Before
     public void setUp() throws Exception {
@@ -80,14 +81,18 @@ public class AclVerifyResourceTest {
         resetDB();
         Mockito.doAnswer(new Answer<Object>() {
             @Override
-            public CoapResponse answer(InvocationOnMock invocation) throws Throwable {
+            public CoapResponse answer(InvocationOnMock invocation)
+                    throws Throwable {
                 Object[] args = invocation.getArguments();
                 CoapResponse resp = (CoapResponse) args[0];
-                System.out.println("\t----------payload : " + resp.getPayloadString());
+                System.out.println(
+                        "\t----------payload : " + resp.getPayloadString());
                 System.out.println("\t---------method : " + resp.getStatus());
                 mResponse = resp;
                 if (mAclId == null) {
-                    HashMap<String, Object> payloadData = mCbor.parsePayloadFromCbor(resp.getPayload(), HashMap.class);
+                    HashMap<String, Object> payloadData = mCbor
+                            .parsePayloadFromCbor(resp.getPayload(),
+                                    HashMap.class);
                     if (payloadData.containsKey("aclid")) {
                         mAclId = (String) payloadData.get("aclid");
                     }
@@ -100,7 +105,7 @@ public class AclVerifyResourceTest {
 
     @After
     public void resetAccountDatabase() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.createTable(Constants.USER_TABLE);
         mongoDB.createTable(Constants.ACL_TABLE);
         mongoDB.createTable(Constants.TOKEN_TABLE);
@@ -113,13 +118,15 @@ public class AclVerifyResourceTest {
         createAclId(mMockDevice, mDeviceUuid, mOwnerUuid);
         hashmapGetAclId(mResponse, "aclid");
         addIndividualAce(mMockDevice, mAclId);
-        verifyAcl(mMockDevice, mSubjectUuid, mDeviceUuid, mRmType, mResourceUri);
+        verifyAcl(mMockDevice, mSubjectUuid, mDeviceUuid, mRmType,
+                mResourceUri);
         assertTrue(methodCheck(mResponse, ResponseStatus.CONTENT));
         assertTrue(hashmapCheck(mResponse, "gp"));
         assertTrue(mLatch.await(2L, SECONDS));
     }
 
-    private void createAclId(CoapDevice device, String di, String oid) throws Exception {
+    private void createAclId(CoapDevice device, String di, String oid)
+            throws Exception {
         System.out.println("-----Create Acl Id");
         IRequest request = null;
         request = createAclIdRequest(oid, di);
@@ -128,12 +135,15 @@ public class AclVerifyResourceTest {
 
     private IRequest createAclIdRequest(String oid, String di) {
         IRequest request = null;
-        String uriQuery = Constants.REQ_OWNER_ID + "=" + oid + ";" + Constants.REQ_DEVICE_ID + "=" + di;
-        request = MessageBuilder.createRequest(RequestMethod.PUT, ACL_ID_URI, uriQuery);
+        String uriQuery = Constants.REQ_OWNER_ID + "=" + oid + ";"
+                + Constants.REQ_DEVICE_ID + "=" + di;
+        request = MessageBuilder.createRequest(RequestMethod.PUT, ACL_ID_URI,
+                uriQuery);
         return request;
     }
 
-    private void addIndividualAce(CoapDevice device, String aclId) throws Exception {
+    private void addIndividualAce(CoapDevice device, String aclId)
+            throws Exception {
         System.out.println("-----Add Individual Ace");
         IRequest request = null;
         request = addIndividualAceRequest(aclId);
@@ -163,28 +173,34 @@ public class AclVerifyResourceTest {
         HashMap<String, Object> payload = new HashMap<>();
         payload.put(Constants.REQ_ACL_LIST, Arrays.asList(acelist));
 
-        return MessageBuilder.createRequest(RequestMethod.POST, ACL_ID_URI + "/" + aclId, null,
-                ContentFormat.APPLICATION_CBOR, mCbor.encodingPayloadToCbor(payload));
+        return MessageBuilder.createRequest(RequestMethod.POST,
+                ACL_ID_URI + "/" + aclId, null, ContentFormat.APPLICATION_CBOR,
+                mCbor.encodingPayloadToCbor(payload));
     }
 
-    private void verifyAcl(CoapDevice device, String subjectUuid, String di, String rm, String uri) throws Exception {
+    private void verifyAcl(CoapDevice device, String subjectUuid, String di,
+            String rm, String uri) throws Exception {
         System.out.println("-----Verify Acl");
         IRequest request = null;
         request = verifyAclRequest(subjectUuid, di, rm, uri);
         mAclVerifyResource.onDefaultRequestReceived(device, request);
     }
 
-    private IRequest verifyAclRequest(String subjectUuid, String di, String rm, String uri) {
+    private IRequest verifyAclRequest(String subjectUuid, String di, String rm,
+            String uri) {
         IRequest request = null;
-        String queryUrl = "sid=" + subjectUuid + ";di=" + di + ";rm=" + rm + ";uri=" + uri;
+        String queryUrl = "sid=" + subjectUuid + ";di=" + di + ";rm=" + rm
+                + ";uri=" + uri;
         System.out.println(queryUrl);
-        request = MessageBuilder.createRequest(RequestMethod.GET, ACL_VERIFY_URI, queryUrl);
+        request = MessageBuilder.createRequest(RequestMethod.GET,
+                ACL_VERIFY_URI, queryUrl);
         ((CoapRequest) request).setObserve(Observe.SUBSCRIBE);
         return request;
     }
 
     private void hashmapGetAclId(IResponse response, String propertyName) {
-        HashMap<String, Object> payloadData = mCbor.parsePayloadFromCbor(response.getPayload(), HashMap.class);
+        HashMap<String, Object> payloadData = mCbor
+                .parsePayloadFromCbor(response.getPayload(), HashMap.class);
         if (payloadData.containsKey(propertyName)) {
 
             mAclId = (String) payloadData.get(propertyName);
@@ -193,7 +209,8 @@ public class AclVerifyResourceTest {
     }
 
     private boolean hashmapCheck(IResponse response, String propertyName) {
-        HashMap<String, Object> payloadData = mCbor.parsePayloadFromCbor(response.getPayload(), HashMap.class);
+        HashMap<String, Object> payloadData = mCbor
+                .parsePayloadFromCbor(response.getPayload(), HashMap.class);
         if (payloadData.containsKey(propertyName)) {
             return true;
         } else {
@@ -201,7 +218,8 @@ public class AclVerifyResourceTest {
         }
     }
 
-    private boolean methodCheck(IResponse response, ResponseStatus responseStatus) {
+    private boolean methodCheck(IResponse response,
+            ResponseStatus responseStatus) {
         if (responseStatus == response.getStatus()) {
             return true;
         } else {
@@ -216,7 +234,7 @@ public class AclVerifyResourceTest {
     }
 
     public void resetDB() throws Exception {
-        MongoDB mongoDB = new MongoDB(Constants.DB_NAME);
+        MongoDB mongoDB = new MongoDB("127.0.0.1", Constants.DB_NAME);
         mongoDB.deleteTable(Constants.GROUP_TABLE);
         mongoDB.createTable(Constants.GROUP_TABLE);
         mongoDB.deleteTable(Constants.ACL_TABLE);