Files
gochat/internal/model/account_ldap_settings.go
T
2026-06-04 15:44:48 +08:00

47 lines
3.2 KiB
Go

package model
// Reference: M13 §4.4 — LDAP/Active Directory per-account configuration
// Enables multi-tenant LDAP identity isolation: each account (tenant) can configure
// its own LDAP server, allowing enterprise customers to connect to their existing
// Active Directory or LDAP infrastructure while maintaining complete isolation
// between tenants.
// This is a GoChat enterprise feature that Chatwoot does not offer.
import (
"encoding/json"
"time"
"gorm.io/gorm"
)
// AccountLDAPSettings stores per-account LDAP configuration for multi-tenant identity isolation.
// Each account can have exactly one active LDAP configuration.
type AccountLDAPSettings struct {
ID uint `gorm:"primaryKey" json:"id"`
AccountID uint `gorm:"not null;uniqueIndex" json:"account_id"` // one active config per account
Host string `gorm:"size:200;not null" json:"host"` // LDAP server hostname
Port int `gorm:"not null;default:389" json:"port"` // LDAP port (389=plain, 636=LDAPS)
UseTLS bool `gorm:"default:false" json:"use_tls"` // use StartTLS on connection
BaseDN string `gorm:"size:200;not null" json:"base_dn"` // search base DN (e.g. dc=example,dc=com)
BindDN string `gorm:"size:200" json:"bind_dn,omitempty"` // service account bind DN
BindPassword string `gorm:"size:200" json:"-"` // bind password (not exposed via API)
UserFilter string `gorm:"size:200;default:'(objectClass=person)'" json:"user_filter"` // LDAP search filter for users
EmailAttribute string `gorm:"size:50;default:'mail'" json:"email_attribute"` // attribute for email
NameAttribute string `gorm:"size:50;default:'cn'" json:"name_attribute"` // attribute for display name
FirstNameAttribute string `gorm:"size:50;default:'givenName'" json:"first_name_attribute"` // attribute for first name
LastNameAttribute string `gorm:"size:50;default:'sn'" json:"last_name_attribute"` // attribute for last name
GroupAttribute string `gorm:"size:50;default:'memberOf'" json:"group_attribute"` // attribute for group membership
GroupFilter string `gorm:"size:200" json:"group_filter,omitempty"` // filter for group search (e.g. (objectClass=group))
RoleMappings json.RawMessage `gorm:"type:jsonb" json:"role_mappings"` // LDAP group -> GoChat role mapping
AutoProvision bool `gorm:"default:true" json:"auto_provision"` // auto-create GoChat user on first LDAP login
SyncInterval int `gorm:"default:3600" json:"sync_interval"` // group sync interval in seconds
Active bool `gorm:"default:true" json:"active"` // whether this config is active
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
Account Account `gorm:"foreignKey:AccountID" json:"account,omitempty"`
}
func (AccountLDAPSettings) TableName() string { return "account_ldap_settings" }