Skip to content

Commit

Permalink
Added support for public paths
Browse files Browse the repository at this point in the history
  • Loading branch information
aalonsog committed Jun 9, 2015
1 parent 8f9b09b commit 85df40e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions config.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
32 changes: 21 additions & 11 deletions controllers/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -99,7 +108,8 @@ var Root = (function() {
};

return {
pep: pep
pep: pep,
public: public
}
})();

Expand Down
5 changes: 5 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 85df40e

Please sign in to comment.