Update voting app with basic auth
[music.git] / examples / VotingApp / src / main / java / main / VotingApp.java
index 8846ba2..653cef2 100644 (file)
@@ -29,6 +29,7 @@ import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Base64;
 
 import javax.ws.rs.core.MediaType;
 
@@ -66,13 +67,11 @@ public class VotingApp {
         if (!namespace.equals("")) {
             builder.header("ns", namespace);
         }
-        if (!userId.equals("")) {
-            builder.header("userId", userId);
+        if (!userId.equals("") && !password.equals("")) {
+            String authString = Base64.getEncoder().encodeToString((userId + ":" + password).getBytes());
+            builder.header("Authorization", "Basic " + authString);
         }
-        if (!password.equals("")) {
-            builder.header("password", password);
-        }
-        
+
         return builder;
     }
     
@@ -511,4 +510,4 @@ public class VotingApp {
     }
             
 
-}
\ No newline at end of file
+}