ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject ignite git commit: IGNITE-843 Reworked from password to token.
Date Tue, 08 Sep 2015 07:30:49 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843 b9a95ef34 -> 9f9265d1b


IGNITE-843 Reworked from password to token.


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

Branch: refs/heads/ignite-843
Commit: 9f9265d1b790bc4d7bcda5084461c40fc73e818a
Parents: b9a95ef
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Tue Sep 8 14:31:25 2015 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Tue Sep 8 14:31:25 2015 +0700

----------------------------------------------------------------------
 modules/control-center-agent/README.txt         | 11 ++--
 .../apache/ignite/agent/AgentConfiguration.java | 24 ++++----
 .../org/apache/ignite/agent/AgentLauncher.java  |  6 +-
 .../org/apache/ignite/agent/AgentSocket.java    |  2 +-
 .../src/main/js/agents/agent-manager.js         | 24 ++++----
 .../main/js/controllers/profile-controller.js   | 13 +++-
 modules/control-center-web/src/main/js/db.js    |  2 +
 .../src/main/js/helpers/common-utils.js         | 19 +++---
 .../src/main/js/public/stylesheets/style.scss   | 21 +------
 .../src/main/js/routes/profile.js               | 64 ++++++++++++--------
 .../src/main/js/routes/public.js                | 10 ++-
 .../main/js/views/configuration/sidebar.jade    |  1 -
 .../src/main/js/views/settings/profile.jade     |  4 ++
 .../src/main/js/views/templates/layout.jade     |  2 +
 14 files changed, 115 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-agent/README.txt
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/README.txt b/modules/control-center-agent/README.txt
index 5094ca3..f59295e 100644
--- a/modules/control-center-agent/README.txt
+++ b/modules/control-center-agent/README.txt
@@ -11,11 +11,13 @@ Two main functions of Ignite Web Agent:
     You may need to copy JDBC driver into "./jdbc-drivers" subfolder or specify path via
"-drv" option.
 
 Usage example:
-    ignite-control-center-agent.sh -l john.smith@gmail.com -p qwerty -s wss://control-center.example.com
+    ignite-control-center-agent.sh -l john.smith@gmail.com -t 1a2b3c4d5f -s wss://control-center.example.com
 
 Test drive of Ignite Web Agent:
     In order to simplify evaluation two test drive modes were implemented:
 
+    1) Get access token on Web Control Center "Profile" screen.
+
     1) Test drive for metadata load from database. Activated by option: -tm or --test-drive-metadata.
        In this mode an in-memory H2 database will started.
        How to evaluate:
@@ -45,7 +47,7 @@ Configuration file:
 
     Available entries names:
         login
-        password
+        token
         serverURI
         nodeURI
         driverFolder
@@ -54,6 +56,7 @@ Configuration file:
 
     Example configuration file:
         login=john.smith@gmail.com
+        token=1a2b3c4d5f
         serverURI=wss://control-center.example.com:3001
         test-drive-sql=true
 
@@ -75,8 +78,8 @@ Options:
        URI for connect to Ignite REST server, for example: "http://localhost:8080".
        Default: "http://localhost:8080".
 
