try to fix configuration logic
This commit is contained in:
parent
3317bc7d89
commit
9977b415ba
3 changed files with 122 additions and 66 deletions
80
library.js
80
library.js
|
|
@ -20,16 +20,28 @@
|
|||
}
|
||||
});
|
||||
|
||||
var master_config = {};
|
||||
var SAML = {};
|
||||
var samlObj;
|
||||
|
||||
if (meta.config['sso:saml:idpentrypoint'] && meta.config['sso:saml:callbackpath']&& meta.config["sso:saml:metadata"] && meta.config["sso:saml:issuer"]) {
|
||||
|
||||
SAML.init = function(params, callback) {
|
||||
|
||||
function render(req, res, next) {
|
||||
res.render('admin/plugins/sso-saml', {});
|
||||
}
|
||||
|
||||
params.router.get('/admin/plugins/sso-saml', params.middleware.admin.buildHeader, render);
|
||||
params.router.get('/api/admin/plugins/sso-saml', render);
|
||||
|
||||
meta.settings.get('sso_saml', function(err, options) {
|
||||
master_config = options;
|
||||
});
|
||||
|
||||
samlObj = new passportSAML({
|
||||
path: meta.config['sso:saml:callbackpath'],
|
||||
entryPoint: meta.config['sso:saml:idpentrypoint'],
|
||||
issuer: meta.config['sso:saml:issuer'],
|
||||
callbackUrl: nconf.get('url') + meta.config['sso:saml:callbackpath'],
|
||||
path: master_config.callback_path,
|
||||
entryPoint: master_config.idp_entry_point,
|
||||
issuer: master_config.issuer,
|
||||
callbackUrl: nconf.get('url') + master_config.callback_path,
|
||||
disableRequestedAuthnContext: true,
|
||||
identifierFormat: null
|
||||
},
|
||||
|
|
@ -58,28 +70,13 @@
|
|||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
else{
|
||||
console.log("No config info")
|
||||
console.log(meta.config);
|
||||
}
|
||||
|
||||
|
||||
SAML.init = function(params, callback) {
|
||||
|
||||
function render(req, res, next) {
|
||||
res.render('admin/plugins/sso-saml', {});
|
||||
}
|
||||
|
||||
params.router.get('/admin/plugins/sso-saml', params.middleware.admin.buildHeader, render);
|
||||
params.router.get('/api/admin/plugins/sso-saml', render);
|
||||
|
||||
if (samlObj){
|
||||
|
||||
if (meta.config["sso:saml:metadata"]) {
|
||||
params.router.get(meta.config["sso:saml:metadata"], function(req, res) {
|
||||
if (meta.config["sso:saml:servercrt"]){
|
||||
var cert = fs.readFileSync(meta.config["sso:saml:servercrt"], 'utf-8');
|
||||
if (master_config.metadata) {
|
||||
params.router.get(master_config.metadata, function(req, res) {
|
||||
if (master_config.server_crt){
|
||||
var cert = fs.readFileSync(master_config.server_crt, 'utf-8');
|
||||
res.header("Content-Type", "application/xml");
|
||||
res.send(samlObj.generateServiceProviderMetadata(cert))
|
||||
}
|
||||
|
|
@ -89,11 +86,11 @@
|
|||
});
|
||||
}
|
||||
|
||||
params.router.post(meta.config['sso:saml:callbackpath'],
|
||||
params.router.post(master_config.callback_path,
|
||||
passport.authenticate('saml'),
|
||||
function(req, res, next){
|
||||
if (meta.config['sso:saml:loginsuccessredirecturl']){
|
||||
res.redirect(meta.config['sso:saml:loginsuccessredirecturl']);
|
||||
if (master_config.login_redirect_url){
|
||||
res.redirect(master_config.login_redirect_url);
|
||||
}
|
||||
else{
|
||||
res.redirect("/");
|
||||
|
|
@ -103,9 +100,9 @@
|
|||
|
||||
);
|
||||
|
||||
if (meta.config['sso:saml:logouturl']) {
|
||||
if (master_config.logout_url) {
|
||||
|
||||
params.router.get(meta.config['sso:saml:logouturl'],function(req,res){
|
||||
params.router.get(master_config.logout_url,function(req,res){
|
||||
if (req.user && parseInt(req.user.uid, 10) > 0) {
|
||||
winston.info('[Auth] Session ' + req.sessionID + ' logout (uid: ' + req.user.uid + ')');
|
||||
|
||||
|
|
@ -114,8 +111,8 @@
|
|||
|
||||
req.logout();
|
||||
|
||||
if (meta.config['sso:saml:logoutredirecturl']){
|
||||
res.redirect(meta.config['sso:saml:logoutredirecturl']);
|
||||
if (master_config.logout_redirect_url){
|
||||
res.redirect(master_config.logout_redirect_url);
|
||||
}
|
||||
else{
|
||||
res.redirect("/");
|
||||
|
|
@ -127,10 +124,27 @@
|
|||
}
|
||||
|
||||
}
|
||||
else {
|
||||
console.log("Cannot create samlObj")
|
||||
}
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
|
||||
SAML.get_config = function(options, callback) {
|
||||
meta.settings.get('sso_saml', function(err, settings) {
|
||||
if (err) {
|
||||
return callback(null, options);
|
||||
}
|
||||
master_config = settings;
|
||||
options.sso_saml = settings;
|
||||
callback(null, options);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
SAML.getStrategy = function(strategies, callback) {
|
||||
|
||||
if (samlObj){
|
||||
|
|
@ -140,7 +154,7 @@
|
|||
strategies.push({
|
||||
name: 'saml',
|
||||
url: '/auth/saml',
|
||||
callbackURL: meta.config['sso:saml:callbackpath'],
|
||||
callbackURL: master_config.callback_path,
|
||||
icon: constants.admin.icon,
|
||||
scope: ''
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue