[SECIOTSRK-345] Add configuration to work with DSM
authorYevhen Zozulia <y.zozulia@surc.local>
Tue, 25 Jul 2017 09:28:35 +0000 (12:28 +0300)
committerYevhen Zozulia <y.zozulia@surc.local>
Tue, 25 Jul 2017 10:53:19 +0000 (13:53 +0300)
cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServer.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Samsung.java

index 220e058..54ed12e 100644 (file)
@@ -50,6 +50,7 @@ public class AccountServer {
     private static boolean tlsMode;
     private static String  databaseHost;
     private static String  webLogHost;
+    private static String  dsmHost;
 
     public static void main(String[] args) throws Exception {
         System.out.println("-----Account SERVER-----");
@@ -58,7 +59,7 @@ public class AccountServer {
         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");
+                    + " 127.0.0.1 27017 0 127.0.0.1 8080\n");
             return;
         }
         if (webLogHost != null)
@@ -103,12 +104,13 @@ public class AccountServer {
 
     private static boolean parseConfiguration(String[] args) {
         // configuration provided by arguments
-        if (args.length == 4 || args.length == 6) {
+        if (args.length == 6 || args.length == 8) {
             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];
+            dsmHost = args[4] + ":" + args[5];
+            if (args.length == 8)
+                webLogHost = args[6] + ":" + args[7];
             return true;
         }
         // configuration provided by docker env
@@ -123,4 +125,9 @@ public class AccountServer {
         }
         return false;
     }
+
+    public static String getDsmHost() {
+        return dsmHost;
+    }
+
 }
index 5701838..76b8147 100644 (file)
@@ -14,6 +14,7 @@ import org.apache.oltu.oauth2.common.OAuth;
 import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
 import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
 import org.apache.oltu.oauth2.common.message.types.GrantType;
+import org.iotivity.cloud.accountserver.AccountServer;
 import org.iotivity.cloud.accountserver.db.TokenTable;
 import org.iotivity.cloud.accountserver.db.UserTable;
 import org.iotivity.cloud.base.exception.ServerException.InternalServerErrorException;
@@ -30,17 +31,17 @@ public class Samsung implements OAuthProvider {
 
     private static final String SAMSUNG_PROVIDER_NAME = "Samsung";
     private static final String TOKEN = "token";
-    private static final String DSM_HOST = "http://localhost:8080";
+    private static String DSM_HOST = "http://" + AccountServer.getDsmHost();
     private static final String CLIENT_ID = "client";
     private static final String SECRET = "secret";
-    private final static String REDIRECT_URL = DSM_HOST + "/dsm/oauth/callback";
-    private final static String TOKEN_END_POINT = DSM_HOST + "/dsm/oauth/token";
+    private static String REDIRECT_URL = "http://localhost:8080/dsm/oauth/callback";//Don't change
+    private static String TOKEN_END_POINT = DSM_HOST + "/dsm/oauth/token";
     @SuppressWarnings("unused")
-    private final static String AUTH_URL = DSM_HOST + "/dsm/oauth";
-    private final static String RESOURCE_URL = DSM_HOST + "/dsm/restapi/access_token/";
+    private static String AUTH_URL = DSM_HOST + "/dsm/oauth";
+    private static String RESOURCE_URL = DSM_HOST + "/dsm/restapi/access_token/";
     private static final String USER_ID_KEY = "username";
 
-    final static private SecureRandom random = new SecureRandom();
+    private static final SecureRandom random = new SecureRandom();
 
     @Override
     public TokenTable requestAccessTokenInfo(String authCode, Object options) {