-    -p, --password
-       User's password.
+    -t, --token
+       User's access token.
 
     -s, --server-uri
        URI for connect to Ignite Web Agent, for example: "wss://control-center.example.com:3001".

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
index 0a3550e..bde628d 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java
@@ -39,8 +39,8 @@ public class AgentConfiguration {
     private String login;
 
     /** */
-    @Parameter(names = {"-p", "--password"}, description = "User's password")
-    private String pwd;
+    @Parameter(names = {"-t", "--token"}, description = "User's access token")
+    private String token;
 
     /** */
     @Parameter(names = {"-s", "--server-uri"}, description = "URI for connect to Ignite Web
Control Center via " +
@@ -91,17 +91,17 @@ public class AgentConfiguration {
     }
 
     /**
-     * @return Password.
+     * @return Token.
      */
-    public String password() {
-        return pwd;
+    public String token() {
+        return token;
     }
 
     /**
-     * @param pwd Password.
+     * @param token Token.
      */
-    public void password(String pwd) {
-        this.pwd = pwd;
+    public void token(String token) {
+        this.token = token;
     }
 
     /**
@@ -203,10 +203,10 @@ public class AgentConfiguration {
         if (val != null)
             login(val);
 
-        val = (String)props.remove("password");
+        val = (String)props.remove("token");
 
         if (val != null)
-            password(val);
+            token(val);
 
         val = (String)props.remove("serverURI");
 
@@ -241,8 +241,8 @@ public class AgentConfiguration {
         if (cmd.login() != null)
             login(cmd.login());
 
-        if (cmd.password() != null)
-            password(cmd.password());
+        if (cmd.token() != null)
+            token(cmd.token());
 
         if (cmd.serverUri() != null)
             serverUri(cmd.serverUri());

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
index 01de963..7ec4c2a 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java
@@ -76,10 +76,10 @@ public class AgentLauncher {
             cfg.login(System.console().readLine().trim());
         }
 
-        if (cfg.password() == null) {
-            System.out.print("Password: ");
+        if (cfg.token() == null) {
+            System.out.print("Token: ");
 
-            cfg.password(new String(System.console().readPassword()));
+            cfg.token(new String(System.console().readPassword()));
         }
 
         RestExecutor restExecutor = new RestExecutor(cfg);

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
----------------------------------------------------------------------
diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
index d66393b..7a87616 100644
--- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
+++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java
@@ -106,7 +106,7 @@ public class AgentSocket implements WebSocketSender {
 
         authMsg.addProperty("type", "AuthMessage");
         authMsg.addProperty("login", cfg.login());
-        authMsg.addProperty("password", cfg.password());
+        authMsg.addProperty("token", cfg.token());
 
         send(authMsg);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/agents/agent-manager.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/agents/agent-manager.js b/modules/control-center-web/src/main/js/agents/agent-manager.js
index e3c7846..8d4db6f 100644
--- a/modules/control-center-web/src/main/js/agents/agent-manager.js
+++ b/modules/control-center-web/src/main/js/agents/agent-manager.js
@@ -237,20 +237,22 @@ Client.prototype._rmtAuthMessage = function(msg) {
             self.authResult('User not found');
         }
         else {
-            account.authenticate(msg.password, function(err, user, res) {
-                if (!user) {
-                    self.authResult(res.message);
-                }
-                else {
-                    self.authResult(null);
+            var token = account.token;
 
-                    self._user = account;
+            if (!token)
+                token = account._id;
 
-                    self._manager._addClient(account._id, self);
+            if (token == msg.token) {
+                self.authResult(null);
 
-                    self._ignite = new apacheIgnite.Ignite(new AgentServer(self));
-                }
-            });
+                self._user = account;
+
+                self._manager._addClient(account._id, self);
+
+                self._ignite = new apacheIgnite.Ignite(new AgentServer(self));
+            }
+            else
+                self.authResult('Invalid token');
         }
     });
 };

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/controllers/profile-controller.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/controllers/profile-controller.js b/modules/control-center-web/src/main/js/controllers/profile-controller.js
index eb6b807..3c74596 100644
--- a/modules/control-center-web/src/main/js/controllers/profile-controller.js
+++ b/modules/control-center-web/src/main/js/controllers/profile-controller.js
@@ -19,6 +19,13 @@
 controlCenterModule.controller('profileController', ['$scope', '$http', '$common', function
($scope, $http, $common) {
     $scope.profileUser = angular.copy($scope.user);
 
+    if ($scope.profileUser && !$scope.profileUser.token)
+        $scope.profileUser.token = $scope.profileUser._id;
+
+    $scope.generateToken = function () {
+        $scope.profileUser.token = $commonUtils.randomString(20);
+    };
+
     $scope.saveUser = function () {
         var profile = $scope.profileUser;
 
@@ -29,11 +36,15 @@ controlCenterModule.controller('profileController', ['$scope', '$http',
'$common
             var email = profile.email;
             var changeEmail = email != $scope.user.email;
 
-            if (changeUsername || changeEmail || profile.changePassword) {
+            var token = profile.token;
+            var changeToken = token != $scope.user.token;
+
+            if (changeUsername || changeEmail || changeToken || profile.changePassword) {
                 $http.post('/profile/save', {
                     _id: profile._id,
                     userName: changeUsername ? userName : undefined,
                     email: changeEmail ? email : undefined,
+                    token: changeToken ? token : undefined,
                     newPassword: profile.changePassword ? profile.newPassword : undefined
                 }).success(function (user) {
                     $common.showInfo('Profile saved.');

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/db.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/db.js b/modules/control-center-web/src/main/js/db.js
index e8eb270..88011d1 100644
--- a/modules/control-center-web/src/main/js/db.js
+++ b/modules/control-center-web/src/main/js/db.js
@@ -34,6 +34,7 @@ var AccountSchema = new Schema({
     email: String,
     lastLogin: Date,
     admin: Boolean,
+    token: String,
     resetPasswordToken: String
 });
 
@@ -49,6 +50,7 @@ AccountSchema.set('toJSON', {
             email: ret.email,
             username: ret.username,
             admin: ret.admin,
+            token: ret.token,
             lastLogin: ret.lastLogin
         };
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/helpers/common-utils.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/helpers/common-utils.js b/modules/control-center-web/src/main/js/helpers/common-utils.js
index 6fad73f..b8dd058 100644
--- a/modules/control-center-web/src/main/js/helpers/common-utils.js
+++ b/modules/control-center-web/src/main/js/helpers/common-utils.js
@@ -42,14 +42,19 @@ $commonUtils.hasProperty = function (obj, props) {
     return false;
 };
 
+$commonUtils.randomString = function (len) {
+    var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+    var possibleLen = possible.length;
+
+    var res = '';
+
+    for (var i = 0; i < len; i++)
+        res += possible.charAt(Math.floor(Math.random() * possibleLen));
+
+    return res;
+};
+
 // For server side we should export Java code generation entry point.
 if (typeof window === 'undefined') {
-    // Generate random HEX string. Server side only.
-    $commonUtils.randomValueHex = function randomValueHex(len) {
-        return require('crypto').randomBytes(Math.ceil(len / 2))
-            .toString('hex') // convert to hexadecimal format
-            .slice(0, len);  // return required number of characters
-    };
-
     module.exports = $commonUtils;
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/public/stylesheets/style.scss
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/public/stylesheets/style.scss b/modules/control-center-web/src/main/js/public/stylesheets/style.scss
index a4058e8..2735da8 100644
--- a/modules/control-center-web/src/main/js/public/stylesheets/style.scss
+++ b/modules/control-center-web/src/main/js/public/stylesheets/style.scss
@@ -857,41 +857,22 @@ label {
     margin-right: 0;
 }
 
-.fa-eye {
-    cursor: pointer;
-}
-
-.fa-plus {
+.fa {
     cursor: pointer;
 }
 
 .fa-remove {
     color: $brand-primary;
-    cursor: pointer;
-}
-
-.fa-floppy-o {
-    cursor: pointer;
-}
-
-.fa-arrow-up {
-    cursor: pointer;
-}
-
-.fa-arrow-down {
-    cursor: pointer;
 }
 
 .fa-chevron-circle-down {
     color: $brand-primary;
-    cursor: pointer;
     margin-right: 5px;
     font-size: 16px;
 }
 
 .fa-chevron-circle-up {
     color: $brand-primary;
-    cursor: pointer;
     margin-right: 5px;
     font-size: 16px;
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/profile.js b/modules/control-center-web/src/main/js/routes/profile.js
index bc73671..b772f21 100644
--- a/modules/control-center-web/src/main/js/routes/profile.js
+++ b/modules/control-center-web/src/main/js/routes/profile.js
@@ -32,6 +32,30 @@ router.get('/', function (req, res) {
     });
 });
 
+function updateUser(user, params) {
+    var updated = false;
+
+    if (params.userName) {
+        user.username = params.userName;
+
+        updated = true;
+    }
+
+    if (params.email) {
+        user.email = params.email;
+
+        updated = true;
+    }
+
+    if (params.token) {
+        user.token = params.token;
+
+        updated = true;
+    }
+
+    return updated;
+}
+
 /**
  * Save user profile.
  */
@@ -48,40 +72,30 @@ router.post('/save', function (req, res) {
             if (err)
                 return res.status(500).send(err);
 
-            user.setPassword(newPassword, function (err, updatedUser) {
+            user.setPassword(newPassword, function (err, user) {
                 if (err)
                     return res.status(500).send(err.message);
 
-                if (params.userName)
-                    updatedUser.username = params.userName;
-
-                if (params.email)
-                    updatedUser.email = params.email;
+                if (updateUser(user, params))
+                    user.save(function (err) {
+                        if (err)
+                            return res.status(500).send(err.message);
 
-                updatedUser.save(function (err) {
-                    if (err)
-                        return res.status(500).send(err.message);
-
-                    res.json(user);
-                });
+                        res.json(user);
+                    });
             });
         });
     }
-    else if (params.userName || params.email) {
-        var upd = {};
-
-        if (params.userName)
-            upd.username = params.userName;
+    else {
+        var user = {};
 
-        if (params.email)
-            upd.email = params.email;
-
-        db.Account.findByIdAndUpdate(params._id, upd, {new: true}, function (err, val) {
-            if (err)
-                return res.status(500).send(err.message);
+        if (updateUser(user, params))
+            db.Account.findByIdAndUpdate(params._id, user, {'new': true}, function (err,
val) {
+                if (err)
+                    return res.status(500).send(err.message);
 
-            res.json(val);
-        })
+                res.json(val);
+            })
     }
 });
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/routes/public.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/public.js b/modules/control-center-web/src/main/js/routes/public.js
index e65bf46..c325bad 100644
--- a/modules/control-center-web/src/main/js/routes/public.js
+++ b/modules/control-center-web/src/main/js/routes/public.js
@@ -21,7 +21,7 @@ var nodemailer = require('nodemailer');
 
 var db = require('../db');
 var config = require('../helpers/configuration-loader.js');
-var utils = require('./../helpers/common-utils');
+var $commonUtils = require('./../helpers/common-utils');
 
 // GET dropdown-menu template.
 router.get('/select', function (req, res) {
@@ -58,7 +58,11 @@ router.post('/register', function (req, res) {
 
         req.body.admin = cnt == 0;
 
-        db.Account.register(new db.Account(req.body), req.body.password, function (err, account)
{
+        var account = new db.Account(req.body);
+
+        account.token = $commonUtils.randomString(20);
+
+        db.Account.register(account, req.body.password, function (err, account) {
             if (err)
                 return res.status(401).send(err.message);
 
@@ -122,7 +126,7 @@ router.post('/password/forgot', function(req, res) {
         return res.status(401).send('Can\'t send e-mail with instructions to reset password.<br
/>' +
             'Please ask webmaster to setup smtp server!');
 
-    var token = utils.randomValueHex(20);
+    var token = $commonUtils.randomString(20);
 
     db.Account.findOne({ email: req.body.email }, function(err, user) {
         if (!user)

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/views/configuration/sidebar.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/configuration/sidebar.jade b/modules/control-center-web/src/main/js/views/configuration/sidebar.jade
index 48f0341..c5410c2 100644
--- a/modules/control-center-web/src/main/js/views/configuration/sidebar.jade
+++ b/modules/control-center-web/src/main/js/views/configuration/sidebar.jade
@@ -17,7 +17,6 @@
 extends ../templates/layout
 
 append scripts
-    script(src='/common-utils.js')
     script(src='/data-structures.js')
     script(src='/generator-common.js')
     script(src='/generator-xml.js')

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/views/settings/profile.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/settings/profile.jade b/modules/control-center-web/src/main/js/views/settings/profile.jade
index 7451d2a..1c5bb4e 100644
--- a/modules/control-center-web/src/main/js/views/settings/profile.jade
+++ b/modules/control-center-web/src/main/js/views/settings/profile.jade
@@ -40,6 +40,10 @@ block container
                             .col-xs-5.col-sm-4
                                 input.form-control(type='email' ng-model='profileUser.email'
placeholder='you@domain.com' required)
                         .details-row
+                            +lbl('Access token:')
+                            label {{profileUser.token}}
+                            i.tipLabel.fa.fa-refresh(ng-click='generateToken()' bs-tooltip
data-title='Generate random access token')
+                        .details-row
                             .checkbox
                                 label
                                     input(type='checkbox' ng-model='profileUser.changePassword')

http://git-wip-us.apache.org/repos/asf/ignite/blob/9f9265d1/modules/control-center-web/src/main/js/views/templates/layout.jade
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/views/templates/layout.jade b/modules/control-center-web/src/main/js/views/templates/layout.jade
index 823b1a6..0959b65 100644
--- a/modules/control-center-web/src/main/js/views/templates/layout.jade
+++ b/modules/control-center-web/src/main/js/views/templates/layout.jade
@@ -30,6 +30,8 @@ html(ng-app='ignite-web-control-center' ng-init='user = #{JSON.stringify(user)};
             link(rel='stylesheet', href='/stylesheets/style.css')
 
         block scripts
+            script(src='/common-utils.js')
+
             script(src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js')
 
             script(src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js')


Mime
View raw message