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/10 13:43:21 UTC

ignite git commit: IGNITE-8201 WIP.

Repository: ignite
Updated Branches:
  refs/heads/ignite-8201 5a1d8a059 -> a80893232


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/a8089323
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a8089323
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a8089323

Branch: refs/heads/ignite-8201
Commit: a8089323273f0ac3e8d5eb9f7460686978414535
Parents: 5a1d8a0
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Tue Apr 10 20:43:12 2018 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Tue Apr 10 20:43:12 2018 +0700

----------------------------------------------------------------------
 .../JettyRestProcessorAbstractSelfTest.java     | 10 +--
 ...ettyRestProcessorAuthenticationSelfTest.java | 26 +++++--
 .../processors/rest/GridRestProcessor.java      |  3 +
 .../auth/AuthenticationCommandHandler.java      | 73 ++++++++++++++++++++
 .../rest/handlers/auth/package-info.java        | 22 ++++++
 .../http/jetty/GridJettyRestHandler.java        |  6 ++
 6 files changed, 128 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a8089323/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
index 5dc44c4..5201b33 100644
--- a/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
+++ b/modules/clients/src/test/java/org/apache/ignite/internal/processors/rest/JettyRestProcessorAbstractSelfTest.java
@@ -779,7 +779,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
 
         assertTrue(res.isObject());
 
