IGNITE-8201 WIP.

Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/3780ac0a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/3780ac0a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/3780ac0a

Branch: refs/heads/ignite-8201
Commit: 3780ac0a09198e2918206d23ee515a2fe522352c
Parents: fe21ed5
Author: Alexey Kuznetsov <akuznet...@apache.org>
Authored: Wed Apr 11 19:28:11 2018 +0700
Committer: Alexey Kuznetsov <akuznet...@apache.org>
Committed: Wed Apr 11 19:28:11 2018 +0700

----------------------------------------------------------------------
 ...ettyRestProcessorAuthenticationSelfTest.java | 43 ++++++++++----------
 .../http/jetty/GridJettyRestHandler.java        |  8 +++-
 2 files changed, 28 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/3780ac0a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java
 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java
index 145d7e9..1536d9d 100644
--- 
a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java
+++ 
b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationSelfTest.java
@@ -41,12 +41,6 @@ public class JettyRestProcessorAuthenticationSelfTest 
extends JettyRestProcessor
     private static final String DFLT_PWD = "ignite";
 
     /** */
-    private String user = DFLT_USER;
-
-    /** */
-    private String pwd = DFLT_PWD;
-
-    /** */
     private String tok = "";
 
     /** {@inheritDoc} */
@@ -60,8 +54,22 @@ public class JettyRestProcessorAuthenticationSelfTest 
extends JettyRestProcessor
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 
-        user = DFLT_USER;
-        pwd = DFLT_PWD;
+        // Authenticate and extract token.
+        if (F.isEmpty(tok)) {
+            String ret = content(null, GridRestCommand.AUTHENTICATE,
+                "user", DFLT_USER,
+                "password", DFLT_PWD);
+
+            int p1 = ret.indexOf("sessionToken");
+            int p2 = ret.indexOf('"', p1 + 16);
+
+            tok = ret.substring(p1 + 15, p2);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean securityEnabled() {
+        return true;
     }
 
     /** {@inheritDoc} */
@@ -104,14 +112,8 @@ public class JettyRestProcessorAuthenticationSelfTest 
extends JettyRestProcessor
     @Override protected String restUrl() {
         String url = super.restUrl();
 
-        if (!F.isEmpty(user)) {
-            url += "user=" + user;
-
-            if (!F.isEmpty(pwd))
-                url += "&password=" + pwd;
-
-            url += '&';
-        }
+        if (!F.isEmpty(tok))
+            url += "sessionToken=" + tok + "&";
 
         return url;
     }
@@ -122,19 +124,18 @@ public class JettyRestProcessorAuthenticationSelfTest 
extends JettyRestProcessor
     public void testAuthenticationCommand() throws Exception {
         String ret = content(null, GridRestCommand.AUTHENTICATE);
 
-        assertResponseContainsError(ret, "The user name or password is 
incorrect");
+        assertResponseSucceeded(ret, false);
     }
 
     /**
      * @throws Exception If failed.
      */
-    public void testMissingCredentials() throws Exception {
-        user = null;
-        pwd = null;
+    public void testMissingSessionToken() throws Exception {
+        tok = null;
 
         String ret = content(null, GridRestCommand.VERSION);
 
-        assertResponseSucceeded(ret, false);
+        assertResponseContainsError(ret, "The user name or password is 
incorrect");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/3780ac0a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
----------------------------------------------------------------------
diff --git 
a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
 
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
index e70ef6a..7f20dca 100644
--- 
a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
+++ 
b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java
@@ -69,6 +69,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import org.jetbrains.annotations.Nullable;
 
 import static 
org.apache.ignite.internal.client.GridClientCacheFlag.KEEP_BINARIES_MASK;
+import static 
org.apache.ignite.internal.processors.rest.GridRestCommand.AUTHENTICATE;
 import static 
org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_CONTAINS_KEYS;
 import static 
org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_GET_ALL;
 import static 
org.apache.ignite.internal.processors.rest.GridRestCommand.CACHE_PUT_ALL;
@@ -852,8 +853,11 @@ public class GridJettyRestHandler extends AbstractHandler {
 
         restReq.command(cmd);
 
-        if (!credentials(params, USER_PARAM, PWD_PARAM, restReq))
-            credentials(params, IGNITE_LOGIN_PARAM, IGNITE_PASSWORD_PARAM, 
restReq);
+        // Check credentials only for AUTHENTICATE command.
+        if (cmd == AUTHENTICATE) {
+            if (!credentials(params, USER_PARAM, PWD_PARAM, restReq))
+                credentials(params, IGNITE_LOGIN_PARAM, IGNITE_PASSWORD_PARAM, 
restReq);
+        }
 
         String clientId = (String)params.get("clientId");
 

Reply via email to