mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-21 17:25:44 +03:00
feat: add LDAP group membership attribute (#236)
Co-authored-by: Elias Schneider <login@eliasschneider.com>
This commit is contained in:
@@ -36,6 +36,7 @@ type AppConfigUpdateDto struct {
|
|||||||
LdapAttributeUserEmail string `json:"ldapAttributeUserEmail"`
|
LdapAttributeUserEmail string `json:"ldapAttributeUserEmail"`
|
||||||
LdapAttributeUserFirstName string `json:"ldapAttributeUserFirstName"`
|
LdapAttributeUserFirstName string `json:"ldapAttributeUserFirstName"`
|
||||||
LdapAttributeUserLastName string `json:"ldapAttributeUserLastName"`
|
LdapAttributeUserLastName string `json:"ldapAttributeUserLastName"`
|
||||||
|
LdapAttributeGroupMember string `json:"ldapAttributeGroupMember"`
|
||||||
LdapAttributeGroupUniqueIdentifier string `json:"ldapAttributeGroupUniqueIdentifier"`
|
LdapAttributeGroupUniqueIdentifier string `json:"ldapAttributeGroupUniqueIdentifier"`
|
||||||
LdapAttributeGroupName string `json:"ldapAttributeGroupName"`
|
LdapAttributeGroupName string `json:"ldapAttributeGroupName"`
|
||||||
LdapAttributeAdminGroup string `json:"ldapAttributeAdminGroup"`
|
LdapAttributeAdminGroup string `json:"ldapAttributeAdminGroup"`
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ type AppConfig struct {
|
|||||||
LdapAttributeUserEmail AppConfigVariable
|
LdapAttributeUserEmail AppConfigVariable
|
||||||
LdapAttributeUserFirstName AppConfigVariable
|
LdapAttributeUserFirstName AppConfigVariable
|
||||||
LdapAttributeUserLastName AppConfigVariable
|
LdapAttributeUserLastName AppConfigVariable
|
||||||
|
LdapAttributeGroupMember AppConfigVariable
|
||||||
LdapAttributeGroupUniqueIdentifier AppConfigVariable
|
LdapAttributeGroupUniqueIdentifier AppConfigVariable
|
||||||
LdapAttributeGroupName AppConfigVariable
|
LdapAttributeGroupName AppConfigVariable
|
||||||
LdapAttributeAdminGroup AppConfigVariable
|
LdapAttributeAdminGroup AppConfigVariable
|
||||||
|
|||||||
@@ -173,6 +173,11 @@ var defaultDbConfig = model.AppConfig{
|
|||||||
Key: "ldapAttributeUserLastName",
|
Key: "ldapAttributeUserLastName",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
},
|
},
|
||||||
|
LdapAttributeGroupMember: model.AppConfigVariable{
|
||||||
|
Key: "ldapAttributeGroupMember",
|
||||||
|
Type: "string",
|
||||||
|
DefaultValue: "member",
|
||||||
|
},
|
||||||
LdapAttributeGroupUniqueIdentifier: model.AppConfigVariable{
|
LdapAttributeGroupUniqueIdentifier: model.AppConfigVariable{
|
||||||
Key: "ldapAttributeGroupUniqueIdentifier",
|
Key: "ldapAttributeGroupUniqueIdentifier",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
|
|||||||
@@ -70,12 +70,13 @@ func (s *LdapService) SyncGroups() error {
|
|||||||
baseDN := s.appConfigService.DbConfig.LdapBase.Value
|
baseDN := s.appConfigService.DbConfig.LdapBase.Value
|
||||||
nameAttribute := s.appConfigService.DbConfig.LdapAttributeGroupName.Value
|
nameAttribute := s.appConfigService.DbConfig.LdapAttributeGroupName.Value
|
||||||
uniqueIdentifierAttribute := s.appConfigService.DbConfig.LdapAttributeGroupUniqueIdentifier.Value
|
uniqueIdentifierAttribute := s.appConfigService.DbConfig.LdapAttributeGroupUniqueIdentifier.Value
|
||||||
|
groupMemberOfAttribute := s.appConfigService.DbConfig.LdapAttributeGroupMember.Value
|
||||||
filter := s.appConfigService.DbConfig.LdapUserGroupSearchFilter.Value
|
filter := s.appConfigService.DbConfig.LdapUserGroupSearchFilter.Value
|
||||||
|
|
||||||
searchAttrs := []string{
|
searchAttrs := []string{
|
||||||
nameAttribute,
|
nameAttribute,
|
||||||
uniqueIdentifierAttribute,
|
uniqueIdentifierAttribute,
|
||||||
"member",
|
groupMemberOfAttribute,
|
||||||
}
|
}
|
||||||
|
|
||||||
searchReq := ldap.NewSearchRequest(baseDN, ldap.ScopeWholeSubtree, 0, 0, 0, false, filter, searchAttrs, []ldap.Control{})
|
searchReq := ldap.NewSearchRequest(baseDN, ldap.ScopeWholeSubtree, 0, 0, 0, false, filter, searchAttrs, []ldap.Control{})
|
||||||
@@ -99,7 +100,7 @@ func (s *LdapService) SyncGroups() error {
|
|||||||
s.db.Where("ldap_id = ?", ldapId).First(&databaseGroup)
|
s.db.Where("ldap_id = ?", ldapId).First(&databaseGroup)
|
||||||
|
|
||||||
// Get group members and add to the correct Group
|
// Get group members and add to the correct Group
|
||||||
groupMembers := value.GetAttributeValues("member")
|
groupMembers := value.GetAttributeValues(groupMemberOfAttribute)
|
||||||
for _, member := range groupMembers {
|
for _, member := range groupMembers {
|
||||||
// Normal output of this would be CN=username,ou=people,dc=example,dc=com
|
// Normal output of this would be CN=username,ou=people,dc=example,dc=com
|
||||||
// Splitting at the "=" and "," then just grabbing the username for that string
|
// Splitting at the "=" and "," then just grabbing the username for that string
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export type AllAppConfig = AppConfig & {
|
|||||||
ldapAttributeUserEmail: string;
|
ldapAttributeUserEmail: string;
|
||||||
ldapAttributeUserFirstName: string;
|
ldapAttributeUserFirstName: string;
|
||||||
ldapAttributeUserLastName: string;
|
ldapAttributeUserLastName: string;
|
||||||
|
ldapAttributeGroupMember: string;
|
||||||
ldapAttributeGroupUniqueIdentifier: string;
|
ldapAttributeGroupUniqueIdentifier: string;
|
||||||
ldapAttributeGroupName: string;
|
ldapAttributeGroupName: string;
|
||||||
ldapAttributeAdminGroup: string;
|
ldapAttributeAdminGroup: string;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
ldapAttributeUserEmail: appConfig.ldapAttributeUserEmail,
|
ldapAttributeUserEmail: appConfig.ldapAttributeUserEmail,
|
||||||
ldapAttributeUserFirstName: appConfig.ldapAttributeUserFirstName,
|
ldapAttributeUserFirstName: appConfig.ldapAttributeUserFirstName,
|
||||||
ldapAttributeUserLastName: appConfig.ldapAttributeUserLastName,
|
ldapAttributeUserLastName: appConfig.ldapAttributeUserLastName,
|
||||||
|
ldapAttributeGroupMember: appConfig.ldapAttributeGroupMember,
|
||||||
ldapAttributeGroupUniqueIdentifier: appConfig.ldapAttributeGroupUniqueIdentifier,
|
ldapAttributeGroupUniqueIdentifier: appConfig.ldapAttributeGroupUniqueIdentifier,
|
||||||
ldapAttributeGroupName: appConfig.ldapAttributeGroupName,
|
ldapAttributeGroupName: appConfig.ldapAttributeGroupName,
|
||||||
ldapAttributeAdminGroup: appConfig.ldapAttributeAdminGroup
|
ldapAttributeAdminGroup: appConfig.ldapAttributeAdminGroup
|
||||||
@@ -56,6 +57,7 @@
|
|||||||
ldapAttributeUserEmail: z.string().min(1),
|
ldapAttributeUserEmail: z.string().min(1),
|
||||||
ldapAttributeUserFirstName: z.string().min(1),
|
ldapAttributeUserFirstName: z.string().min(1),
|
||||||
ldapAttributeUserLastName: z.string().min(1),
|
ldapAttributeUserLastName: z.string().min(1),
|
||||||
|
ldapAttributeGroupMember: z.string(),
|
||||||
ldapAttributeGroupUniqueIdentifier: z.string().min(1),
|
ldapAttributeGroupUniqueIdentifier: z.string().min(1),
|
||||||
ldapAttributeGroupName: z.string().min(1),
|
ldapAttributeGroupName: z.string().min(1),
|
||||||
ldapAttributeAdminGroup: z.string()
|
ldapAttributeAdminGroup: z.string()
|
||||||
@@ -98,8 +100,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form onsubmit={onSubmit}>
|
<form onsubmit={onSubmit}>
|
||||||
<fieldset disabled={uiConfigDisabled}>
|
|
||||||
<h4 class="text-lg font-semibold">Client Configuration</h4>
|
<h4 class="text-lg font-semibold">Client Configuration</h4>
|
||||||
|
<fieldset disabled={uiConfigDisabled}>
|
||||||
<div class="mt-4 grid grid-cols-1 items-start gap-5 md:grid-cols-2">
|
<div class="mt-4 grid grid-cols-1 items-start gap-5 md:grid-cols-2">
|
||||||
<FormInput
|
<FormInput
|
||||||
label="LDAP URL"
|
label="LDAP URL"
|
||||||
@@ -164,6 +166,12 @@
|
|||||||
placeholder="sn"
|
placeholder="sn"
|
||||||
bind:input={$inputs.ldapAttributeUserLastName}
|
bind:input={$inputs.ldapAttributeUserLastName}
|
||||||
/>
|
/>
|
||||||
|
<FormInput
|
||||||
|
label="Group Members Attribute"
|
||||||
|
description="The attribute to use for querying members of a group."
|
||||||
|
placeholder="member"
|
||||||
|
bind:input={$inputs.ldapAttributeGroupMember}
|
||||||
|
/>
|
||||||
<FormInput
|
<FormInput
|
||||||
label="Group Unique Identifier Attribute"
|
label="Group Unique Identifier Attribute"
|
||||||
description="The value of this attribute should never change."
|
description="The value of this attribute should never change."
|
||||||
@@ -183,6 +191,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<div class="mt-8 flex flex-wrap justify-end gap-3">
|
<div class="mt-8 flex flex-wrap justify-end gap-3">
|
||||||
{#if ldapEnabled}
|
{#if ldapEnabled}
|
||||||
<Button variant="secondary" onclick={onDisable} disabled={uiConfigDisabled}>Disable</Button>
|
<Button variant="secondary" onclick={onDisable} disabled={uiConfigDisabled}>Disable</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user