-        assertTrue(entries.equals(JSON_MAPPER.treeToValue(res, Map.class)));
+        assertEquals(entries, JSON_MAPPER.treeToValue(res, Map.class));
     }
 
     /**
@@ -1100,7 +1100,7 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
         assertNull(jcache().localPeek("rmvKey2"));
         assertNull(jcache().localPeek("rmvKey3"));
         assertNull(jcache().localPeek("rmvKey4"));
-        assertTrue(jcache().localSize() == 0);
+        assertEquals(0, jcache().localSize());
 
         assertCacheBulkOperation(ret, true);
     }
@@ -1353,20 +1353,20 @@ public abstract class JettyRestProcessorAbstractSelfTest extends AbstractRestPro
             assertNotNull(keyClasses);
             assertFalse(keyClasses.isNull());
 
-            assertTrue(meta.keyClasses().equals(JSON_MAPPER.treeToValue(keyClasses, Map.class)));
+            assertEquals(meta.keyClasses(), JSON_MAPPER.treeToValue(keyClasses, Map.class));
 
             JsonNode valClasses = item.get("valClasses");
 
             assertNotNull(valClasses);
             assertFalse(valClasses.isNull());
 
-            assertTrue(meta.valClasses().equals(JSON_MAPPER.treeToValue(valClasses, Map.class)));
+            assertEquals(meta.valClasses(), JSON_MAPPER.treeToValue(valClasses, Map.class));
 
             JsonNode fields = item.get("fields");
 
             assertNotNull(fields);
             assertFalse(fields.isNull());
-            assertTrue(meta.fields().equals(JSON_MAPPER.treeToValue(fields, Map.class)));
+            assertEquals(meta.fields(), JSON_MAPPER.treeToValue(fields, Map.class));
 
             JsonNode indexesByType = item.get("indexes");
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8089323/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 ca62091..68a96da 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
@@ -35,17 +35,20 @@ import static org.apache.ignite.configuration.WALMode.NONE;
  */
 public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessorUnsignedSelfTest {
     /** */
-    private static final String DFLT_LOGIN = "ignite";
+    private static final String DFLT_USER = "ignite";
 
     /** */
     private static final String DFLT_PWD = "ignite";
 
     /** */
-    private String login = DFLT_LOGIN;
+    private String user = DFLT_USER;
 
     /** */
     private String pwd = DFLT_PWD;
 
+    /** */
+    private String tok = "";
+
     /** {@inheritDoc} */
     @Override protected void beforeTestsStarted() throws Exception {
         U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", true);
@@ -57,7 +60,7 @@ public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessor
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 
-        login = DFLT_LOGIN;
+        user = DFLT_USER;
         pwd = DFLT_PWD;
     }
 
@@ -101,11 +104,11 @@ public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessor
     @Override protected String restUrl() {
         String url = super.restUrl();
 
-        if (!F.isEmpty(login)) {
-            url += "ignite.login=" + login;
+        if (!F.isEmpty(user)) {
+            url += "user=" + user;
 
             if (!F.isEmpty(pwd))
-                url += "&ignite.password=" + pwd;
+                url += "&password=" + pwd;
 
             url += '&';
         }
@@ -116,8 +119,17 @@ public class JettyRestProcessorAuthenticationSelfTest extends JettyRestProcessor
     /**
      * @throws Exception If failed.
      */
+    public void testAuthenticationCommand() throws Exception {
+        String ret = content(null, GridRestCommand.AUTHENTICATE);
+
+        assertResponseContainsError(ret, "The user name or password is incorrect");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testMissingCredentials() throws Exception {
-        login = null;
+        user = null;
         pwd = null;
 
         String ret = content(null, GridRestCommand.VERSION);

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8089323/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 4b8497e..a823be0 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
@@ -45,6 +45,7 @@ import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.authentication.AuthorizationContext;
 import org.apache.ignite.internal.processors.rest.client.message.GridClientTaskResultBean;
 import org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.auth.AuthenticationCommandHandler;
 import org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler;
 import org.apache.ignite.internal.processors.rest.handlers.cluster.GridChangeStateCommandHandler;
 import org.apache.ignite.internal.processors.rest.handlers.datastructures.DataStructuresCommandHandler;
@@ -505,6 +506,7 @@ public class GridRestProcessor extends GridProcessorAdapter {
             addHandler(new GridLogCommandHandler(ctx));
             addHandler(new GridChangeStateCommandHandler(ctx));
             addHandler(new UserActionCommandHandler(ctx));
+            addHandler(new AuthenticationCommandHandler(ctx));
 
             // Start protocols.
             startTcpProtocol();
@@ -860,6 +862,7 @@ public class GridRestProcessor extends GridProcessorAdapter {
             case CLUSTER_CURRENT_STATE:
             case CLUSTER_ACTIVE:
             case CLUSTER_INACTIVE:
+            case AUTHENTICATE:
             case ADD_USER:
             case REMOVE_USER:
             case UPDATE_USER:

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8089323/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/auth/AuthenticationCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/auth/AuthenticationCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/auth/AuthenticationCommandHandler.java
new file mode 100644
index 0000000..0cecf3d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/auth/AuthenticationCommandHandler.java
@@ -0,0 +1,73 @@
+/*
+ * 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.handlers.auth;
+
+import java.util.Collection;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.rest.GridRestCommand;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandlerAdapter;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+
+import static org.apache.ignite.internal.processors.rest.GridRestCommand.AUTHENTICATE;
+
+/**
+ * Authentication handler.
+ */
+public class AuthenticationCommandHandler extends GridRestCommandHandlerAdapter {
+    /** Commands. */
+    private static final Collection<GridRestCommand> SUPPORTED_COMMANDS = U.sealList(AUTHENTICATE);
+
+    /**
+     * @param ctx Context.
+     */
+    public AuthenticationCommandHandler(GridKernalContext ctx) {
+        super(ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<GridRestCommand> supportedCommands() {
+        return SUPPORTED_COMMANDS;
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest req) {
+        assert req != null;
+
+        if (log.isDebugEnabled())
+            log.debug("Handling topology REST request: " + req);
+
+        try {
+            GridRestCommand cmd = req.command();
+
+            if (log.isDebugEnabled())
+                log.debug("Handled topology REST request [req=" + req + ']');
+
+            return new GridFinishedFuture<>(new GridRestResponse(true));
+        }
+        catch (Throwable e) {
+            log.error("Failed to handle REST request [req=" + req + ']', e);
+
+            return new GridFinishedFuture<>(e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8089323/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/auth/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/auth/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/auth/package-info.java
new file mode 100644
index 0000000..1d58218
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/auth/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * REST authentication command.
+ */
+package org.apache.ignite.internal.processors.rest.handlers.auth;

http://git-wip-us.apache.org/repos/asf/ignite/blob/a8089323/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 f784492..e70ef6a 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
@@ -737,6 +737,12 @@ public class GridJettyRestHandler extends AbstractHandler {
                 break;
             }
 
+            case AUTHENTICATE: {
+                restReq = new GridRestRequest();
+
+                break;
+            }
+
             case ADD_USER:
             case REMOVE_USER:
             case UPDATE_USER: {