policy, idp, member.

member not working atm
This commit is contained in:
adlerhurst
2020-11-30 06:40:56 +01:00
parent fc861ea544
commit ebeedd1346
45 changed files with 795 additions and 316 deletions
+24 -25
View File
@@ -1,7 +1,6 @@
package policy
import (
"context"
"encoding/json"
"github.com/caos/zitadel/internal/errors"
@@ -17,9 +16,6 @@ const (
type LabelPolicyAggregate struct {
eventstore.Aggregate
PrimaryColor string
SecondaryColor string
}
type LabelPolicyReadModel struct {
@@ -43,6 +39,17 @@ func (rm *LabelPolicyReadModel) Reduce() error {
return rm.ReadModel.Reduce()
}
type LabelPolicyWriteModel struct {
eventstore.WriteModel
PrimaryColor string
SecondaryColor string
}
func (wm *LabelPolicyWriteModel) Reduce() error {
return errors.ThrowUnimplemented(nil, "POLIC-xJjvN", "reduce unimpelemnted")
}
type LabelPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
@@ -59,16 +66,13 @@ func (e *LabelPolicyAddedEvent) Data() interface{} {
}
func NewLabelPolicyAddedEvent(
ctx context.Context,
base *eventstore.BaseEvent,
primaryColor,
secondaryColor string,
) *LabelPolicyAddedEvent {
return &LabelPolicyAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
LabelPolicyAddedEventType,
),
BaseEvent: *base,
PrimaryColor: primaryColor,
SecondaryColor: secondaryColor,
}
@@ -103,22 +107,20 @@ func (e *LabelPolicyChangedEvent) Data() interface{} {
}
func NewLabelPolicyChangedEvent(
ctx context.Context,
current,
changed *LabelPolicyAggregate,
base *eventstore.BaseEvent,
current *LabelPolicyWriteModel,
primaryColor,
secondaryColor string,
) *LabelPolicyChangedEvent {
e := &LabelPolicyChangedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
LabelPolicyChangedEventType,
),
BaseEvent: *base,
}
if current.PrimaryColor != changed.PrimaryColor {
e.PrimaryColor = changed.PrimaryColor
if primaryColor != "" && current.PrimaryColor != primaryColor {
e.PrimaryColor = primaryColor
}
if current.SecondaryColor != changed.SecondaryColor {
e.SecondaryColor = changed.SecondaryColor
if secondaryColor != "" && current.SecondaryColor != secondaryColor {
e.SecondaryColor = secondaryColor
}
return e
@@ -149,12 +151,9 @@ func (e *LabelPolicyRemovedEvent) Data() interface{} {
return nil
}
func NewLabelPolicyRemovedEvent(ctx context.Context) *LabelPolicyRemovedEvent {
func NewLabelPolicyRemovedEvent(base *eventstore.BaseEvent) *LabelPolicyRemovedEvent {
return &LabelPolicyRemovedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
LabelPolicyRemovedEventType,
),
BaseEvent: *base,
}
}
+101 -32
View File
@@ -1,26 +1,24 @@
package policy
import (
"context"
"encoding/json"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore/v2"
"github.com/caos/zitadel/internal/eventstore/v2/repository"
"github.com/caos/zitadel/internal/v2/repository/idp/provider"
)
const (
LoginPolicyAddedEventType = "policy.login.added"
LoginPolicyChangedEventType = "policy.login.changed"
LoginPolicyRemovedEventType = "policy.login.removed"
LoginPolicyAddedEventType = "policy.login.added"
LoginPolicyChangedEventType = "policy.login.changed"
LoginPolicyRemovedEventType = "policy.login.removed"
LoginPolicyIDPProviderAddedEventType = "policy.login." + provider.AddedEventType
LoginPolicyIDPProviderRemovedEventType = "policy.login." + provider.RemovedEventType
)
type LoginPolicyAggregate struct {
eventstore.Aggregate
AllowUserNamePassword bool
AllowRegister bool
AllowExternalIDP bool
}
type LoginPolicyReadModel struct {
@@ -47,13 +45,24 @@ func (rm *LoginPolicyReadModel) Reduce() error {
return rm.ReadModel.Reduce()
}
type LoginPolicyWriteModel struct {
eventstore.WriteModel
AllowUserNamePassword bool
AllowRegister bool
AllowExternalIDP bool
}
func (wm *LoginPolicyWriteModel) Reduce() error {
return errors.ThrowUnimplemented(nil, "POLIC-xJjvN", "reduce unimpelemnted")
}
type LoginPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
AllowUserNamePassword bool `json:"allowUsernamePassword"`
AllowRegister bool `json:"allowRegister"`
AllowExternalIDP bool `json:"allowExternalIdp"`
// TODO: IDPProviders
}
func (e *LoginPolicyAddedEvent) CheckPrevious() bool {
@@ -65,17 +74,14 @@ func (e *LoginPolicyAddedEvent) Data() interface{} {
}
func NewLoginPolicyAddedEvent(
ctx context.Context,
base *eventstore.BaseEvent,
allowUserNamePassword,
allowRegister,
allowExternalIDP bool,
) *LoginPolicyAddedEvent {
return &LoginPolicyAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
LoginPolicyAddedEventType,
),
BaseEvent: *base,
AllowExternalIDP: allowExternalIDP,
AllowRegister: allowRegister,
AllowUserNamePassword: allowUserNamePassword,
@@ -112,26 +118,25 @@ func (e *LoginPolicyChangedEvent) Data() interface{} {
}
func NewLoginPolicyChangedEvent(
ctx context.Context,
current,
changed *LoginPolicyAggregate,
base *eventstore.BaseEvent,
current *LoginPolicyWriteModel,
allowUserNamePassword,
allowRegister,
allowExternalIDP bool,
) *LoginPolicyChangedEvent {
e := &LoginPolicyChangedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
LoginPolicyChangedEventType,
),
BaseEvent: *base,
}
if current.AllowUserNamePassword != changed.AllowUserNamePassword {
e.AllowUserNamePassword = changed.AllowUserNamePassword
if current.AllowUserNamePassword != allowUserNamePassword {
e.AllowUserNamePassword = allowUserNamePassword
}
if current.AllowRegister != changed.AllowRegister {
e.AllowRegister = changed.AllowRegister
if current.AllowRegister != allowRegister {
e.AllowRegister = allowRegister
}
if current.AllowExternalIDP != changed.AllowExternalIDP {
e.AllowExternalIDP = changed.AllowExternalIDP
if current.AllowExternalIDP != allowExternalIDP {
e.AllowExternalIDP = allowExternalIDP
}
return e
@@ -162,12 +167,9 @@ func (e *LoginPolicyRemovedEvent) Data() interface{} {
return nil
}
func NewLoginPolicyRemovedEvent(ctx context.Context) *LoginPolicyRemovedEvent {
func NewLoginPolicyRemovedEvent(base *eventstore.BaseEvent) *LoginPolicyRemovedEvent {
return &LoginPolicyRemovedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
LoginPolicyRemovedEventType,
),
BaseEvent: *base,
}
}
@@ -176,3 +178,70 @@ func LoginPolicyRemovedEventMapper(event *repository.Event) (eventstore.EventRea
BaseEvent: *eventstore.BaseEventFromRepo(event),
}, nil
}
type IDPProviderWriteModel struct {
provider.WriteModel
}
func (wm *IDPProviderWriteModel) AppendEvents(events ...eventstore.EventReader) {
for _, event := range events {
switch e := event.(type) {
case *IDPProviderAddedEvent:
wm.WriteModel.AppendEvents(&e.AddedEvent)
}
}
}
type IDPProviderAddedEvent struct {
provider.AddedEvent
}
func NewIDPProviderAddedEvent(
base *eventstore.BaseEvent,
idpConfigID string,
idpProviderType provider.Type,
) *IDPProviderAddedEvent {
return &IDPProviderAddedEvent{
AddedEvent: *provider.NewAddedEvent(
base,
idpConfigID,
idpProviderType),
}
}
func IDPProviderAddedEventEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := provider.AddedEventEventMapper(event)
if err != nil {
return nil, err
}
return &IDPProviderAddedEvent{
AddedEvent: *e.(*provider.AddedEvent),
}, nil
}
type IDPProviderRemovedEvent struct {
provider.RemovedEvent
}
func NewIDPProviderRemovedEvent(
base *eventstore.BaseEvent,
idpConfigID string,
) *IDPProviderRemovedEvent {
return &IDPProviderRemovedEvent{
RemovedEvent: *provider.NewRemovedEvent(base, idpConfigID),
}
}
func IDPProviderRemovedEventEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := provider.RemovedEventEventMapper(event)
if err != nil {
return nil, err
}
return &IDPProviderRemovedEvent{
RemovedEvent: *e.(*provider.RemovedEvent),
}, nil
}
+12 -8
View File
@@ -1,7 +1,6 @@
package policy
import (
"context"
"encoding/json"
"github.com/caos/zitadel/internal/errors"
@@ -15,8 +14,6 @@ const (
type OrgIAMPolicyAggregate struct {
eventstore.Aggregate
UserLoginMustBeDomain bool
}
type OrgIAMPolicyReadModel struct {
@@ -35,6 +32,16 @@ func (rm *OrgIAMPolicyReadModel) Reduce() error {
return rm.ReadModel.Reduce()
}
type OrgIAMPolicyWriteModel struct {
eventstore.WriteModel
UserLoginMustBeDomain bool
}
func (wm *OrgIAMPolicyWriteModel) Reduce() error {
return errors.ThrowUnimplemented(nil, "POLIC-xJjvN", "reduce unimpelemnted")
}
type OrgIAMPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
@@ -50,15 +57,12 @@ func (e *OrgIAMPolicyAddedEvent) Data() interface{} {
}
func NewOrgIAMPolicyAddedEvent(
ctx context.Context,
base *eventstore.BaseEvent,
userLoginMustBeDomain bool,
) *OrgIAMPolicyAddedEvent {
return &OrgIAMPolicyAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
OrgIAMPolicyAddedEventType,
),
BaseEvent: *base,
UserLoginMustBeDomain: userLoginMustBeDomain,
}
}
+24 -25
View File
@@ -1,7 +1,6 @@
package policy
import (
"context"
"encoding/json"
"github.com/caos/zitadel/internal/errors"
@@ -17,9 +16,6 @@ const (
type PasswordAgePolicyAggregate struct {
eventstore.Aggregate
ExpireWarnDays uint16
MaxAgeDays uint16
}
type PasswordAgePolicyReadModel struct {
@@ -43,6 +39,17 @@ func (rm *PasswordAgePolicyReadModel) Reduce() error {
return rm.ReadModel.Reduce()
}
type PasswordAgePolicyWriteModel struct {
eventstore.WriteModel
ExpireWarnDays uint16
MaxAgeDays uint16
}
func (wm *PasswordAgePolicyWriteModel) Reduce() error {
return errors.ThrowUnimplemented(nil, "POLIC-xJjvN", "reduce unimpelemnted")
}
type PasswordAgePolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
@@ -59,16 +66,13 @@ func (e *PasswordAgePolicyAddedEvent) Data() interface{} {
}
func NewPasswordAgePolicyAddedEvent(
ctx context.Context,
base *eventstore.BaseEvent,
expireWarnDays,
maxAgeDays uint16,
) *PasswordAgePolicyAddedEvent {
return &PasswordAgePolicyAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordAgePolicyAddedEventType,
),
BaseEvent: *base,
ExpireWarnDays: expireWarnDays,
MaxAgeDays: maxAgeDays,
}
@@ -103,23 +107,21 @@ func (e *PasswordAgePolicyChangedEvent) Data() interface{} {
}
func NewPasswordAgePolicyChangedEvent(
ctx context.Context,
current,
changed *PasswordAgePolicyAggregate,
base *eventstore.BaseEvent,
current *PasswordAgePolicyWriteModel,
expireWarnDays,
maxAgeDays uint16,
) *PasswordAgePolicyChangedEvent {
e := &PasswordAgePolicyChangedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordAgePolicyChangedEventType,
),
BaseEvent: *base,
}
if current.ExpireWarnDays != changed.ExpireWarnDays {
e.ExpireWarnDays = changed.ExpireWarnDays
if current.ExpireWarnDays != expireWarnDays {
e.ExpireWarnDays = expireWarnDays
}
if current.MaxAgeDays != changed.MaxAgeDays {
e.MaxAgeDays = changed.ExpireWarnDays
if current.MaxAgeDays != maxAgeDays {
e.MaxAgeDays = maxAgeDays
}
return e
@@ -151,16 +153,13 @@ func (e *PasswordAgePolicyRemovedEvent) Data() interface{} {
}
func NewPasswordAgePolicyRemovedEvent(
ctx context.Context,
base *eventstore.BaseEvent,
current,
changed *PasswordAgePolicyRemovedEvent,
) *PasswordAgePolicyChangedEvent {
return &PasswordAgePolicyChangedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordAgePolicyRemovedEventType,
),
BaseEvent: *base,
}
}
@@ -1,7 +1,6 @@
package policy
import (
"context"
"encoding/json"
"github.com/caos/zitadel/internal/errors"
@@ -17,12 +16,6 @@ const (
type PasswordComplexityPolicyAggregate struct {
eventstore.Aggregate
MinLength uint8
HasLowercase bool
HasUpperCase bool
HasNumber bool
HasSymbol bool
}
type PasswordComplexityPolicyReadModel struct {
@@ -55,6 +48,20 @@ func (rm *PasswordComplexityPolicyReadModel) Reduce() error {
return rm.ReadModel.Reduce()
}
type PasswordComplexityPolicyWriteModel struct {
eventstore.WriteModel
MinLength uint8
HasLowercase bool
HasUpperCase bool
HasNumber bool
HasSymbol bool
}
func (wm *PasswordComplexityPolicyWriteModel) Reduce() error {
return errors.ThrowUnimplemented(nil, "POLIC-xJjvN", "reduce unimpelemnted")
}
type PasswordComplexityPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
@@ -74,7 +81,7 @@ func (e *PasswordComplexityPolicyAddedEvent) Data() interface{} {
}
func NewPasswordComplexityPolicyAddedEvent(
ctx context.Context,
base *eventstore.BaseEvent,
hasLowerCase,
hasUpperCase,
hasNumber,
@@ -83,10 +90,7 @@ func NewPasswordComplexityPolicyAddedEvent(
) *PasswordComplexityPolicyAddedEvent {
return &PasswordComplexityPolicyAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordComplexityPolicyAddedEventType,
),
BaseEvent: *base,
HasLowercase: hasLowerCase,
HasNumber: hasNumber,
HasSymbol: hasSymbol,
@@ -127,32 +131,33 @@ func (e *PasswordComplexityPolicyChangedEvent) Data() interface{} {
}
func NewPasswordComplexityPolicyChangedEvent(
ctx context.Context,
current,
changed *PasswordComplexityPolicyAggregate,
base *eventstore.BaseEvent,
current *PasswordComplexityPolicyWriteModel,
minLength uint8,
hasLowerCase,
hasUpperCase,
hasNumber,
hasSymbol bool,
) *PasswordComplexityPolicyChangedEvent {
e := &PasswordComplexityPolicyChangedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordComplexityPolicyChangedEventType,
),
BaseEvent: *base,
}
if current.MinLength != changed.MinLength {
e.MinLength = changed.MinLength
if current.MinLength != minLength {
e.MinLength = minLength
}
if current.HasLowercase != changed.HasLowercase {
e.HasLowercase = changed.HasLowercase
if current.HasLowercase != hasLowerCase {
e.HasLowercase = hasLowerCase
}
if current.HasUpperCase != changed.HasUpperCase {
e.HasUpperCase = changed.HasUpperCase
if current.HasUpperCase != hasUpperCase {
e.HasUpperCase = hasUpperCase
}
if current.HasNumber != changed.HasNumber {
e.HasNumber = changed.HasNumber
if current.HasNumber != hasNumber {
e.HasNumber = hasNumber
}
if current.HasSymbol != changed.HasSymbol {
e.HasSymbol = changed.HasSymbol
if current.HasSymbol != hasSymbol {
e.HasSymbol = hasSymbol
}
return e
@@ -183,15 +188,9 @@ func (e *PasswordComplexityPolicyRemovedEvent) Data() interface{} {
return nil
}
func NewPasswordComplexityPolicyRemovedEvent(
ctx context.Context,
) *PasswordComplexityPolicyRemovedEvent {
func NewPasswordComplexityPolicyRemovedEvent(base *eventstore.BaseEvent) *PasswordComplexityPolicyRemovedEvent {
return &PasswordComplexityPolicyRemovedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordComplexityPolicyRemovedEventType,
),
BaseEvent: *base,
}
}
@@ -1,7 +1,6 @@
package policy
import (
"context"
"encoding/json"
"github.com/caos/zitadel/internal/errors"
@@ -17,9 +16,6 @@ const (
type PasswordLockoutPolicyAggregate struct {
eventstore.Aggregate
MaxAttempts uint8
ShowLockOutFailures bool
}
type PasswordLockoutPolicyReadModel struct {
@@ -43,6 +39,17 @@ func (rm *PasswordLockoutPolicyReadModel) Reduce() error {
return rm.ReadModel.Reduce()
}
type PasswordLockoutPolicyWriteModel struct {
eventstore.WriteModel
MaxAttempts uint8
ShowLockOutFailures bool
}
func (wm *PasswordLockoutPolicyWriteModel) Reduce() error {
return errors.ThrowUnimplemented(nil, "POLIC-xJjvN", "reduce unimpelemnted")
}
type PasswordLockoutPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
@@ -59,16 +66,13 @@ func (e *PasswordLockoutPolicyAddedEvent) Data() interface{} {
}
func NewPasswordLockoutPolicyAddedEvent(
ctx context.Context,
base *eventstore.BaseEvent,
maxAttempts uint8,
showLockOutFailures bool,
) *PasswordLockoutPolicyAddedEvent {
return &PasswordLockoutPolicyAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordLockoutPolicyAddedEventType,
),
BaseEvent: *base,
MaxAttempts: maxAttempts,
ShowLockOutFailures: showLockOutFailures,
}
@@ -103,23 +107,21 @@ func (e *PasswordLockoutPolicyChangedEvent) Data() interface{} {
}
func NewPasswordLockoutPolicyChangedEvent(
ctx context.Context,
current,
changed *PasswordLockoutPolicyAggregate,
base *eventstore.BaseEvent,
current *PasswordLockoutPolicyWriteModel,
maxAttempts uint8,
showLockOutFailures bool,
) *PasswordLockoutPolicyChangedEvent {
e := &PasswordLockoutPolicyChangedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordLockoutPolicyChangedEventType,
),
BaseEvent: *base,
}
if current.MaxAttempts != changed.MaxAttempts {
e.MaxAttempts = changed.MaxAttempts
if current.MaxAttempts != maxAttempts {
e.MaxAttempts = maxAttempts
}
if current.ShowLockOutFailures != changed.ShowLockOutFailures {
e.ShowLockOutFailures = changed.ShowLockOutFailures
if current.ShowLockOutFailures != showLockOutFailures {
e.ShowLockOutFailures = showLockOutFailures
}
return e
@@ -151,14 +153,11 @@ func (e *PasswordLockoutPolicyRemovedEvent) Data() interface{} {
}
func NewPasswordLockoutPolicyRemovedEvent(
ctx context.Context,
base *eventstore.BaseEvent,
) *PasswordLockoutPolicyRemovedEvent {
return &PasswordLockoutPolicyRemovedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
ctx,
PasswordLockoutPolicyRemovedEventType,
),
BaseEvent: *base,
}
}