Add ldapjs to get user groups upon ldap login

This commit is contained in:
Tuan Dang
2024-04-22 22:02:12 -07:00
parent 62aebe2fd4
commit 2d51445dd9
16 changed files with 394 additions and 110 deletions
@@ -60,6 +60,8 @@ export const ldapConfigServiceFactory = ({
bindDN,
bindPass,
searchBase,
groupSearchBase,
groupSearchFilter,
caCert
}: TCreateLdapCfgDTO) => {
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);
@@ -135,6 +137,8 @@ export const ldapConfigServiceFactory = ({
bindPassIV,
bindPassTag,
searchBase,
groupSearchBase,
groupSearchFilter,
encryptedCACert,
caCertIV,
caCertTag
@@ -154,6 +158,8 @@ export const ldapConfigServiceFactory = ({
bindDN,
bindPass,
searchBase,
groupSearchBase,
groupSearchFilter,
caCert
}: TUpdateLdapCfgDTO) => {
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);
@@ -169,7 +175,9 @@ export const ldapConfigServiceFactory = ({
const updateQuery: TLdapConfigsUpdate = {
isActive,
url,
searchBase
searchBase,
groupSearchBase,
groupSearchFilter
};
const orgBot = await orgBotDAL.findOne({ orgId });
@@ -271,6 +279,8 @@ export const ldapConfigServiceFactory = ({
bindDN,
bindPass,
searchBase: ldapConfig.searchBase,
groupSearchBase: ldapConfig.groupSearchBase,
groupSearchFilter: ldapConfig.groupSearchFilter,
caCert
};
};
@@ -305,7 +315,7 @@ export const ldapConfigServiceFactory = ({
bindCredentials: ldapConfig.bindPass,
searchBase: ldapConfig.searchBase,
searchFilter: "(uid={{username}})",
searchAttributes: ["uid", "uidNumber", "givenName", "sn", "mail"],
// searchAttributes: ["uid", "uidNumber", "givenName", "sn", "mail"],
...(ldapConfig.caCert !== ""
? {
tlsOptions: {
@@ -7,6 +7,8 @@ export type TCreateLdapCfgDTO = {
bindDN: string;
bindPass: string;
searchBase: string;
groupSearchBase: string;
groupSearchFilter: string;
caCert: string;
} & TOrgPermission;
@@ -18,6 +20,8 @@ export type TUpdateLdapCfgDTO = {
bindDN: string;
bindPass: string;
searchBase: string;
groupSearchBase: string;
groupSearchFilter: string;
caCert: string;
}> &
TOrgPermission;
@@ -0,0 +1,36 @@
import ldap from "ldapjs";
export const searchGroups = async (
ldapClient: ldap.Client,
filter: string,
base: string
): Promise<{ dn: string; cn: string }[]> => {
return new Promise((resolve, reject) => {
ldapClient.search(
base,
{
filter,
scope: "sub"
},
(err, res) => {
if (err) {
reject(err);
}
const groups: { dn: string; cn: string }[] = [];
res.on("searchEntry", (entry) => {
groups.push({ dn: entry.object.dn, cn: entry.object.cn as string });
});
res.on("error", (error) => {
reject(error);
});
res.on("end", () => {
resolve(groups);
});
}
);
});
};
@@ -19,7 +19,7 @@ export const getDefaultOnPremFeatures = () => {
auditLogsRetentionDays: 0,
samlSSO: false,
scim: false,
ldap: false,
ldap: true,
groups: false,
status: null,
trial_end: null,
@@ -26,7 +26,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
auditLogsRetentionDays: 0,
samlSSO: false,
scim: false,
ldap: false,
ldap: true,
groups: false,
status: null,
trial_end: null,
@@ -42,7 +42,7 @@ export type TFeatureSet = {
auditLogsRetentionDays: 0;
samlSSO: false;
scim: false;
ldap: false;
ldap: true;
groups: false;
status: null;
trial_end: null;