Compare commits

..

2 Commits

Author SHA1 Message Date
Christoph
059234d416 never publish pointer payloads on message bus (#411) 2025-04-21 16:42:35 +02:00
Christoph
e2966d32ea fix user creation (#411) 2025-04-21 15:29:53 +02:00
3 changed files with 20 additions and 8 deletions

View File

@@ -82,7 +82,7 @@ func (m Manager) RegisterUser(ctx context.Context, user *domain.User) error {
return err return err
} }
m.bus.Publish(app.TopicUserRegistered, createdUser) m.bus.Publish(app.TopicUserRegistered, *createdUser)
return nil return nil
} }
@@ -294,8 +294,8 @@ func (m Manager) ActivateApi(ctx context.Context, id domain.UserIdentifier) (*do
return nil, fmt.Errorf("update failure: %w", err) return nil, fmt.Errorf("update failure: %w", err)
} }
m.bus.Publish(app.TopicUserUpdated, user) m.bus.Publish(app.TopicUserUpdated, *user)
m.bus.Publish(app.TopicUserApiEnabled, user) m.bus.Publish(app.TopicUserApiEnabled, *user)
return user, nil return user, nil
} }
@@ -322,8 +322,8 @@ func (m Manager) DeactivateApi(ctx context.Context, id domain.UserIdentifier) (*
return nil, fmt.Errorf("update failure: %w", err) return nil, fmt.Errorf("update failure: %w", err)
} }
m.bus.Publish(app.TopicUserUpdated, user) m.bus.Publish(app.TopicUserUpdated, *user)
m.bus.Publish(app.TopicUserApiDisabled, user) m.bus.Publish(app.TopicUserApiDisabled, *user)
return user, nil return user, nil
} }
@@ -389,12 +389,14 @@ func (m Manager) validateCreation(ctx context.Context, new *domain.User) error {
return fmt.Errorf("reserved user identifier: %w", domain.ErrInvalidData) return fmt.Errorf("reserved user identifier: %w", domain.ErrInvalidData)
} }
if new.Source != domain.UserSourceDatabase { // Admins are allowed to create users for arbitrary sources.
if new.Source != domain.UserSourceDatabase && !currentUser.IsAdmin {
return fmt.Errorf("invalid user source: %s, only %s is allowed: %w", return fmt.Errorf("invalid user source: %s, only %s is allowed: %w",
new.Source, domain.UserSourceDatabase, domain.ErrInvalidData) new.Source, domain.UserSourceDatabase, domain.ErrInvalidData)
} }
if string(new.Password) == "" { // database users must have a password
if new.Source == domain.UserSourceDatabase && string(new.Password) == "" {
return fmt.Errorf("invalid password: %w", domain.ErrInvalidData) return fmt.Errorf("invalid password: %w", domain.ErrInvalidData)
} }
@@ -430,6 +432,8 @@ func (m Manager) validateApiChange(ctx context.Context, user *domain.User) error
} }
func (m Manager) runLdapSynchronizationService(ctx context.Context) { func (m Manager) runLdapSynchronizationService(ctx context.Context) {
ctx = domain.SetUserInfo(ctx, domain.LdapSyncContextUserInfo()) // switch to service context for LDAP sync
for _, ldapCfg := range m.cfg.Auth.Ldap { // LDAP Auth providers for _, ldapCfg := range m.cfg.Auth.Ldap { // LDAP Auth providers
go func(cfg config.LdapProvider) { go func(cfg config.LdapProvider) {
syncInterval := cfg.SyncInterval syncInterval := cfg.SyncInterval

View File

@@ -112,7 +112,7 @@ func (m Manager) connectToMessageBus() {
_ = m.bus.Subscribe(app.TopicUserDeleted, m.handleUserDeletedEvent) _ = m.bus.Subscribe(app.TopicUserDeleted, m.handleUserDeletedEvent)
} }
func (m Manager) handleUserCreationEvent(user *domain.User) { func (m Manager) handleUserCreationEvent(user domain.User) {
if !m.cfg.Core.CreateDefaultPeerOnCreation { if !m.cfg.Core.CreateDefaultPeerOnCreation {
return return
} }

View File

@@ -45,6 +45,14 @@ func SystemAdminContextUserInfo() *ContextUserInfo {
} }
} }
// LdapSyncContextUserInfo returns a context user info for the LDAP syncer.
func LdapSyncContextUserInfo() *ContextUserInfo {
return &ContextUserInfo{
Id: CtxSystemLdapSyncer,
IsAdmin: true,
}
}
// SetUserInfo sets the user info in the context. // SetUserInfo sets the user info in the context.
func SetUserInfo(ctx context.Context, info *ContextUserInfo) context.Context { func SetUserInfo(ctx context.Context, info *ContextUserInfo) context.Context {
ctx = context.WithValue(ctx, CtxUserInfo, info) ctx = context.WithValue(ctx, CtxUserInfo, info)