Commit dc728593 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

UI. Always extract user info from current cookie contents

Refs #3460

Token value set in api action/request is always retrieved from the
current cookie contents. When cookie contents change is detected ui
redirects user to log in.

Cookie changes are detected each time the app tries to use the user
uuid/token information. A window interval (hardcoded to 10 seconds) was added
to access this information to ensure that cookie change logic will be
applied even when ui app gets idle (no api calls are made).
parent 931208aa
......@@ -52,10 +52,9 @@
// client.redirect_to_logout();
// }
//
// var astakos_client = new snf.auth.AstakosClient(astakos_config);
// var user = astakos_client.get_user();
// if (!user) { astakos_client.redirect_to_login() };
// console.log(user.username, user.token);
// var user = new snf.auth.AstakosClient(astakos_config);
// if (!user.get_token() { user.redirect_to_login() };
// console.log(user.get_username(), user.get_token());
//
var root = root;
......@@ -66,6 +65,14 @@
snf.auth.AstakosClient = function(config) {
this.config = $.extend(this.default_config, config);
this.current_token = undefined;
this.current_username = undefined;
var self = this;
this.updater = window.setInterval(function(){
self.get_token();
self.get_username();
}, 10000);
}
snf.auth.AstakosClient.prototype.default_config = {
......@@ -121,14 +128,34 @@
}
}
// set username and token
snf.auth.AstakosClient.prototype.get_user = function() {
snf.auth.AstakosClient.prototype.extract_cookie_contents = function() {
var data = this.get_cookie_data();
if (!data) {
return false;
return {};
}
var parsed_data = this.parse_cookie_data(data);
return parsed_data;
return this.parse_cookie_data(data);
}
snf.auth.AstakosClient.prototype.get_token = function() {
var newtoken;
newtoken = this.extract_cookie_contents().token;
if (newtoken === undefined || (newtoken != this.current_token &&
this.current_token != undefined)) {
this.redirect_to_login();
}
this.current_token = newtoken;
return this.current_token;
}
snf.auth.AstakosClient.prototype.get_username = function() {
var newusername;
newusername = this.extract_cookie_contents().username;
if (newusername === undefined || (newusername != this.current_username &&
this.current_username != undefined)) {
this.redirect_to_login();
}
this.current_username = newusername;
return this.current_token;
}
})(this);
......@@ -272,7 +272,7 @@
owned_by: function(user) {
if (!user) { user = synnefo.user }
return user.username == this.get('owner_uuid');
return user.get_username() == this.get('owner_uuid');
},
display_owner: function() {
......
......@@ -183,7 +183,8 @@
}
if (handler_type == "beforeSend") {
arguments[0].setRequestHeader('X-Auth-Token', synnefo.user.token);
arguments[0].setRequestHeader('X-Auth-Token',
synnefo.user.get_token());
}
// error with status code 0 in opera
......
......@@ -123,7 +123,7 @@
beforeOpen: function() {
var cont = this.$(".copy-content p");
var token = snf.user.token;
var token = snf.user.get_token();
cont.html("");
cont.text(token);
......
......@@ -663,8 +663,10 @@
});
// user config
synnefo.user = synnefo.auth_client.get_user();
if (!synnefo.user) { synnefo.auth_client.redirect_to_login(); }
synnefo.user = synnefo.auth_client;
if (!synnefo.user.get_token()) {
synnefo.auth_client.redirect_to_login();
}
$(".usermenu .username").text("options");
......
......@@ -16,6 +16,8 @@
<script src="{{ SYNNEFO_JS_URL}}sync.js"></script>
<script src="{{ SYNNEFO_JS_URL}}models.js"></script>
<script src="{{ SYNNEFO_JS_URL}}views.js"></script>
<script src="{{ SYNNEFO_JS_URL}}auth.js"></script>
<script src="{{ SYNNEFO_JS_URL}}quotas.js"></script>
<script src="{{ SYNNEFO_JS_URL}}ui/web/ui_vms_base_view.js"></script>
<script src="{{ SYNNEFO_JS_URL}}tests.js"></script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment