Added newaccountsrights support for SSO accounts.
Ylian Saint-Hilaire committed
May 25, 2020 at 12:52 UTC
0848ed2cb0fcb363bc9bb5f56249e72b7245a508
1 file changed
+14
-1
webserver.js
+14
-1
@@ -390,6 +390,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
390
user['emailVerified'] = true;
391
}
392
if (domain.newaccountsrights) { user.siteadmin = domain.newaccountsrights; }
393
+ if (obj.common.validateStrArray(domain.newaccountrealms)) { user.groups = domain.newaccountrealms; }
394
var usercount = 0;
395
for (var i in obj.users) { if (obj.users[i].domain == domain.id) { usercount++; } }
396
if (usercount == 0) { user.siteadmin = 4294967295; /*if (domain.newaccounts === 2) { delete domain.newaccounts; }*/ } // If this is the first user, give the account site admin.
@@ -478,6 +479,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
479
user['emailVerified'] = true;
480
}
481
if (domain.newaccountsrights) { user.siteadmin = domain.newaccountsrights; }
482
+ if (obj.common.validateStrArray(domain.newaccountrealms)) { user.groups = domain.newaccountrealms; }
483
var usercount = 0;
484
for (var i in obj.users) { if (obj.users[i].domain == domain.id) { usercount++; } }
485
if (usercount == 0) { user.siteadmin = 4294967295; /*if (domain.newaccounts === 2) { delete domain.newaccounts; }*/ } // If this is the first user, give the account site admin.
@@ -1142,6 +1144,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1144
} else {
1145
var user = { type: 'user', _id: 'user/' + domain.id + '/' + req.body.username.toLowerCase(), name: req.body.username, email: req.body.email, creation: Math.floor(Date.now() / 1000), login: Math.floor(Date.now() / 1000), domain: domain.id };
1146
if (domain.newaccountsrights) { user.siteadmin = domain.newaccountsrights; }
1147
+ if (obj.common.validateStrArray(domain.newaccountrealms)) { user.groups = domain.newaccountrealms; }
1148
if ((domain.passwordrequirements != null) && (domain.passwordrequirements.hint === true) && (req.body.apasswordhint)) { var hint = req.body.apasswordhint; if (hint.length > 250) { hint = hint.substring(0, 250); } user.passhint = hint; }
1149
if (domainUserCount == 0) { user.siteadmin = 4294967295; /*if (domain.newaccounts === 2) { delete domain.newaccounts; }*/ } // If this is the first user, give the account site admin.
1150
obj.users[user._id] = user;
@@ -1744,14 +1747,23 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1747
var user = obj.users[userid];
1748
if (user == null) {
1749
var newAccountAllowed = false;
1750
+ var newAccountRealms = null;
1751
+
1752
if (domain.newaccounts === true) { newAccountAllowed = true; }
1748
- if ((domain.authstrategies != null) && (domain.authstrategies[req.user.strategy] != null) && (domain.authstrategies[req.user.strategy].newaccounts === true)) { newAccountAllowed = true; }
1753
+ if (obj.common.validateStrArray(domain.newaccountrealms)) { newAccountRealms = domain.newaccountrealms; }
1754
+
1755
+ if ((domain.authstrategies != null) && (domain.authstrategies[req.user.strategy] != null)) {
1756
+ if (domain.authstrategies[req.user.strategy].newaccounts === true) { newAccountAllowed = true; }
1757
+ if (obj.common.validateStrArray(domain.authstrategies[req.user.strategy].newaccountrealms)) { newAccountRealms = domain.authstrategies[req.user.strategy].newaccountrealms; }
1758
+ }
1759
1760
if (newAccountAllowed === true) {
1761
// Create the user
1762
parent.debug('web', 'handleStrategyLogin: creating new user: ' + userid);
1763
user = { type: 'user', _id: userid, name: req.user.name, email: req.user.email, creation: Math.floor(Date.now() / 1000), domain: domain.id };
1764
if (req.user.email != null) { user.email = req.user.email; user.emailVerified = true; }
1765
+ if (domain.newaccountsrights) { user.siteadmin = domain.newaccountsrights; } // New accounts automatically assigned server rights.
1766
+ if (newAccountRealms) { user.groups = newAccountRealms; } // New accounts automatically part of some groups (Realms).
1767
obj.users[userid] = user;
1768
obj.db.SetUser(user);
1769
@@ -1899,6 +1911,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
1911
// Create the domain user
1912
var usercount = 0, user2 = { type: 'user', _id: req.session.userid, name: req.connection.user, domain: domain.id, sid: req.session.usersid, creation: Math.floor(Date.now() / 1000), login: Math.floor(Date.now() / 1000) };
1913
if (domain.newaccountsrights) { user2.siteadmin = domain.newaccountsrights; }
1914
+ if (obj.common.validateStrArray(domain.newaccountrealms)) { user2.groups = domain.newaccountrealms; }
1915
for (var i in obj.users) { if (obj.users[i].domain == domain.id) { usercount++; } }
1916
if (usercount == 0) { user2.siteadmin = 4294967295; } // If this is the first user, give the account site admin.
1917
obj.users[req.session.userid] = user2;