mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
fbb30840f1
* feat: move pw policy * feat: default pw complexity policy * fix: org password complexity policy * fix: org password complexity policy * fix: pw complexity policy with setup * fix: age and lockout policies on aggregates * fix: migration * fix: org iam policy * fix: org iam policy * fix: org iam policy * fix: tests * fix: policy request * fix: merge master * fix(console): policies frontend (#817) * fix policy build * fix: age, complexity, lockout policies * fix: ready return err of setup not done * fix: fix remove policies in spoolers * fix: fix remove policies in spoolers * feat(console): policy settings for iam and org (#824) * fix policy build * fix: age, complexity, lockout policies * fix pwd complexity * policy remove action * add imports * fix accounts card, enable mgmt login policy * lint * add iam policy to admin * toasts, i18n, show default * routing, i18n * reset policy, toast i18n, cleanup, routing * policy delete permission * lint style * delete iam policy * delete non project from grid list, i18n * lint ts, style * fix: remove instead delete * feat(console): delete external idp from user (#835) * dialog i18n, delete column and function * dialog i18n * fix rm button * Update console/src/assets/i18n/de.json Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * Update console/src/assets/i18n/de.json Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * fix: revert env, rename policy, remove comments * fix: lowercase sich * fix: pr requests * Update internal/iam/repository/eventsourcing/eventstore_test.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: tests * fix: tests * fix(console): policies (#839) * fix: nil pointer on get userdata (#815) * fix: external login (#818) * fix: external login * fix: external login * feat(console): delete user (#819) * add action col to user table, i18n * delete user from detail component * lint * fix(console): cleanup user detail and member components, user/me redirect, permission guards, filter, org policy guard, user table, scss cleanup (#808) * fix: remove user.write guard for filtering * border color * fix user routing from member tables * idp detail layout * generic contact component * fix redirect to auth user, user grant disable * disable policy action without permission, i18n * user-create flex fix, contact ng-content * rm unused styles * sidenav divider * lint * chore(deps-dev): bump @angular/cli from 10.1.3 to 10.1.4 in /console (#806) * fix: user session with external login (#797) * fix: user session with external login * fix: tests * fix: tests * fix: change idp config name * fix(container): stop copying / and instead only copy zitadel (#691) * chore: stop copying / and instead only copy zitadel * Update Dockerfile * Update release.yml * enable anchors debug * fix(container): don't copy alpine content into scratch execpt pwd * chore: remove need step * merge master * chore(deps-dev): bump @angular/cli from 10.1.3 to 10.1.4 in /console Bumps [@angular/cli](https://github.com/angular/angular-cli) from 10.1.3 to 10.1.4. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/compare/v10.1.3...v10.1.4) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular/language-service from 10.1.3 to 10.1.4 in /console (#805) * fix: user session with external login (#797) * fix: user session with external login * fix: tests * fix: tests * fix: change idp config name * fix(container): stop copying / and instead only copy zitadel (#691) * chore: stop copying / and instead only copy zitadel * Update Dockerfile * Update release.yml * enable anchors debug * fix(container): don't copy alpine content into scratch execpt pwd * chore: remove need step * merge master * chore(deps-dev): bump @angular/language-service in /console Bumps [@angular/language-service](https://github.com/angular/angular/tree/HEAD/packages/language-service) from 10.1.3 to 10.1.4. - [Release notes](https://github.com/angular/angular/releases) - [Changelog](https://github.com/angular/angular/blob/master/CHANGELOG.md) - [Commits](https://github.com/angular/angular/commits/10.1.4/packages/language-service) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump codelyzer from 6.0.0 to 6.0.1 in /console (#804) * fix: user session with external login (#797) * fix: user session with external login * fix: tests * fix: tests * fix: change idp config name * fix(container): stop copying / and instead only copy zitadel (#691) * chore: stop copying / and instead only copy zitadel * Update Dockerfile * Update release.yml * enable anchors debug * fix(container): don't copy alpine content into scratch execpt pwd * chore: remove need step * merge master * chore(deps-dev): bump codelyzer from 6.0.0 to 6.0.1 in /console Bumps [codelyzer](https://github.com/mgechev/codelyzer) from 6.0.0 to 6.0.1. - [Release notes](https://github.com/mgechev/codelyzer/releases) - [Changelog](https://github.com/mgechev/codelyzer/blob/master/CHANGELOG.md) - [Commits](https://github.com/mgechev/codelyzer/commits/6.0.1) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump @angular-devkit/build-angular from 0.1000.8 to 0.1001.4 in /console (#803) * fix: user session with external login (#797) * fix: user session with external login * fix: tests * fix: tests * fix: change idp config name * fix(container): stop copying / and instead only copy zitadel (#691) * chore: stop copying / and instead only copy zitadel * Update Dockerfile * Update release.yml * enable anchors debug * fix(container): don't copy alpine content into scratch execpt pwd * chore: remove need step * merge master * chore(deps-dev): bump @angular-devkit/build-angular in /console Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 0.1000.8 to 0.1001.4. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/commits) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Max Peintner <max@caos.ch> * chore(deps): bump uuid from 8.3.0 to 8.3.1 in /console (#802) * fix: user session with external login (#797) * fix: user session with external login * fix: tests * fix: tests * fix: change idp config name * fix(container): stop copying / and instead only copy zitadel (#691) * chore: stop copying / and instead only copy zitadel * Update Dockerfile * Update release.yml * enable anchors debug * fix(container): don't copy alpine content into scratch execpt pwd * chore: remove need step * merge master * chore(deps): bump uuid from 8.3.0 to 8.3.1 in /console Bumps [uuid](https://github.com/uuidjs/uuid) from 8.3.0 to 8.3.1. - [Release notes](https://github.com/uuidjs/uuid/releases) - [Changelog](https://github.com/uuidjs/uuid/blob/master/CHANGELOG.md) - [Commits](https://github.com/uuidjs/uuid/compare/v8.3.0...v8.3.1) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * create memberstable as common component * iam member cleanup * iam + org m table, user table service user avatar * toast config * fix selection emitter * fix project grant table width * project grant members refactor * theme optimizations * member table col delete * lint * fix table row color * refactor grey color * lint scss * org list redirect on click, fix user table undef * refresh table after grant add Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch> * fix(console): intercept navigator.language, set browser lang as default for user without explicit setting, user table outline, member create dialog import (#820) * i18n interceptor, set language to browser lang * nullcheck * rm external idp log * fix module imports, rm user displayname from i18n * Update console/src/assets/i18n/de.json Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * fix: delete external idps from users (#822) * fix(console): permission regex, account switcher null check, restrict app and member create access (#821) * fix member table disable, gerneal regexp * fix user session card, app disable * memberships max count * fix policy permissions * permission check for member add dialog * lint * rm accounts log * rm id regex * fix: handle usermemberships on project and project grant delete (#825) * fix: go handler Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch> * fix: tests * fix: not needed error handling Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Silvan <silvan.reusser@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch>
567 lines
21 KiB
Go
567 lines
21 KiB
Go
package eventsourcing
|
|
|
|
import (
|
|
"context"
|
|
"github.com/caos/zitadel/internal/errors"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
)
|
|
|
|
func IAMByIDQuery(id string, latestSequence uint64) (*es_models.SearchQuery, error) {
|
|
if id == "" {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-0soe4", "Errors.IAM.IDMissing")
|
|
}
|
|
return IAMQuery(latestSequence).
|
|
AggregateIDFilter(id), nil
|
|
}
|
|
|
|
func IAMQuery(latestSequence uint64) *es_models.SearchQuery {
|
|
return es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.IAMAggregate).
|
|
LatestSequenceFilter(latestSequence)
|
|
}
|
|
|
|
func IAMAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, iam *model.IAM) (*es_models.Aggregate, error) {
|
|
if iam == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-lo04e", "Errors.Internal")
|
|
}
|
|
return aggCreator.NewAggregate(ctx, iam.AggregateID, model.IAMAggregate, model.IAMVersion, iam.Sequence)
|
|
}
|
|
|
|
func IAMAggregateOverwriteContext(ctx context.Context, aggCreator *es_models.AggregateCreator, iam *model.IAM, resourceOwnerID string, userID string) (*es_models.Aggregate, error) {
|
|
if iam == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-dis83", "Errors.Internal")
|
|
}
|
|
|
|
return aggCreator.NewAggregate(ctx, iam.AggregateID, model.IAMAggregate, model.IAMVersion, iam.Sequence, es_models.OverwriteResourceOwner(resourceOwnerID), es_models.OverwriteEditorUser(userID))
|
|
}
|
|
|
|
func IAMSetupStartedAggregate(aggCreator *es_models.AggregateCreator, iam *model.IAM) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
agg, err := IAMAggregate(ctx, aggCreator, iam)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.IAMSetupStarted, &struct{ Step model.Step }{Step: iam.SetUpStarted})
|
|
}
|
|
}
|
|
|
|
func IAMSetupDoneAggregate(aggCreator *es_models.AggregateCreator, iam *model.IAM) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
agg, err := IAMAggregate(ctx, aggCreator, iam)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return agg.AppendEvent(model.IAMSetupDone, &struct{ Step model.Step }{Step: iam.SetUpDone})
|
|
}
|
|
}
|
|
|
|
func IAMSetupDoneEvent(ctx context.Context, agg *es_models.Aggregate, iam *model.IAM) (*es_models.Aggregate, error) {
|
|
return agg.AppendEvent(model.IAMSetupDone, &struct{ Step model.Step }{Step: iam.SetUpDone})
|
|
}
|
|
|
|
func IAMSetGlobalOrgAggregate(aggCreator *es_models.AggregateCreator, iam *model.IAM, globalOrg string) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if globalOrg == "" {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-8siwa", "Errors.IAM.GlobalOrgMissing")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, iam)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.GlobalOrgSet, &model.IAM{GlobalOrgID: globalOrg})
|
|
}
|
|
}
|
|
|
|
func IAMSetIamProjectAggregate(aggCreator *es_models.AggregateCreator, iam *model.IAM, projectID string) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if projectID == "" {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-sjuw3", "Errors.IAM.IamProjectIDMisisng")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, iam)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.IAMProjectSet, &model.IAM{IAMProjectID: projectID})
|
|
}
|
|
}
|
|
|
|
func IAMMemberAddedAggregate(aggCreator *es_models.AggregateCreator, existingIAM *model.IAM, member *model.IAMMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if member == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-9sope", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existingIAM)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.IAMMemberAdded, member)
|
|
}
|
|
}
|
|
|
|
func IAMMemberChangedAggregate(aggCreator *es_models.AggregateCreator, existingIAM *model.IAM, member *model.IAMMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if member == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-38skf", "Errors.Internal")
|
|
}
|
|
|
|
agg, err := IAMAggregate(ctx, aggCreator, existingIAM)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.IAMMemberChanged, member)
|
|
}
|
|
}
|
|
|
|
func IAMMemberRemovedAggregate(aggCreator *es_models.AggregateCreator, existingIAM *model.IAM, member *model.IAMMember) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if member == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-90lsw", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existingIAM)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.IAMMemberRemoved, member)
|
|
}
|
|
}
|
|
|
|
func IDPConfigAddedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, idp *model.IDPConfig) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if idp == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-MSn7d", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
agg, err = agg.AppendEvent(model.IDPConfigAdded, idp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if idp.OIDCIDPConfig != nil {
|
|
return agg.AppendEvent(model.OIDCIDPConfigAdded, idp.OIDCIDPConfig)
|
|
}
|
|
return agg, nil
|
|
}
|
|
}
|
|
|
|
func IDPConfigChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, idp *model.IDPConfig) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if idp == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Amc7s", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var changes map[string]interface{}
|
|
for _, i := range existing.IDPs {
|
|
if i.IDPConfigID == idp.IDPConfigID {
|
|
changes = i.Changes(idp)
|
|
}
|
|
}
|
|
return agg.AppendEvent(model.IDPConfigChanged, changes)
|
|
}
|
|
}
|
|
|
|
func IDPConfigRemovedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.IAM, idp *model.IDPConfig, provider *model.IDPProvider) (*es_models.Aggregate, error) {
|
|
if idp == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-se23g", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
agg, err = agg.AppendEvent(model.IDPConfigRemoved, &model.IDPConfigID{IDPConfigID: idp.IDPConfigID})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if provider != nil {
|
|
return agg.AppendEvent(model.LoginPolicyIDPProviderCascadeRemoved, &model.IDPConfigID{IDPConfigID: idp.IDPConfigID})
|
|
}
|
|
return agg, nil
|
|
}
|
|
|
|
func IDPConfigDeactivatedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, idp *model.IDPConfig) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if idp == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-slfi3", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.IDPConfigDeactivated, &model.IDPConfigID{IDPConfigID: idp.IDPConfigID})
|
|
}
|
|
}
|
|
|
|
func IDPConfigReactivatedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, idp *model.IDPConfig) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if idp == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-slf32", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.IDPConfigReactivated, &model.IDPConfigID{IDPConfigID: idp.IDPConfigID})
|
|
}
|
|
}
|
|
|
|
func OIDCIDPConfigChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, config *model.OIDCIDPConfig) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if config == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-slf32", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var changes map[string]interface{}
|
|
for _, idp := range existing.IDPs {
|
|
if idp.IDPConfigID == config.IDPConfigID && idp.OIDCIDPConfig != nil {
|
|
changes = idp.OIDCIDPConfig.Changes(config)
|
|
}
|
|
}
|
|
if len(changes) <= 1 {
|
|
return nil, errors.ThrowPreconditionFailedf(nil, "EVENT-Cml9s", "Errors.NoChangesFound")
|
|
}
|
|
return agg.AppendEvent(model.OIDCIDPConfigChanged, changes)
|
|
}
|
|
}
|
|
|
|
func LoginPolicyAddedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.LoginPolicy) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Smla8", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validationQuery := es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.IAMAggregate).
|
|
EventTypesFilter(model.LoginPolicyAdded).
|
|
AggregateIDFilter(existing.AggregateID)
|
|
|
|
validation := checkExistingLoginPolicyValidation()
|
|
agg.SetPrecondition(validationQuery, validation)
|
|
return agg.AppendEvent(model.LoginPolicyAdded, policy)
|
|
}
|
|
|
|
func LoginPolicyChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.LoginPolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Mlco9", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
changes := existing.DefaultLoginPolicy.Changes(policy)
|
|
if len(changes) == 0 {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Smk8d", "Errors.NoChangesFound")
|
|
}
|
|
return agg.AppendEvent(model.LoginPolicyChanged, changes)
|
|
}
|
|
}
|
|
|
|
func LoginPolicyIDPProviderAddedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, provider *model.IDPProvider) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if provider == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Sml9d", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validationQuery := es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.IAMAggregate).
|
|
AggregateIDFilter(existing.AggregateID)
|
|
|
|
validation := checkExistingLoginPolicyIDPProviderValidation(provider.IDPConfigID)
|
|
agg.SetPrecondition(validationQuery, validation)
|
|
return agg.AppendEvent(model.LoginPolicyIDPProviderAdded, provider)
|
|
}
|
|
}
|
|
|
|
func LoginPolicyIDPProviderRemovedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.IAM, provider *model.IDPProviderID) (*es_models.Aggregate, error) {
|
|
if provider == nil || existing == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Sml9d", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return agg.AppendEvent(model.LoginPolicyIDPProviderRemoved, provider)
|
|
}
|
|
|
|
func PasswordComplexityPolicyAddedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.PasswordComplexityPolicy) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Smla8", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validationQuery := es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.IAMAggregate).
|
|
EventTypesFilter(model.PasswordComplexityPolicyAdded).
|
|
AggregateIDFilter(existing.AggregateID)
|
|
|
|
validation := checkExistingPasswordComplexityPolicyValidation()
|
|
agg.SetPrecondition(validationQuery, validation)
|
|
return agg.AppendEvent(model.PasswordComplexityPolicyAdded, policy)
|
|
}
|
|
|
|
func PasswordComplexityPolicyChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.PasswordComplexityPolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Mlco9", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
changes := existing.DefaultPasswordComplexityPolicy.Changes(policy)
|
|
if len(changes) == 0 {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-Smk8d", "Errors.NoChangesFound")
|
|
}
|
|
return agg.AppendEvent(model.PasswordComplexityPolicyChanged, changes)
|
|
}
|
|
}
|
|
|
|
func PasswordAgePolicyAddedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.PasswordAgePolicy) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-T7sui", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validationQuery := es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.IAMAggregate).
|
|
EventTypesFilter(model.PasswordAgePolicyAdded).
|
|
AggregateIDFilter(existing.AggregateID)
|
|
|
|
validation := checkExistingPasswordAgePolicyValidation()
|
|
agg.SetPrecondition(validationQuery, validation)
|
|
return agg.AppendEvent(model.PasswordAgePolicyAdded, policy)
|
|
}
|
|
|
|
func PasswordAgePolicyChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.PasswordAgePolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-3Gs0o", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
changes := existing.DefaultPasswordAgePolicy.Changes(policy)
|
|
if len(changes) == 0 {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-3Wdos", "Errors.NoChangesFound")
|
|
}
|
|
return agg.AppendEvent(model.PasswordAgePolicyChanged, changes)
|
|
}
|
|
}
|
|
|
|
func PasswordLockoutPolicyAddedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.PasswordLockoutPolicy) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-w5Tds", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validationQuery := es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.IAMAggregate).
|
|
EventTypesFilter(model.PasswordLockoutPolicyAdded).
|
|
AggregateIDFilter(existing.AggregateID)
|
|
|
|
validation := checkExistingPasswordLockoutPolicyValidation()
|
|
agg.SetPrecondition(validationQuery, validation)
|
|
return agg.AppendEvent(model.PasswordLockoutPolicyAdded, policy)
|
|
}
|
|
|
|
func PasswordLockoutPolicyChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.PasswordLockoutPolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-2D0fs", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
changes := existing.DefaultPasswordLockoutPolicy.Changes(policy)
|
|
if len(changes) == 0 {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-7Hsk9", "Errors.NoChangesFound")
|
|
}
|
|
return agg.AppendEvent(model.PasswordLockoutPolicyChanged, changes)
|
|
}
|
|
}
|
|
|
|
func OrgIAMPolicyAddedAggregate(ctx context.Context, aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.OrgIAMPolicy) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-w5Tds", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
validationQuery := es_models.NewSearchQuery().
|
|
AggregateTypeFilter(model.IAMAggregate).
|
|
EventTypesFilter(model.OrgIAMPolicyAdded).
|
|
AggregateIDFilter(existing.AggregateID)
|
|
|
|
validation := checkExistingOrgIAMPolicyValidation()
|
|
agg.SetPrecondition(validationQuery, validation)
|
|
return agg.AppendEvent(model.OrgIAMPolicyAdded, policy)
|
|
}
|
|
|
|
func OrgIAMPolicyChangedAggregate(aggCreator *es_models.AggregateCreator, existing *model.IAM, policy *model.OrgIAMPolicy) func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
return func(ctx context.Context) (*es_models.Aggregate, error) {
|
|
if policy == nil {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-2D0fs", "Errors.Internal")
|
|
}
|
|
agg, err := IAMAggregate(ctx, aggCreator, existing)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
changes := existing.DefaultOrgIAMPolicy.Changes(policy)
|
|
if len(changes) == 0 {
|
|
return nil, errors.ThrowPreconditionFailed(nil, "EVENT-7Hsk9", "Errors.NoChangesFound")
|
|
}
|
|
return agg.AppendEvent(model.OrgIAMPolicyChanged, changes)
|
|
}
|
|
}
|
|
|
|
func checkExistingLoginPolicyValidation() func(...*es_models.Event) error {
|
|
return func(events ...*es_models.Event) error {
|
|
for _, event := range events {
|
|
switch event.Type {
|
|
case model.LoginPolicyAdded:
|
|
return errors.ThrowPreconditionFailed(nil, "EVENT-Ski9d", "Errors.IAM.LoginPolicy.AlreadyExists")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func checkExistingPasswordComplexityPolicyValidation() func(...*es_models.Event) error {
|
|
return func(events ...*es_models.Event) error {
|
|
for _, event := range events {
|
|
switch event.Type {
|
|
case model.PasswordComplexityPolicyAdded:
|
|
return errors.ThrowPreconditionFailed(nil, "EVENT-Ski9d", "Errors.IAM.PasswordComplexityPolicy.AlreadyExists")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func checkExistingPasswordAgePolicyValidation() func(...*es_models.Event) error {
|
|
return func(events ...*es_models.Event) error {
|
|
for _, event := range events {
|
|
switch event.Type {
|
|
case model.PasswordAgePolicyAdded:
|
|
return errors.ThrowPreconditionFailed(nil, "EVENT-Ski9d", "Errors.IAM.PasswordAgePolicy.AlreadyExists")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func checkExistingPasswordLockoutPolicyValidation() func(...*es_models.Event) error {
|
|
return func(events ...*es_models.Event) error {
|
|
for _, event := range events {
|
|
switch event.Type {
|
|
case model.PasswordLockoutPolicyAdded:
|
|
return errors.ThrowPreconditionFailed(nil, "EVENT-Ski9d", "Errors.IAM.PasswordLockoutPolicy.AlreadyExists")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func checkExistingOrgIAMPolicyValidation() func(...*es_models.Event) error {
|
|
return func(events ...*es_models.Event) error {
|
|
for _, event := range events {
|
|
switch event.Type {
|
|
case model.OrgIAMPolicyAdded:
|
|
return errors.ThrowPreconditionFailed(nil, "EVENT-bSm8f", "Errors.IAM.OrgIAMPolicy.AlreadyExists")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func checkExistingLoginPolicyIDPProviderValidation(idpConfigID string) func(...*es_models.Event) error {
|
|
return func(events ...*es_models.Event) error {
|
|
idpConfigs := make([]*model.IDPConfig, 0)
|
|
idps := make([]*model.IDPProvider, 0)
|
|
for _, event := range events {
|
|
switch event.Type {
|
|
case model.IDPConfigAdded:
|
|
config := new(model.IDPConfig)
|
|
err := config.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
idpConfigs = append(idpConfigs, config)
|
|
case model.IDPConfigRemoved:
|
|
config := new(model.IDPConfig)
|
|
err := config.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for i := len(idpConfigs) - 1; i >= 0; i-- {
|
|
if idpConfigs[i].IDPConfigID == config.IDPConfigID {
|
|
idpConfigs[i] = idpConfigs[len(idpConfigs)-1]
|
|
idpConfigs[len(idpConfigs)-1] = nil
|
|
idpConfigs = idpConfigs[:len(idpConfigs)-1]
|
|
break
|
|
}
|
|
}
|
|
case model.LoginPolicyIDPProviderAdded:
|
|
idp := new(model.IDPProvider)
|
|
err := idp.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
idps = append(idps, idp)
|
|
case model.LoginPolicyIDPProviderRemoved:
|
|
idp := new(model.IDPProvider)
|
|
err := idp.SetData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for i := len(idps) - 1; i >= 0; i-- {
|
|
if idps[i].IDPConfigID == idp.IDPConfigID {
|
|
idps[i] = idps[len(idps)-1]
|
|
idps[len(idps)-1] = nil
|
|
idps = idps[:len(idps)-1]
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exists := false
|
|
for _, p := range idpConfigs {
|
|
if p.IDPConfigID == idpConfigID {
|
|
exists = true
|
|
}
|
|
}
|
|
if !exists {
|
|
return errors.ThrowPreconditionFailed(nil, "EVENT-Djlo9", "Errors.IAM.IdpNotExisting")
|
|
}
|
|
for _, p := range idps {
|
|
if p.IDPConfigID == idpConfigID {
|
|
return errors.ThrowPreconditionFailed(nil, "EVENT-us5Zw", "Errors.IAM.LoginPolicy.IdpProviderAlreadyExisting")
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|