|
@@ -42,6 +42,22 @@ module.exports = function(crowi, app) {
|
|
|
return res.redirect('/login');
|
|
return res.redirect('/login');
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * return true(valid) or false(invalid)
|
|
|
|
|
+ *
|
|
|
|
|
+ * true ... group filter is not defined or the user has one or more groups
|
|
|
|
|
+ * false ... group filter is defined and the user has any group
|
|
|
|
|
+ *
|
|
|
|
|
+ */
|
|
|
|
|
+ function isValidLdapUserByGroupFilter(user) {
|
|
|
|
|
+ let bool = true;
|
|
|
|
|
+ if (user._groups != null) {
|
|
|
|
|
+ if (user._groups.length == 0) {
|
|
|
|
|
+ bool = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return bool;
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* middleware that login with LdapStrategy
|
|
* middleware that login with LdapStrategy
|
|
|
* @param {*} req
|
|
* @param {*} req
|
|
@@ -80,10 +96,8 @@ module.exports = function(crowi, app) {
|
|
|
// authentication failure
|
|
// authentication failure
|
|
|
if (!ldapAccountInfo) { return next(); }
|
|
if (!ldapAccountInfo) { return next(); }
|
|
|
// check groups
|
|
// check groups
|
|
|
- if (ldapAccountInfo._groups != null) {
|
|
|
|
|
- if (ldapAccountInfo._groups.length == 0) {
|
|
|
|
|
- return loginFailure(req, res, next);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!isValidLdapUserByGroupFilter(ldapAccountInfo)) {
|
|
|
|
|
+ return loginFailure(req, res, next);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -160,13 +174,11 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
}
|
|
|
if (user) {
|
|
if (user) {
|
|
|
// check groups
|
|
// check groups
|
|
|
- if (user._groups != null) {
|
|
|
|
|
- if (user._groups.length == 0) {
|
|
|
|
|
- return res.json({
|
|
|
|
|
- status: 'warning',
|
|
|
|
|
- message: 'An user is found, but the groups are empty.',
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!isValidLdapUserByGroupFilter(user)) {
|
|
|
|
|
+ return res.json({
|
|
|
|
|
+ status: 'warning',
|
|
|
|
|
+ message: 'An user is found, but the groups are empty.',
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
return res.json({
|
|
return res.json({
|
|
|
status: 'success',
|
|
status: 'success',
|