You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2018/04/13 03:17:01 UTC

ignite git commit: IGNITE-8201 REST: Fixed old API.

Repository: ignite
Updated Branches:
  refs/heads/ignite-8201 bc20f7827 -> f31452dc8


IGNITE-8201 REST: Fixed old API.


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

Branch: refs/heads/ignite-8201
Commit: f31452dc84e36ba3decda7de48cfc708bb000c02
Parents: bc20f78
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Fri Apr 13 10:16:52 2018 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Fri Apr 13 10:16:52 2018 +0700

----------------------------------------------------------------------
 .../client/suite/IgniteClientTestSuite.java     |  6 +-
 ...ettyRestProcessorAuthenticationSelfTest.java | 71 +----------------
 ...rocessorAuthenticationWithCredsSelfTest.java | 32 ++++++++
 ...rocessorAuthenticationWithTokenSelfTest.java | 80 ++++++++++++++++++++
 .../processors/rest/GridRestProcessor.java      |  2 +-
 5 files changed, 120 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f31452dc/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java b/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java
index 79fcf38..163f89a 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/client/suite/IgniteClientTestSuite.java
@@ -49,7 +49,8 @@ import org.apache.ignite.internal.client.util.ClientByteUtilsTest;
 import org.apache.ignite.internal.client.util.ClientConsistentHashSelfTest;
 import org.apache.ignite.internal.client.util.ClientJavaHasherSelfTest;
 import org.apache.ignite.internal.processors.rest.ClientMemcachedProtocolSelfTest;
-import org.apache.ignite.internal.processors.rest.JettyRestProcessorAuthenticationSelfTest;
+import org.apache.ignite.internal.processors.rest.JettyRestProcessorAuthenticationWithCredsSelfTest;
+import org.apache.ignite.internal.processors.rest.JettyRestProcessorAuthenticationWithTokenSelfTest;
 import org.apache.ignite.internal.processors.rest.JettyRestProcessorSignedSelfTest;
 import org.apache.ignite.internal.processors.rest.JettyRestProcessorUnsignedSelfTest;
 import org.apache.ignite.internal.processors.rest.RestBinaryProtocolSelfTest;
@@ -87,7 +88,8 @@ public class IgniteClientTestSuite extends TestSuite {
         // Test jetty rest processor
         suite.addTestSuite(JettyRestProcessorSignedSelfTest.class);
         suite.addTestSuite(JettyRestProcessorUnsignedSelfTest.class);
-        suite.addTestSuite(JettyRestProcessorAuthenticationSelfTest.class);
+        suite.addTestSuite(JettyRestProcessorAuthenticationWithCredsSelfTest.class);
+        suite.addTestSuite(JettyRestProcessorAuthenticationWithTokenSelfTest.class);
 
         // Test TCP rest processor with original memcache client.
         suite.addTestSuite(ClientMemcachedProtocolSelfTest.class);

http://git-wip-us.apache.org/repos/asf/ignite/blob/f31452dc/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 fd52ee7..27b8c03 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
@@ -24,7 +24,6 @@ import org.apache.ignite.configuration.DataStorageConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.processors.authentication.IgniteAccessControlException;
 import org.apache.ignite.internal.processors.authentication.IgniteAuthenticationProcessor;
-import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.testframework.GridTestUtils;
 
@@ -33,15 +32,12 @@ import static org.apache.ignite.configuration.WALMode.NONE;
 /**
  * Test REST with enabled authentication.
  */
-public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessorUnsignedSelfTest {
+public abstract class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessorUnsignedSelfTest {
     /** */
-    private static final String DFLT_USER = "ignite";
+    protected static final String DFLT_USER = "ignite";
 
     /** */
-    private static final String DFLT_PWD = "ignite";
-
-    /** */
-    private String tok = "";
+    protected static final String DFLT_PWD = "ignite";
 
     /** {@inheritDoc} */
     @Override protected void beforeTestsStarted() throws Exception {
@@ -51,23 +47,6 @@ public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessor
     }
 
     /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        super.beforeTest();
-
-        // 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;
     }
@@ -108,16 +87,6 @@ public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessor
         return cfg;
     }
 
-    /** {@inheritDoc} */
-    @Override protected String restUrl() {
-        String url = super.restUrl();
-
-        if (!F.isEmpty(tok))
-            url += "sessionToken=" + tok + "&";
-
-        return url;
-    }
-
     /**
      * @throws Exception If failed.
      */
@@ -130,40 +99,6 @@ public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessor
     /**
      * @throws Exception If failed.
      */
-    public void testInvalidSessionToken() throws Exception {
-        tok = null;
-
-        String ret = content(null, GridRestCommand.VERSION);
-
-        assertResponseContainsError(ret, "Failed to handle request - session token not found or invalid");
-
-        tok = "InvalidToken";
-
-        ret = content(null, GridRestCommand.VERSION);
-
-        assertResponseContainsError(ret, "Failed to handle request - session token not found or invalid");
-
-        tok = "26BE027D32CC42329DEC92D517B44E9E";
-
-        ret = content(null, GridRestCommand.VERSION);
-
-        assertResponseContainsError(ret, "Failed to handle request - unknown session token (maybe expired session)");
-
-        tok = null; // Cleanup token for next tests.
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testWithToken() throws Exception {
-        String ret = content(null, GridRestCommand.VERSION);
-
-        assertResponseSucceeded(ret, false);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
     public void testAddUpdateRemoveUser() throws Exception {
         // Add user.
         String ret = content(null, GridRestCommand.ADD_USER,

http://git-wip-us.apache.org/repos/asf/ignite/blob/f31452dc/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java
new file mode 100644
index 0000000..c75e8a9
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithCredsSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.ignite.internal.processors.rest;
+
+/**
+ * Test REST with enabled authentication and credentials in each request.
+ */
+public class JettyRestProcessorAuthenticationWithCredsSelfTest extends JettyRestProcessorAuthenticationSelfTest {
+    /** {@inheritDoc} */
+    @Override protected String restUrl() {
+        String url = super.restUrl();
+
+        url += "ignite.login=" + DFLT_USER + "&ignite.password=" + DFLT_PWD + "&";
+
+        return url;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f31452dc/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java
new file mode 100644
index 0000000..5c046af
--- /dev/null
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAuthenticationWithTokenSelfTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.ignite.internal.processors.rest;
+
+import org.apache.ignite.internal.util.typedef.F;
+
+/**
+ * Test REST with enabled authentication and token.
+ */
+public class JettyRestProcessorAuthenticationWithTokenSelfTest extends JettyRestProcessorAuthenticationSelfTest {
+    /** */
+    private String tok = "";
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        // 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 String restUrl() {
+        String url = super.restUrl();
+
+        if (!F.isEmpty(tok))
+            url += "sessionToken=" + tok + "&";
+
+        return url;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testInvalidSessionToken() throws Exception {
+        tok = null;
+
+        String ret = content(null, GridRestCommand.VERSION);
+
+        assertResponseContainsError(ret, "Failed to handle request - session token not found or invalid");
+
+        tok = "InvalidToken";
+
+        ret = content(null, GridRestCommand.VERSION);
+
+        assertResponseContainsError(ret, "Failed to handle request - session token not found or invalid");
+
+        tok = "26BE027D32CC42329DEC92D517B44E9E";
+
+        ret = content(null, GridRestCommand.VERSION);
+
+        assertResponseContainsError(ret, "Failed to handle request - unknown session token (maybe expired session)");
+
+        tok = null; // Cleanup token for next tests.
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/f31452dc/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
index 205fb73..6b94e7c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/GridRestProcessor.java
@@ -365,7 +365,7 @@ public class GridRestProcessor extends GridProcessorAdapter {
 
         while (true) {
             if (F.isEmpty(sesTok) && clientId == null) {
-                if (ctx.authentication().enabled() && req.command() != AUTHENTICATE)
+                if (ctx.authentication().enabled() && req.command() != AUTHENTICATE && req.credentials() == null)
                     throw new IgniteAuthenticationException("Failed to handle request - session token not found or invalid");
 
                 Session ses = Session.random();