fix: prevent panic in loginNameInformation (#6876)

This commit is contained in:
Livio Spring 2023-11-07 12:16:49 +02:00 committed by GitHub
parent a50d1408be
commit e342e3d99b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View File

@ -531,14 +531,18 @@ func (u *User) loginNameInformation(ctx context.Context, orgID string, instanceI
if err != nil {
return false, "", nil, err
}
primaryDomain, err = org.GetPrimaryDomain()
if err != nil {
return false, "", nil, err
}
if org.DomainPolicy != nil {
return org.DomainPolicy.UserLoginMustBeDomain, org.GetPrimaryDomain().Domain, org.Domains, nil
return org.DomainPolicy.UserLoginMustBeDomain, primaryDomain, org.Domains, nil
}
policy, err := u.queries.DefaultDomainPolicy(authz.WithInstanceID(ctx, org.InstanceID))
if err != nil {
return false, "", nil, err
}
return policy.UserLoginMustBeDomain, org.GetPrimaryDomain().Domain, org.Domains, nil
return policy.UserLoginMustBeDomain, primaryDomain, org.Domains, nil
}
func (u *User) userFromEventstore(agg *eventstore.Aggregate, eventTypes []eventstore.EventType) (*view_model.UserView, error) {

View File

@ -358,14 +358,18 @@ func (u *UserSession) loginNameInformation(ctx context.Context, orgID string, in
if err != nil {
return false, "", err
}
primaryDomain, err = org.GetPrimaryDomain()
if err != nil {
return false, "", err
}
if org.DomainPolicy != nil {
return org.DomainPolicy.UserLoginMustBeDomain, org.GetPrimaryDomain().Domain, nil
return org.DomainPolicy.UserLoginMustBeDomain, primaryDomain, nil
}
policy, err := u.queries.DefaultDomainPolicy(authz.WithInstanceID(ctx, org.InstanceID))
if err != nil {
return false, "", err
}
return policy.UserLoginMustBeDomain, org.GetPrimaryDomain().Domain, nil
return policy.UserLoginMustBeDomain, primaryDomain, nil
}
func (u *UserSession) getOrgByID(ctx context.Context, orgID, instanceID string) (*org_model.Org, error) {

View File

@ -2,6 +2,7 @@ package model
import (
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/errors"
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
iam_model "github.com/zitadel/zitadel/internal/iam/model"
)
@ -36,13 +37,13 @@ func (o *Org) GetDomain(domain *OrgDomain) (int, *OrgDomain) {
return -1, nil
}
func (o *Org) GetPrimaryDomain() *OrgDomain {
func (o *Org) GetPrimaryDomain() (string, error) {
for _, d := range o.Domains {
if d.Primary {
return d
return d.Domain, nil
}
}
return nil
return "", errors.ThrowInternalf(nil, "ORG-Dertg", "no primary domain found for org: %s (instanceID: %s)", o.AggregateID, o.InstanceID)
}
func (o *Org) AddIAMDomain(iamDomain string) {