RIFT-14989: Login fixes for Accounts and RO Config pages 88/588/1
authorLaurence Maultsby <laurence.maultsby@riftio.com>
Mon, 31 Oct 2016 20:32:53 +0000 (16:32 -0400)
committerLaurence Maultsby <laurence.maultsby@riftio.com>
Mon, 31 Oct 2016 20:32:53 +0000 (16:32 -0400)
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
skyquake/framework/core/api_utils/utils.js
skyquake/framework/core/modules/routes/configuration.js
skyquake/framework/utils/utils.js
skyquake/plugins/accounts/api/accounts.js
skyquake/plugins/accounts/src/account/account.jsx
skyquake/plugins/accounts/src/account/accountSource.js
skyquake/plugins/accounts/src/account/accountStore.js
skyquake/plugins/config/src/dashboard/configStore.js
skyquake/plugins/config/src/dashboard/dashboard.jsx

index 163769a..0d1990c 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -233,5 +233,5 @@ module.exports = {
 
        sendSuccessResponse: sendSuccessResponse,
 
 
        sendSuccessResponse: sendSuccessResponse,
 
-       passThroughConstructor: passThroughConstructor
+    passThroughConstructor: passThroughConstructor
 };
 };
index 3a686f0..b789ff0 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
 
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@
  */
 
 /**
  */
 
 /**
- * Node configuration routes module. 
+ * Node configuration routes module.
  * Provides a RESTful API to provide configuration
  * details such as api_server.
  * @module framework/core/modules/routes/configuration
  * Provides a RESTful API to provide configuration
  * details such as api_server.
  * @module framework/core/modules/routes/configuration
@@ -30,6 +30,9 @@ var bodyParser = require('body-parser');
 var configurationAPI = require('../api/configuration');
 var Router = require('express').Router();
 var utils = require('../../api_utils/utils');
 var configurationAPI = require('../api/configuration');
 var Router = require('express').Router();
 var utils = require('../../api_utils/utils');
+var CONSTANTS = require('../../api_utils/constants.js');
+var request = require('request');
+var _ = require('lodash');
 
 Router.use(bodyParser.json());
 Router.use(cors());
 
 Router.use(bodyParser.json());
 Router.use(cors());
@@ -48,9 +51,43 @@ Router.put('/server-configuration', cors(), function(req, res) {
 Router.get('/server-configuration', cors(), function(req, res) {
     configurationAPI.get(req).then(function(data) {
         utils.sendSuccessResponse(data, res);
 Router.get('/server-configuration', cors(), function(req, res) {
     configurationAPI.get(req).then(function(data) {
         utils.sendSuccessResponse(data, res);
-       }, function(error) {
-               utils.sendErrorResponse(error, res);
-       });
+    }, function(error) {
+        utils.sendErrorResponse(error, res);
+    });
+});
+
+Router.get('/check-auth', function(req, res) {
+    console.log('testing auth')
+    var api_server = req.query["api_server"];
+    var uri = utils.confdPort(api_server) + '/api/config/';
+
+    checkAuth(uri, req).then(function(data) {
+        utils.sendSuccessResponse(data, res);
+    }, function(error) {
+        utils.sendErrorResponse(error, res);
+    });
 });
 
 });
 
+function checkAuth(uri, req){
+    return new Promise(function(resolve, reject) {
+        request({
+            uri: uri,
+            method: 'GET',
+            headers: _.extend({}, {
+                'Authorization': req.get('Authorization'),
+                forever: CONSTANTS.FOREVER_ON,
+                rejectUnauthorized: false,
+            })
+        }, function(error, response, body) {
+            console.log(arguments)
+            if( response.statusCode == 401) {
+                reject({statusCode: 401, error: response.body});
+            } else {
+                resolve({statusCode:200, data:response.body})
+            }
+        });
+    });
+}
+
+
 module.exports = Router;
 module.exports = Router;
index d08fe5f..7442027 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -20,7 +20,7 @@ var AuthActions = require('../widgets/login/loginAuthActions.js');
 var $ = require('jquery');
 var rw = require('utils/rw.js');
 var API_SERVER = rw.getSearchParams(window.location).api_server;
 var $ = require('jquery');
 var rw = require('utils/rw.js');
 var API_SERVER = rw.getSearchParams(window.location).api_server;
-var NODE_PORT = 3000;
+let NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
 var SockJS = require('sockjs-client');
 
 var Utils = {};
 var SockJS = require('sockjs-client');
 
 var Utils = {};
@@ -188,9 +188,20 @@ Utils.setAuthentication = function(username, password, cb) {
     var AuthBase64 = btoa(username + ":" + password);
     window.sessionStorage.setItem("auth", AuthBase64);
     self.detectInactivity();
     var AuthBase64 = btoa(username + ":" + password);
     window.sessionStorage.setItem("auth", AuthBase64);
     self.detectInactivity();
-    if (cb) {
-        cb();
-    }
+    $.ajax({
+            url: '//' + window.location.hostname + ':' + NODE_PORT + '/check-auth?api_server=' + API_SERVER,
+            type: 'GET',
+            beforeSend: Utils.addAuthorizationStub,
+            success: function(data) {
+              //console.log("LoggingSource.getLoggingConfig success call. data=", data);
+                if (cb) {
+                    cb();
+                };
+            },
+            error: function(data) {
+                Utils.clearAuthentication();
+            }
+          });
 }
 Utils.clearAuthentication = function(callback) {
     var self = this;
 }
 Utils.clearAuthentication = function(callback) {
     var self = this;
index 215032b..ec74f51 100644 (file)
@@ -42,7 +42,9 @@ Accounts.get = function(req) {
                             type: req.params.type
                         })
                     });
                             type: req.params.type
                         })
                     });
-                })
+                }, function(reason) {
+            reject(reason);
+        })
         } else {
             getAll(req, resolve, reject);
         }
         } else {
             getAll(req, resolve, reject);
         }
@@ -66,6 +68,8 @@ Accounts.get = function(req) {
                 statusCode: 200,
                 data: ReturnData
             });
                 statusCode: 200,
                 data: ReturnData
             });
+        }, function(reason) {
+            reject(reason);
         })
     }
 }
         })
     }
 }
index a3b0bf1..45b31fc 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * 
+ *
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   Copyright 2016 RIFT.IO Inc
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,6 +47,7 @@ class Account extends React.Component {
         }
     }
     componentWillUnmount() {
         }
     }
     componentWillUnmount() {
+        this.props.store.closeSocket();
         this.props.store.unlisten(this.storeListener);
     }
     setUp(props){
         this.props.store.unlisten(this.storeListener);
     }
     setUp(props){
index 4506724..c0fd36b 100644 (file)
@@ -34,6 +34,7 @@ module.exports = function(Alt) {
             return new Promise(function(resolve, reject) {
               //If socket connection already exists, eat the request.
               if(state.socket) {
             return new Promise(function(resolve, reject) {
               //If socket connection already exists, eat the request.
               if(state.socket) {
+                console.log('connection already exists')
                 return resolve(false);
               }
                $.ajax({
                 return resolve(false);
               }
                $.ajax({
index 29a15e2..1267fab 100644 (file)
@@ -18,7 +18,7 @@
 import AccountActions from './accountActions.js';
 import AccountSource from './accountSource.js';
 
 import AccountActions from './accountActions.js';
 import AccountSource from './accountSource.js';
 
-
+var Utils = require('utils/utils.js');
 var rw = require('utils/rw.js');
 var altImage = rw.getSearchParams(window.location).alt_image;
 
 var rw = require('utils/rw.js');
 var altImage = rw.getSearchParams(window.location).alt_image;
 
@@ -252,7 +252,6 @@ export default class AccountStore {
     openAccountSocketSuccess = (connection) => {
         let self = this;
         let  ws = window.multiplexer.channel(connection);
     openAccountSocketSuccess = (connection) => {
         let self = this;
         let  ws = window.multiplexer.channel(connection);
-
         if (!connection) return;
         this.setState({
             socket: ws.ws,
         if (!connection) return;
         this.setState({
             socket: ws.ws,
@@ -261,6 +260,9 @@ export default class AccountStore {
         ws.onmessage = (socket) => {
             try {
                 var data = JSON.parse(socket.data);
         ws.onmessage = (socket) => {
             try {
                 var data = JSON.parse(socket.data);
+                Utils.checkAuthentication(data.statusCode, function() {
+                    self.closeSocket();
+                });
                 let SdnOptions = [{
                     label: 'Select an SDN Account',
                     value: false
                 let SdnOptions = [{
                     label: 'Select an SDN Account',
                     value: false
@@ -407,18 +409,3 @@ export default class AccountStore {
     }
 }
 
     }
 }
 
-
-/**
- *Cloud
- *
- * {"name":"eng2","account-type":"openstack","openstack":{"key":"lmaultsb","secret":"mypasswd","auth_url":"http://engstack.eng.riftio.com:5000/v3/","tenant":"lmaultsb","mgmt-network":"private"}}
-Name
-Path
-
-
-SDN
-
-
- *
- *
- */
index c5ba696..54f3568 100644 (file)
@@ -52,7 +52,7 @@ let AccountMeta = {
     }
 }
 
     }
 }
 
-export default class AccountStore {
+export default class ConfigStore {
     constructor() {
         this.account = {};
         this.accountType = 'openmano';
     constructor() {
         this.account = {};
         this.accountType = 'openmano';
index b8a743f..99bff06 100644 (file)
@@ -123,7 +123,6 @@ class ConfigDashboard extends React.Component {
                             }
                 </div>
                 <div className="form-actions">
                             }
                 </div>
                 <div className="form-actions">
-                    <Button  className="light" label="Cancel" />
                     <Button key="4" role="button" className="update dark" label="Update"  onClick={this.updateAccount} />
                 </div>
             </form>
                     <Button key="4" role="button" className="update dark" label="Update"  onClick={this.updateAccount} />
                 </div>
             </form>