diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2025-02-22 17:40:08 +1100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-22 06:40:08 +0000 |
| commit | 34932a845ec6a090147c37f8d5ddac9f334888d2 (patch) | |
| tree | 15c94be40e31ed1cd9a862af4f22b45e696f7534 /internal/authentication/file_user_provider.go | |
| parent | 7d3c2b1dedc415f4a4b80a0035a819ecf91894ec (diff) | |
feat(authentication): additional and custom attributes (#8078)
This facilitates adding additional attributes to the Authelia authentication backends as well as custom attributes based on the Common Expression Language. This will be utilized in the future to facilitate additional features.
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/authentication/file_user_provider.go')
| -rw-r--r-- | internal/authentication/file_user_provider.go | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/internal/authentication/file_user_provider.go b/internal/authentication/file_user_provider.go index 4c92c7cdf..02e0faa81 100644 --- a/internal/authentication/file_user_provider.go +++ b/internal/authentication/file_user_provider.go @@ -16,6 +16,7 @@ import ( "github.com/go-crypt/crypt/algorithm/shacrypt" "github.com/authelia/authelia/v4/internal/configuration/schema" + "github.com/authelia/authelia/v4/internal/expression" "github.com/authelia/authelia/v4/internal/logging" ) @@ -34,10 +35,22 @@ func NewFileUserProvider(config *schema.AuthenticationBackendFile) (provider *Fi config: config, mutex: &sync.Mutex{}, timeoutReload: time.Now().Add(-1 * time.Second), - database: NewFileUserDatabase(config.Path, config.Search.Email, config.Search.CaseInsensitive), + database: NewFileUserDatabase(config.Path, config.Search.Email, config.Search.CaseInsensitive, getExtra(config)), } } +func getExtra(config *schema.AuthenticationBackendFile) (extra map[string]expression.ExtraAttribute) { + extra = make(map[string]expression.ExtraAttribute, len(config.ExtraAttributes)) + + if len(config.ExtraAttributes) != 0 { + for name, attribute := range config.ExtraAttributes { + extra[name] = attribute + } + } + + return extra +} + // Reload the database. func (p *FileUserProvider) Reload() (reloaded bool, err error) { now := time.Now() @@ -94,6 +107,20 @@ func (p *FileUserProvider) GetDetails(username string) (details *UserDetails, er return d.ToUserDetails(), nil } +func (p *FileUserProvider) GetDetailsExtended(username string) (details *UserDetailsExtended, err error) { + var d FileUserDatabaseUserDetails + + if d, err = p.database.GetUserDetails(username); err != nil { + return nil, err + } + + if d.Disabled { + return nil, ErrUserNotFound + } + + return d.ToExtendedUserDetails(), nil +} + // UpdatePassword update the password of the given user. func (p *FileUserProvider) UpdatePassword(username string, newPassword string) (err error) { var details FileUserDatabaseUserDetails @@ -142,7 +169,7 @@ func (p *FileUserProvider) StartupCheck() (err error) { } if p.database == nil { - p.database = NewFileUserDatabase(p.config.Path, p.config.Search.Email, p.config.Search.CaseInsensitive) + p.database = NewFileUserDatabase(p.config.Path, p.config.Search.Email, p.config.Search.CaseInsensitive, getExtra(p.config)) } if err = p.database.Load(); err != nil { |
