From 85df40e376311beed51d1c21104414c8c3c9b2bf Mon Sep 17 00:00:00 2001 From: aalonsog Date: Tue, 9 Jun 2015 15:03:26 +0200 Subject: [PATCH] Added support for public paths --- config.js.template | 4 ++++ controllers/root.js | 32 +++++++++++++++++++++----------- server.js | 5 +++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/config.js.template b/config.js.template index f58b556..06efef9 100644 --- a/config.js.template +++ b/config.js.template @@ -33,6 +33,10 @@ config.azf = { path: '/authzforce/domains/d698df7f-ffd4-11e4-a09d-ed06f24e1e78/pdp' }; +// list of paths that will not check authentication/authorization +// example: ['/public/*', '/static/css/'] +config.public_paths = []; + // options: oauth2/keystone config.tokens_engine = 'oauth2'; diff --git a/controllers/root.js b/controllers/root.js index 6413a53..e0a1b2c 100644 --- a/controllers/root.js +++ b/controllers/root.js @@ -71,20 +71,29 @@ var Root = (function() { }; }; + var public = function(req, res) { + redir_request(req, res); + }; + var redir_request = function (req, res, user_info) { - console.log('[TOKEN] Access-token OK. Redirecting to app...'); + if (user_info) { - if (config.tokens_engine === 'keystone') { - req.headers['X-Nick-Name'] = user_info.token.user.id; - req.headers['X-Display-Name'] = user_info.token.user.id; - req.headers['X-Roles'] = user_info.token.roles; - req.headers['X-Organizations'] = user_info.token.project; + console.log('[ROOT] Access-token OK. Redirecting to app...'); + + if (config.tokens_engine === 'keystone') { + req.headers['X-Nick-Name'] = user_info.token.user.id; + req.headers['X-Display-Name'] = user_info.token.user.id; + req.headers['X-Roles'] = user_info.token.roles; + req.headers['X-Organizations'] = user_info.token.project; + } else { + req.headers['X-Nick-Name'] = user_info.id; + req.headers['X-Display-Name'] = user_info.displayName; + req.headers['X-Roles'] = user_info.roles; + req.headers['X-Organizations'] = user_info.organizations; + } } else { - req.headers['X-Nick-Name'] = user_info.id; - req.headers['X-Display-Name'] = user_info.displayName; - req.headers['X-Roles'] = user_info.roles; - req.headers['X-Organizations'] = user_info.organizations; + console.log('[ROOT] Public path. Redirecting to app...'); } var options = { @@ -99,7 +108,8 @@ var Root = (function() { }; return { - pep: pep + pep: pep, + public: public } })(); diff --git a/server.js b/server.js index 0353e40..d5b50cc 100644 --- a/server.js +++ b/server.js @@ -63,6 +63,11 @@ var port = config.pep_port || 80; if (config.https.enabled) port = config.https.port || 443; app.set('port', port); +for (var p in config.public_paths) { + console.log(config.public_paths[p]); + app.all(config.public_paths[p], Root.public); +} + app.all('/*', Root.pep); if (config.tokens_engine === 'keystone' && config.azf.enabled === true) {