2021-01-04 13:52:13 +00:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/v2"
|
|
|
|
"github.com/caos/zitadel/internal/iam/model"
|
2021-01-05 08:33:45 +00:00
|
|
|
"github.com/caos/zitadel/internal/v2/domain"
|
2021-01-04 13:52:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func readModelToIAM(readModel *ReadModel) *model.IAM {
|
|
|
|
return &model.IAM{
|
|
|
|
ObjectRoot: readModelToObjectRoot(readModel.ReadModel),
|
|
|
|
GlobalOrgID: readModel.GlobalOrgID,
|
|
|
|
IAMProjectID: readModel.ProjectID,
|
|
|
|
SetUpDone: readModel.SetUpDone,
|
|
|
|
SetUpStarted: readModel.SetUpStarted,
|
|
|
|
Members: readModelToMembers(&readModel.Members),
|
|
|
|
DefaultLabelPolicy: readModelToLabelPolicy(&readModel.DefaultLabelPolicy),
|
|
|
|
DefaultLoginPolicy: readModelToLoginPolicy(&readModel.DefaultLoginPolicy),
|
|
|
|
DefaultOrgIAMPolicy: readModelToOrgIAMPolicy(&readModel.DefaultOrgIAMPolicy),
|
|
|
|
DefaultPasswordAgePolicy: readModelToPasswordAgePolicy(&readModel.DefaultPasswordAgePolicy),
|
|
|
|
DefaultPasswordComplexityPolicy: readModelToPasswordComplexityPolicy(&readModel.DefaultPasswordComplexityPolicy),
|
|
|
|
DefaultPasswordLockoutPolicy: readModelToPasswordLockoutPolicy(&readModel.DefaultPasswordLockoutPolicy),
|
|
|
|
IDPs: readModelToIDPConfigs(&readModel.IDPs),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-05 08:33:45 +00:00
|
|
|
func readModelToIDPConfigView(rm *IAMIDPConfigReadModel) *domain.IDPConfigView {
|
|
|
|
converted := &domain.IDPConfigView{
|
|
|
|
AggregateID: rm.AggregateID,
|
|
|
|
ChangeDate: rm.ChangeDate,
|
|
|
|
CreationDate: rm.CreationDate,
|
|
|
|
IDPConfigID: rm.ConfigID,
|
|
|
|
IDPProviderType: rm.ProviderType,
|
|
|
|
IsOIDC: rm.OIDCConfig != nil,
|
|
|
|
Name: rm.Name,
|
|
|
|
Sequence: rm.ProcessedSequence,
|
|
|
|
State: rm.State,
|
|
|
|
StylingType: rm.StylingType,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
2021-01-05 08:33:45 +00:00
|
|
|
if rm.OIDCConfig != nil {
|
|
|
|
converted.OIDCClientID = rm.OIDCConfig.ClientID
|
|
|
|
converted.OIDCClientSecret = rm.OIDCConfig.ClientSecret
|
|
|
|
converted.OIDCIDPDisplayNameMapping = rm.OIDCConfig.IDPDisplayNameMapping
|
|
|
|
converted.OIDCIssuer = rm.OIDCConfig.Issuer
|
|
|
|
converted.OIDCScopes = rm.OIDCConfig.Scopes
|
|
|
|
converted.OIDCUsernameMapping = rm.OIDCConfig.UserNameMapping
|
|
|
|
}
|
|
|
|
return converted
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToMember(readModel *MemberReadModel) *model.IAMMember {
|
|
|
|
return &model.IAMMember{
|
|
|
|
ObjectRoot: readModelToObjectRoot(readModel.ReadModel),
|
|
|
|
Roles: readModel.Roles,
|
|
|
|
UserID: readModel.UserID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToMembers(readModel *IAMMembersReadModel) []*model.IAMMember {
|
|
|
|
members := make([]*model.IAMMember, len(readModel.Members))
|
|
|
|
|
|
|
|
for i, member := range readModel.Members {
|
|
|
|
members[i] = &model.IAMMember{
|
|
|
|
ObjectRoot: readModelToObjectRoot(member.ReadModel),
|
|
|
|
Roles: member.Roles,
|
|
|
|
UserID: member.UserID,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return members
|
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToLabelPolicy(readModel *IAMLabelPolicyReadModel) *model.LabelPolicy {
|
|
|
|
return &model.LabelPolicy{
|
|
|
|
ObjectRoot: readModelToObjectRoot(readModel.LabelPolicyReadModel.ReadModel),
|
|
|
|
PrimaryColor: readModel.PrimaryColor,
|
|
|
|
SecondaryColor: readModel.SecondaryColor,
|
|
|
|
Default: true,
|
2021-01-15 08:32:59 +00:00
|
|
|
//TODO: OTPState: int32,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToLoginPolicy(readModel *IAMLoginPolicyReadModel) *model.LoginPolicy {
|
|
|
|
return &model.LoginPolicy{
|
|
|
|
ObjectRoot: readModelToObjectRoot(readModel.LoginPolicyReadModel.ReadModel),
|
|
|
|
AllowExternalIdp: readModel.AllowExternalIDP,
|
|
|
|
AllowRegister: readModel.AllowRegister,
|
|
|
|
AllowUsernamePassword: readModel.AllowUserNamePassword,
|
|
|
|
Default: true,
|
|
|
|
//TODO: IDPProviders: []*model.IDPProvider,
|
2021-01-15 08:32:59 +00:00
|
|
|
//TODO: OTPState: int32,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func readModelToOrgIAMPolicy(readModel *IAMOrgIAMPolicyReadModel) *model.OrgIAMPolicy {
|
|
|
|
return &model.OrgIAMPolicy{
|
|
|
|
ObjectRoot: readModelToObjectRoot(readModel.OrgIAMPolicyReadModel.ReadModel),
|
|
|
|
UserLoginMustBeDomain: readModel.UserLoginMustBeDomain,
|
|
|
|
Default: true,
|
2021-01-15 08:32:59 +00:00
|
|
|
//TODO: OTPState: int32,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func readModelToPasswordAgePolicy(readModel *IAMPasswordAgePolicyReadModel) *model.PasswordAgePolicy {
|
|
|
|
return &model.PasswordAgePolicy{
|
|
|
|
ObjectRoot: readModelToObjectRoot(readModel.PasswordAgePolicyReadModel.ReadModel),
|
|
|
|
ExpireWarnDays: uint64(readModel.ExpireWarnDays),
|
|
|
|
MaxAgeDays: uint64(readModel.MaxAgeDays),
|
2021-01-15 08:32:59 +00:00
|
|
|
//TODO: OTPState: int32,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func readModelToPasswordComplexityPolicy(readModel *IAMPasswordComplexityPolicyReadModel) *model.PasswordComplexityPolicy {
|
|
|
|
return &model.PasswordComplexityPolicy{
|
|
|
|
ObjectRoot: readModelToObjectRoot(readModel.PasswordComplexityPolicyReadModel.ReadModel),
|
|
|
|
HasLowercase: readModel.HasLowercase,
|
|
|
|
HasNumber: readModel.HasNumber,
|
|
|
|
HasSymbol: readModel.HasSymbol,
|
|
|
|
HasUppercase: readModel.HasUpperCase,
|
|
|
|
MinLength: uint64(readModel.MinLength),
|
2021-01-15 08:32:59 +00:00
|
|
|
//TODO: OTPState: int32,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
func readModelToPasswordLockoutPolicy(readModel *IAMPasswordLockoutPolicyReadModel) *model.PasswordLockoutPolicy {
|
|
|
|
return &model.PasswordLockoutPolicy{
|
|
|
|
ObjectRoot: readModelToObjectRoot(readModel.PasswordLockoutPolicyReadModel.ReadModel),
|
|
|
|
MaxAttempts: uint64(readModel.MaxAttempts),
|
|
|
|
ShowLockOutFailures: readModel.ShowLockOutFailures,
|
2021-01-15 08:32:59 +00:00
|
|
|
//TODO: OTPState: int32,
|
2021-01-04 13:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToIDPConfigs(rm *IAMIDPConfigsReadModel) []*model.IDPConfig {
|
|
|
|
configs := make([]*model.IDPConfig, len(rm.Configs))
|
|
|
|
for i, config := range rm.Configs {
|
|
|
|
configs[i] = readModelToIDPConfig(&IAMIDPConfigReadModel{IDPConfigReadModel: *config})
|
|
|
|
}
|
|
|
|
return configs
|
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToIDPConfig(rm *IAMIDPConfigReadModel) *model.IDPConfig {
|
|
|
|
return &model.IDPConfig{
|
|
|
|
ObjectRoot: readModelToObjectRoot(rm.ReadModel),
|
|
|
|
OIDCConfig: readModelToIDPOIDCConfig(rm.OIDCConfig),
|
|
|
|
IDPConfigID: rm.ConfigID,
|
|
|
|
Name: rm.Name,
|
|
|
|
State: model.IDPConfigState(rm.State),
|
|
|
|
StylingType: model.IDPStylingType(rm.StylingType),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToIDPOIDCConfig(rm *OIDCConfigReadModel) *model.OIDCIDPConfig {
|
|
|
|
return &model.OIDCIDPConfig{
|
|
|
|
ObjectRoot: readModelToObjectRoot(rm.ReadModel),
|
|
|
|
ClientID: rm.ClientID,
|
|
|
|
ClientSecret: rm.ClientSecret,
|
|
|
|
ClientSecretString: string(rm.ClientSecret.Crypted),
|
|
|
|
IDPConfigID: rm.IDPConfigID,
|
|
|
|
IDPDisplayNameMapping: model.OIDCMappingField(rm.IDPDisplayNameMapping),
|
|
|
|
Issuer: rm.Issuer,
|
|
|
|
Scopes: rm.Scopes,
|
|
|
|
UsernameMapping: model.OIDCMappingField(rm.UserNameMapping),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func readModelToObjectRoot(readModel eventstore.ReadModel) models.ObjectRoot {
|
|
|
|
return models.ObjectRoot{
|
|
|
|
AggregateID: readModel.AggregateID,
|
|
|
|
ChangeDate: readModel.ChangeDate,
|
|
|
|
CreationDate: readModel.CreationDate,
|
|
|
|
ResourceOwner: readModel.ResourceOwner,
|
|
|
|
Sequence: readModel.ProcessedSequence,
|
|
|
|
}
|
|
|
|
}
|