mirror of
https://github.com/zitadel/zitadel.git
synced 2025-02-28 20:37:23 +00:00
fix(query): pw complexity policy (#2417)
* job queue * wg improvements * start handler * statement * statements * imporve handler * improve statement * statement in seperate file * move handlers * move query/old to query * handler * read models * bulk works * cleanup * contrib * rename readmodel to projection * rename read_models schema to projections * rename read_models schema to projections * search query as func, bulk iterates as long as new events * add event sequence less query * update checks for events between current sequence and sequence of first statement if it has previous sequence 0 * cleanup crdb projection * refactor projection handler * start with testing * tests for handler * remove todo * refactor statement: remove table name, add tests * improve projection handler shutdown, no savepoint if noop stmt, tests for stmt handler * tests * start failed events * seperate branch for contrib * move statement constructors to crdb pkg * correct import * Subscribe for eventtypes (#1800) * fix: is default (#1737) * fix: use email as username on global org (#1738) * fix: use email as username on global org * Update user_human.go * Update register_handler.go * chore(deps): update docusaurus (#1739) * chore: remove PAT and use GH Token (#1716) * chore: remove PAT and use GH Token * fix env * fix env * fix env * md lint * trigger ci * change user * fix GH bug * replace login part * chore: add GH Token to sem rel (#1746) * chore: add GH Token to sem rel * try branch * add GH Token * remove test branch again * docs: changes acme to acme-caos (#1744) * changes acme to acme-caos * Apply suggestions from code review Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: Maximilian Panne <maximilian.panne@gmail.com> Co-authored-by: Florian Forster <florian@caos.ch> * feat: add additional origins on applications (#1691) * feat: add additional origins on applications * app additional redirects * chore(deps-dev): bump @angular/cli from 11.2.8 to 11.2.11 in /console (#1706) * fix: show org with regex (#1688) * fix: flag mapping (#1699) * chore(deps-dev): bump @angular/cli from 11.2.8 to 11.2.11 in /console Bumps [@angular/cli](https://github.com/angular/angular-cli) from 11.2.8 to 11.2.11. - [Release notes](https://github.com/angular/angular-cli/releases) - [Commits](https://github.com/angular/angular-cli/compare/v11.2.8...v11.2.11) Signed-off-by: dependabot[bot] <support@github.com> 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> * chore(deps-dev): bump stylelint from 13.10.0 to 13.13.1 in /console (#1703) * fix: show org with regex (#1688) * fix: flag mapping (#1699) * chore(deps-dev): bump stylelint from 13.10.0 to 13.13.1 in /console Bumps [stylelint](https://github.com/stylelint/stylelint) from 13.10.0 to 13.13.1. - [Release notes](https://github.com/stylelint/stylelint/releases) - [Changelog](https://github.com/stylelint/stylelint/blob/master/CHANGELOG.md) - [Commits](https://github.com/stylelint/stylelint/compare/13.10.0...13.13.1) Signed-off-by: dependabot[bot] <support@github.com> 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> * chore(deps-dev): bump @types/node from 14.14.37 to 15.0.1 in /console (#1702) * fix: show org with regex (#1688) * fix: flag mapping (#1699) * chore(deps-dev): bump @types/node from 14.14.37 to 15.0.1 in /console Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.37 to 15.0.1. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot[bot] <support@github.com> 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> * chore(deps): bump ts-protoc-gen from 0.14.0 to 0.15.0 in /console (#1701) * fix: show org with regex (#1688) * fix: flag mapping (#1699) * chore(deps): bump ts-protoc-gen from 0.14.0 to 0.15.0 in /console Bumps [ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) from 0.14.0 to 0.15.0. - [Release notes](https://github.com/improbable-eng/ts-protoc-gen/releases) - [Changelog](https://github.com/improbable-eng/ts-protoc-gen/blob/master/CHANGELOG.md) - [Commits](https://github.com/improbable-eng/ts-protoc-gen/compare/0.14.0...0.15.0) Signed-off-by: dependabot[bot] <support@github.com> 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> * chore(deps-dev): bump @types/jasmine from 3.6.9 to 3.6.10 in /console (#1682) Bumps [@types/jasmine](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jasmine) from 3.6.9 to 3.6.10. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jasmine) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump @types/google-protobuf in /console (#1681) Bumps [@types/google-protobuf](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/google-protobuf) from 3.7.4 to 3.15.2. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/google-protobuf) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump grpc from 1.24.5 to 1.24.7 in /console (#1666) Bumps [grpc](https://github.com/grpc/grpc-node) from 1.24.5 to 1.24.7. - [Release notes](https://github.com/grpc/grpc-node/releases) - [Commits](https://github.com/grpc/grpc-node/compare/grpc@1.24.5...grpc@1.24.7) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * lock * chore(deps-dev): bump @angular/language-service from 11.2.9 to 11.2.12 in /console (#1704) * fix: show org with regex (#1688) * fix: flag mapping (#1699) * chore(deps-dev): bump @angular/language-service in /console Bumps [@angular/language-service](https://github.com/angular/angular/tree/HEAD/packages/language-service) from 11.2.9 to 11.2.12. - [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/11.2.12/packages/language-service) Signed-off-by: dependabot[bot] <support@github.com> 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> * package lock * downgrade grpc * downgrade protobuf types * revert npm packs 🥸 Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Silvan <silvan.reusser@gmail.com> * docs: update run and start section texts (#1745) * update run and start section texts * adds showcase Co-authored-by: Maximilian Panne <maximilian.panne@gmail.com> * fix: additional origin list (#1753) * fix: handle api configs in authz handler (#1755) * fix(console): add model for api keys, fix toast, binding (#1757) * fix: add model for api keys, fix toast, binding * show api clientid * fix: missing patchvalue (#1758) * feat: refresh token (#1728) * begin refresh tokens * refresh tokens * list and revoke refresh tokens * handle remove * tests for refresh tokens * uniqueness and default expiration * rename oidc token methods * cleanup * migration version * Update internal/static/i18n/en.yaml Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * fixes * feat: update oidc pkg for refresh tokens Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * fix: correct json name of clientId in key.json (#1760) * fix: migration version (#1767) * start subscription * eventtypes * fix(login): links (#1778) * fix(login): href for help * fix(login): correct link to tos * fix: access tokens for service users and refresh token infos (#1779) * fix: access token for service user * handle info from refresh request * uniqueness * postpone access token uniqueness change * chore(coc): recommend code of conduct (#1782) * subscribe for events * feat(console): refresh toggle out of granttype context (#1785) * refresh toggle * disable if not code flow, lint * lint * fix: change oidc config order * accept refresh option within flow Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: refresh token activation (#1795) * fix: oidc grant type check * docs: add offline_access scope * docs: update refresh token status in supported grant types * fix: update oidc pkg * fix: check refresh token grant type (#1796) * configuration structs * org admins * failed events * fixes Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: mffap <mpa@caos.ch> Co-authored-by: Maximilian Panne <maximilian.panne@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> * remove comment * aggregate reducer * remove eventtypes * add protoc-get-validate to mod * fix transaltion * upsert * add gender on org admins, allow to retry failed stmts after configurable time * remove if * sub queries * fix: tests * add builder to tests * new search query * rename searchquerybuilder to builder * remove comment from code * test with multiple queries * add filters test * current sequences * make org and org_admins work again * add aggregate type to current sequence * fix(contibute): listing * add validate module * fix: search queries * feat(eventstore): previous aggregate root sequence (#1810) * feat(eventstore): previous aggregate root sequence * fix tests * fix: eventstore v1 test * add col to all mocked rows * next try * fix mig * rename aggregate root to aggregate type * update comment Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Livio Amstutz <livio.a@gmail.com> * small refactorings * allow update multiple current sequences * unique log id * fix migrations * rename org admin to org owner * improve error handling and logging * fix(migration): optimize prev agg root seq * fix: projection handler test * fix: sub queries * small fixes * additional event types * correct org owner projection * fix primary key * feat(eventstore): jobs for projections (#2026) * fix: template names in login (#1974) * fix: template names in login * fix: error.html * fix: check for features on mgmt only (#1976) * fix: add sentry in ui, http and projection handlers (#1977) * fix: add sentry in ui, http and projection handlers * fix test * fix(eventstore): sub queries (#1805) * sub queries * fix: tests * add builder to tests * new search query * rename searchquerybuilder to builder * remove comment from code * test with multiple queries * add filters test * fix(contibute): listing * add validate module * fix: search queries * remove unused event type in query * ignore query if error in marshal * go mod tidy * update privacy policy query * update queries Co-authored-by: Livio Amstutz <livio.a@gmail.com> * feat: Extend oidc idp with oauth endpoints (#1980) * feat: add oauth attributes to oidc idp configuration * feat: return idpconfig id on create idp * feat: tests * feat: descriptions * feat: docs * feat: tests * docs: update to beta 3 (#1984) * fix: role assertion (#1986) * fix: enum to display access token role assertion * improve assertion descriptions * fix nil pointer * docs: eventstore (#1982) * docs: eventstore * Apply suggestions from code review Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: Florian Forster <florian@caos.ch> * fix(sentry): trigger sentry release (#1989) * feat(send sentry release): send sentry release * fix(moved step and added releasetag): moved step and added releasetag * fix: set version for sentry release (#1990) * feat(send sentry release): send sentry release * fix(moved step and added releasetag): moved step and added releasetag * fix(corrected var name): corrected var name Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: log error reason on terminate session (#1973) * fix: return default language file, if requested lang does not exist for default login texts (#1988) * fix: return default language file, if requested lang doesnt exists * feat: read default translation file * feat: docs * fix: race condition in auth request unmarshalling (#1993) * feat: handle ui_locales in login (#1994) * fix: handle ui_locales in login * move supportedlanguage func into i18n package * update oidc pkg * fix: handle closed channels on unsubscribe (#1995) * fix: give restore more time (#1997) * fix: translation file read (#2009) * feat: translation file read * feat: readme * fix: enable idp add button for iam users (#2010) * fix: filter event_data (#2011) * feat: Custom message files (#1992) * feat: add get custom message text to admin api * feat: read custom message texts from files * feat: get languages in apis * feat: get languages in apis * feat: get languages in apis * feat: pr feedback * feat: docs * feat: merge main * fix: sms notification (#2013) * fix: phone verifications * feat: fix password reset as sms * fix: phone verification * fix: grpc status in sentry and validation interceptors (#2012) * fix: remove oauth endpoints from oidc config proto (#2014) * try with view * fix(console): disable sw (#2021) * fix: disable sw * angular.json disable sw * project projections * fix typos * customize projections * customizable projections, add change date to projects Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: mffap <mpa@caos.ch> Co-authored-by: Christian Jakob <47860090+thesephirot@users.noreply.github.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com> * env file * typo * correct users * correct migration * fix: merge fail * fix test * fix(tests): unordered matcher * improve currentSequenceMatcher * correct certs * correct certs * add zitadel database on database list * refctor switch in match * enable all handlers * Delete io.env * cleanup * add handlers * rename view to projection * rename view to projection * fix type typo * remove unnecessary logs * refactor stmts * simplify interval calculation * fix tests * fix unlock test * fix migration * migs * fix(operator): update cockroach and flyway versions (#2138) * chore(deps): bump k8s.io/apiextensions-apiserver from 0.19.2 to 0.21.3 Bumps [k8s.io/apiextensions-apiserver](https://github.com/kubernetes/apiextensions-apiserver) from 0.19.2 to 0.21.3. - [Release notes](https://github.com/kubernetes/apiextensions-apiserver/releases) - [Commits](https://github.com/kubernetes/apiextensions-apiserver/compare/v0.19.2...v0.21.3) --- updated-dependencies: - dependency-name: k8s.io/apiextensions-apiserver dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump google.golang.org/api from 0.34.0 to 0.52.0 Bumps [google.golang.org/api](https://github.com/googleapis/google-api-go-client) from 0.34.0 to 0.52.0. - [Release notes](https://github.com/googleapis/google-api-go-client/releases) - [Changelog](https://github.com/googleapis/google-api-go-client/blob/master/CHANGES.md) - [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.34.0...v0.52.0) --- updated-dependencies: - dependency-name: google.golang.org/api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * start update dependencies * update mods and otlp * fix(build): update to go 1.16 * old version for k8s mods * update k8s versions * update orbos * fix(operator): update cockroach and flyway version * Update images.go Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Stefan Benz <stefan@caos.ch> * fix import * fix typo * fix(migration): add org projection * fix(projection): correct table for org events in org owners * better insert stmt * fix typo * fix typo * set max connection lifetime * set max conns and conn lifetime in eventstore v1 * configure sql connection settings * add mig for agg type index * fix replace tab in yaml * handler interfaces * subscription * first try * handler * move sql client initialization * first part implemented * removed all occurencies of org by id and search orgs * fix merge issues * cleanup code * fix: queries implements orgviewprovider * cleanup * refactor text comparison * remove unused file * remove unused code * log * remove unused code * remove unused field * remove unused file * refactor * tests for search query * remove try * simplify state change mappers * projection tests * query functions * move reusable objects to separate files * rename domain column to primar_domain * fix tests * add current sequence * remove log prints * fix tests * fix: verifier * fix test * rename domain col migrations * simplify search response * add custom column constructors * fix: org projection table const * fix: full column name * feat: text query extension * fix: tests for query * number query * add deprection message * projection * correct migration * column in a single place (#2416) * column in a single place * use projection for columns * query column with aliases * rename methods * remove unused code * column for current sequences * global counter column * fix is org unique * query * fix wrong code * remove unused code * remove unused code * remove unused code * tests * fix: tests * migrations * fixes * errors * add converter option Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Florian Forster <florian@caos.ch> Co-authored-by: mffap <mpa@caos.ch> Co-authored-by: Maximilian Panne <maximilian.panne@gmail.com> 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: Christian Jakob <47860090+thesephirot@users.noreply.github.com> Co-authored-by: Elio Bischof <eliobischof@gmail.com> Co-authored-by: Stefan Benz <stefan@caos.ch> Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
This commit is contained in:
parent
1aa26e727e
commit
d7c681e4eb
9
go.mod
9
go.mod
@ -15,11 +15,10 @@ require (
|
|||||||
github.com/VictoriaMetrics/fastcache v1.7.0
|
github.com/VictoriaMetrics/fastcache v1.7.0
|
||||||
github.com/ajstarks/svgo v0.0.0-20210406150507-75cfd577ce75
|
github.com/ajstarks/svgo v0.0.0-20210406150507-75cfd577ce75
|
||||||
github.com/allegro/bigcache v1.2.1
|
github.com/allegro/bigcache v1.2.1
|
||||||
github.com/aws/aws-sdk-go-v2 v1.6.0 // indirect
|
github.com/aws/aws-sdk-go-v2 v1.6.0
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.3.0 // indirect
|
github.com/aws/aws-sdk-go-v2/config v1.3.0
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.2.1 // indirect
|
github.com/aws/aws-sdk-go-v2/credentials v1.2.1
|
||||||
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.3.1 // indirect
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.10.0
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.10.0 // indirect
|
|
||||||
github.com/boombuler/barcode v1.0.1
|
github.com/boombuler/barcode v1.0.1
|
||||||
github.com/caos/logging v0.0.2
|
github.com/caos/logging v0.0.2
|
||||||
github.com/caos/oidc v0.15.10
|
github.com/caos/oidc v0.15.10
|
||||||
|
@ -167,32 +167,6 @@ func (repo *IAMRepository) SearchDefaultIDPProviders(ctx context.Context, reques
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *IAMRepository) GetDefaultPasswordComplexityPolicy(ctx context.Context) (*iam_model.PasswordComplexityPolicyView, error) {
|
|
||||||
policy, viewErr := repo.View.PasswordComplexityPolicyByAggregateID(repo.SystemDefaults.IamID)
|
|
||||||
if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
|
|
||||||
return nil, viewErr
|
|
||||||
}
|
|
||||||
if caos_errs.IsNotFound(viewErr) {
|
|
||||||
policy = new(iam_es_model.PasswordComplexityPolicyView)
|
|
||||||
}
|
|
||||||
|
|
||||||
events, esErr := repo.getIAMEvents(ctx, policy.Sequence)
|
|
||||||
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
|
||||||
return nil, caos_errs.ThrowNotFound(nil, "EVENT-1Mc0s", "Errors.IAM.PasswordComplexityPolicy.NotFound")
|
|
||||||
}
|
|
||||||
if esErr != nil {
|
|
||||||
logging.Log("EVENT-3M0xs").WithError(esErr).Debug("error retrieving new events")
|
|
||||||
return iam_es_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
policyCopy := *policy
|
|
||||||
for _, event := range events {
|
|
||||||
if err := policyCopy.AppendEvent(event); err != nil {
|
|
||||||
return iam_es_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return iam_es_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *IAMRepository) GetDefaultPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error) {
|
func (repo *IAMRepository) GetDefaultPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error) {
|
||||||
policy, viewErr := repo.View.PasswordAgePolicyByAggregateID(repo.SystemDefaults.IamID)
|
policy, viewErr := repo.View.PasswordAgePolicyByAggregateID(repo.SystemDefaults.IamID)
|
||||||
if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
|
if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
|
||||||
|
@ -45,8 +45,6 @@ func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es
|
|||||||
newUser(
|
newUser(
|
||||||
handler{view, bulkLimit, configs.cycleDuration("User"), errorCount, es},
|
handler{view, bulkLimit, configs.cycleDuration("User"), errorCount, es},
|
||||||
defaults),
|
defaults),
|
||||||
newPasswordComplexityPolicy(
|
|
||||||
handler{view, bulkLimit, configs.cycleDuration("PasswordComplexityPolicy"), errorCount, es}),
|
|
||||||
newPasswordAgePolicy(
|
newPasswordAgePolicy(
|
||||||
handler{view, bulkLimit, configs.cycleDuration("PasswordAgePolicy"), errorCount, es}),
|
handler{view, bulkLimit, configs.cycleDuration("PasswordAgePolicy"), errorCount, es}),
|
||||||
newLockoutPolicy(
|
newLockoutPolicy(
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/caos/logging"
|
|
||||||
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
|
||||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
||||||
|
|
||||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/query"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/spooler"
|
|
||||||
iam_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
||||||
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
passwordComplexityPolicyTable = "adminapi.password_complexity_policies"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PasswordComplexityPolicy struct {
|
|
||||||
handler
|
|
||||||
subscription *v1.Subscription
|
|
||||||
}
|
|
||||||
|
|
||||||
func newPasswordComplexityPolicy(handler handler) *PasswordComplexityPolicy {
|
|
||||||
h := &PasswordComplexityPolicy{
|
|
||||||
handler: handler,
|
|
||||||
}
|
|
||||||
|
|
||||||
h.subscribe()
|
|
||||||
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) subscribe() {
|
|
||||||
p.subscription = p.es.Subscribe(p.AggregateTypes()...)
|
|
||||||
go func() {
|
|
||||||
for event := range p.subscription.Events {
|
|
||||||
query.ReduceEvent(p, event)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) ViewModel() string {
|
|
||||||
return passwordComplexityPolicyTable
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *PasswordComplexityPolicy) Subscription() *v1.Subscription {
|
|
||||||
return m.subscription
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) AggregateTypes() []es_models.AggregateType {
|
|
||||||
return []es_models.AggregateType{model.OrgAggregate, iam_es_model.IAMAggregate}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) CurrentSequence() (uint64, error) {
|
|
||||||
sequence, err := p.view.GetLatestPasswordComplexityPolicySequence()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return sequence.CurrentSequence, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) EventQuery() (*es_models.SearchQuery, error) {
|
|
||||||
sequence, err := p.view.GetLatestPasswordComplexityPolicySequence()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return es_models.NewSearchQuery().
|
|
||||||
AggregateTypeFilter(p.AggregateTypes()...).
|
|
||||||
LatestSequenceFilter(sequence.CurrentSequence), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) Reduce(event *es_models.Event) (err error) {
|
|
||||||
switch event.AggregateType {
|
|
||||||
case model.OrgAggregate, iam_es_model.IAMAggregate:
|
|
||||||
err = p.processPasswordComplexityPolicy(event)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) processPasswordComplexityPolicy(event *es_models.Event) (err error) {
|
|
||||||
policy := new(iam_model.PasswordComplexityPolicyView)
|
|
||||||
switch event.Type {
|
|
||||||
case iam_es_model.PasswordComplexityPolicyAdded, model.PasswordComplexityPolicyAdded:
|
|
||||||
err = policy.AppendEvent(event)
|
|
||||||
case iam_es_model.PasswordComplexityPolicyChanged, model.PasswordComplexityPolicyChanged:
|
|
||||||
policy, err = p.view.PasswordComplexityPolicyByAggregateID(event.AggregateID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = policy.AppendEvent(event)
|
|
||||||
case model.PasswordComplexityPolicyRemoved:
|
|
||||||
return p.view.DeletePasswordComplexityPolicy(event.AggregateID, event)
|
|
||||||
default:
|
|
||||||
return p.view.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return p.view.PutPasswordComplexityPolicy(policy, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) OnError(event *es_models.Event, err error) error {
|
|
||||||
logging.LogWithFields("SPOOL-Wm8fs", "id", event.AggregateID).WithError(err).Warn("something went wrong in passwordComplexity policy handler")
|
|
||||||
return spooler.HandleError(event, err, p.view.GetLatestPasswordComplexityPolicyFailedEvent, p.view.ProcessedPasswordComplexityPolicyFailedEvent, p.view.ProcessedPasswordComplexityPolicySequence, p.errorCountUntilSkip)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) OnSuccess() error {
|
|
||||||
return spooler.HandleSuccess(p.view.UpdatePasswordComplexityPolicySpoolerRunTimestamp)
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/caos/zitadel/internal/errors"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
||||||
"github.com/caos/zitadel/internal/iam/repository/view"
|
|
||||||
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
||||||
global_view "github.com/caos/zitadel/internal/view/repository"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
passwordComplexityPolicyTable = "adminapi.password_complexity_policies"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (v *View) PasswordComplexityPolicyByAggregateID(aggregateID string) (*model.PasswordComplexityPolicyView, error) {
|
|
||||||
return view.GetPasswordComplexityPolicyByAggregateID(v.Db, passwordComplexityPolicyTable, aggregateID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) PutPasswordComplexityPolicy(policy *model.PasswordComplexityPolicyView, event *models.Event) error {
|
|
||||||
err := view.PutPasswordComplexityPolicy(v.Db, passwordComplexityPolicyTable, policy)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return v.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) DeletePasswordComplexityPolicy(aggregateID string, event *models.Event) error {
|
|
||||||
err := view.DeletePasswordComplexityPolicy(v.Db, passwordComplexityPolicyTable, aggregateID)
|
|
||||||
if err != nil && !errors.IsNotFound(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return v.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) GetLatestPasswordComplexityPolicySequence() (*global_view.CurrentSequence, error) {
|
|
||||||
return v.latestSequence(passwordComplexityPolicyTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) ProcessedPasswordComplexityPolicySequence(event *models.Event) error {
|
|
||||||
return v.saveCurrentSequence(passwordComplexityPolicyTable, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) UpdatePasswordComplexityPolicySpoolerRunTimestamp() error {
|
|
||||||
return v.updateSpoolerRunSequence(passwordComplexityPolicyTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) GetLatestPasswordComplexityPolicyFailedEvent(sequence uint64) (*global_view.FailedEvent, error) {
|
|
||||||
return v.latestFailedEvent(passwordComplexityPolicyTable, sequence)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) ProcessedPasswordComplexityPolicyFailedEvent(failedEvent *global_view.FailedEvent) error {
|
|
||||||
return v.saveFailedEvent(failedEvent)
|
|
||||||
}
|
|
@ -35,8 +35,6 @@ type IAMRepository interface {
|
|||||||
GetDefaultLoginTexts(ctx context.Context, lang string) (*domain.CustomLoginText, error)
|
GetDefaultLoginTexts(ctx context.Context, lang string) (*domain.CustomLoginText, error)
|
||||||
GetCustomLoginTexts(ctx context.Context, lang string) (*domain.CustomLoginText, error)
|
GetCustomLoginTexts(ctx context.Context, lang string) (*domain.CustomLoginText, error)
|
||||||
|
|
||||||
GetDefaultPasswordComplexityPolicy(ctx context.Context) (*iam_model.PasswordComplexityPolicyView, error)
|
|
||||||
|
|
||||||
GetDefaultPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error)
|
GetDefaultPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error)
|
||||||
|
|
||||||
GetDefaultLockoutPolicy(ctx context.Context) (*iam_model.LockoutPolicyView, error)
|
GetDefaultLockoutPolicy(ctx context.Context) (*iam_model.LockoutPolicyView, error)
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) GetPasswordComplexityPolicy(ctx context.Context, _ *admin_pb.GetPasswordComplexityPolicyRequest) (*admin_pb.GetPasswordComplexityPolicyResponse, error) {
|
func (s *Server) GetPasswordComplexityPolicy(ctx context.Context, _ *admin_pb.GetPasswordComplexityPolicyRequest) (*admin_pb.GetPasswordComplexityPolicyResponse, error) {
|
||||||
policy, err := s.iam.GetDefaultPasswordComplexityPolicy(ctx)
|
policy, err := s.query.DefaultPasswordComplexityPolicy(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,13 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/caos/zitadel/internal/api/authz"
|
||||||
policy_grpc "github.com/caos/zitadel/internal/api/grpc/policy"
|
policy_grpc "github.com/caos/zitadel/internal/api/grpc/policy"
|
||||||
auth_pb "github.com/caos/zitadel/pkg/grpc/auth"
|
auth_pb "github.com/caos/zitadel/pkg/grpc/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) GetMyPasswordComplexityPolicy(ctx context.Context, _ *auth_pb.GetMyPasswordComplexityPolicyRequest) (*auth_pb.GetMyPasswordComplexityPolicyResponse, error) {
|
func (s *Server) GetMyPasswordComplexityPolicy(ctx context.Context, _ *auth_pb.GetMyPasswordComplexityPolicyRequest) (*auth_pb.GetMyPasswordComplexityPolicyResponse, error) {
|
||||||
policy, err := s.repo.GetMyPasswordComplexityPolicy(ctx)
|
policy, err := s.query.PasswordComplexityPolicyByOrg(ctx, authz.GetCtxData(ctx).OrgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package management
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/caos/zitadel/internal/api/authz"
|
"github.com/caos/zitadel/internal/api/authz"
|
||||||
"github.com/caos/zitadel/internal/api/grpc/object"
|
"github.com/caos/zitadel/internal/api/grpc/object"
|
||||||
policy_grpc "github.com/caos/zitadel/internal/api/grpc/policy"
|
policy_grpc "github.com/caos/zitadel/internal/api/grpc/policy"
|
||||||
@ -9,15 +10,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) GetPasswordComplexityPolicy(ctx context.Context, req *mgmt_pb.GetPasswordComplexityPolicyRequest) (*mgmt_pb.GetPasswordComplexityPolicyResponse, error) {
|
func (s *Server) GetPasswordComplexityPolicy(ctx context.Context, req *mgmt_pb.GetPasswordComplexityPolicyRequest) (*mgmt_pb.GetPasswordComplexityPolicyResponse, error) {
|
||||||
policy, err := s.org.GetPasswordComplexityPolicy(ctx)
|
policy, err := s.query.PasswordComplexityPolicyByOrg(ctx, authz.GetCtxData(ctx).OrgID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &mgmt_pb.GetPasswordComplexityPolicyResponse{Policy: policy_grpc.ModelPasswordComplexityPolicyToPb(policy), IsDefault: policy.Default}, nil
|
return &mgmt_pb.GetPasswordComplexityPolicyResponse{Policy: policy_grpc.ModelPasswordComplexityPolicyToPb(policy), IsDefault: policy.IsDefault}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GetDefaultPasswordComplexityPolicy(ctx context.Context, req *mgmt_pb.GetDefaultPasswordComplexityPolicyRequest) (*mgmt_pb.GetDefaultPasswordComplexityPolicyResponse, error) {
|
func (s *Server) GetDefaultPasswordComplexityPolicy(ctx context.Context, req *mgmt_pb.GetDefaultPasswordComplexityPolicyRequest) (*mgmt_pb.GetDefaultPasswordComplexityPolicyResponse, error) {
|
||||||
policy, err := s.org.GetDefaultPasswordComplexityPolicy(ctx)
|
policy, err := s.query.DefaultPasswordComplexityPolicy(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,13 @@ package policy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/caos/zitadel/internal/api/grpc/object"
|
"github.com/caos/zitadel/internal/api/grpc/object"
|
||||||
"github.com/caos/zitadel/internal/iam/model"
|
"github.com/caos/zitadel/internal/query"
|
||||||
policy_pb "github.com/caos/zitadel/pkg/grpc/policy"
|
policy_pb "github.com/caos/zitadel/pkg/grpc/policy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ModelPasswordComplexityPolicyToPb(policy *model.PasswordComplexityPolicyView) *policy_pb.PasswordComplexityPolicy {
|
func ModelPasswordComplexityPolicyToPb(policy *query.PasswordComplexityPolicy) *policy_pb.PasswordComplexityPolicy {
|
||||||
return &policy_pb.PasswordComplexityPolicy{
|
return &policy_pb.PasswordComplexityPolicy{
|
||||||
IsDefault: policy.Default,
|
IsDefault: policy.IsDefault,
|
||||||
MinLength: policy.MinLength,
|
MinLength: policy.MinLength,
|
||||||
HasUppercase: policy.HasUppercase,
|
HasUppercase: policy.HasUppercase,
|
||||||
HasLowercase: policy.HasLowercase,
|
HasLowercase: policy.HasLowercase,
|
||||||
@ -18,7 +18,7 @@ func ModelPasswordComplexityPolicyToPb(policy *model.PasswordComplexityPolicyVie
|
|||||||
policy.Sequence,
|
policy.Sequence,
|
||||||
policy.CreationDate,
|
policy.CreationDate,
|
||||||
policy.ChangeDate,
|
policy.ChangeDate,
|
||||||
"", //TODO: ro
|
policy.ResourceOwner,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||||
iam_view_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
iam_view_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||||
|
"github.com/caos/zitadel/internal/query"
|
||||||
"github.com/caos/zitadel/internal/repository/iam"
|
"github.com/caos/zitadel/internal/repository/iam"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ type OrgRepository struct {
|
|||||||
Eventstore eventstore.Eventstore
|
Eventstore eventstore.Eventstore
|
||||||
View *auth_view.View
|
View *auth_view.View
|
||||||
SystemDefaults systemdefaults.SystemDefaults
|
SystemDefaults systemdefaults.SystemDefaults
|
||||||
|
Query query.Queries
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *OrgRepository) GetDefaultOrgIAMPolicy(ctx context.Context) (*iam_model.OrgIAMPolicyView, error) {
|
func (repo *OrgRepository) GetDefaultOrgIAMPolicy(ctx context.Context) (*iam_model.OrgIAMPolicyView, error) {
|
||||||
@ -59,14 +61,7 @@ func (repo *OrgRepository) GetIDPConfigByID(ctx context.Context, idpConfigID str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repo *OrgRepository) GetMyPasswordComplexityPolicy(ctx context.Context) (*iam_model.PasswordComplexityPolicyView, error) {
|
func (repo *OrgRepository) GetMyPasswordComplexityPolicy(ctx context.Context) (*iam_model.PasswordComplexityPolicyView, error) {
|
||||||
policy, err := repo.View.PasswordComplexityPolicyByAggregateID(authz.GetCtxData(ctx).OrgID)
|
policy, err := repo.Query.PasswordComplexityPolicyByOrg(ctx, authz.GetCtxData(ctx).OrgID)
|
||||||
if errors.IsNotFound(err) {
|
|
||||||
policy, err = repo.View.PasswordComplexityPolicyByAggregateID(repo.SystemDefaults.IamID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
policy.Default = true
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,6 @@ func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es
|
|||||||
newExternalIDP(
|
newExternalIDP(
|
||||||
handler{view, bulkLimit, configs.cycleDuration("ExternalIDP"), errorCount, es},
|
handler{view, bulkLimit, configs.cycleDuration("ExternalIDP"), errorCount, es},
|
||||||
systemDefaults),
|
systemDefaults),
|
||||||
newPasswordComplexityPolicy(
|
|
||||||
handler{view, bulkLimit, configs.cycleDuration("PasswordComplexityPolicy"), errorCount, es}),
|
|
||||||
newOrgIAMPolicy(
|
newOrgIAMPolicy(
|
||||||
handler{view, bulkLimit, configs.cycleDuration("OrgIAMPolicy"), errorCount, es}),
|
handler{view, bulkLimit, configs.cycleDuration("OrgIAMPolicy"), errorCount, es}),
|
||||||
newProjectRole(handler{view, bulkLimit, configs.cycleDuration("ProjectRole"), errorCount, es}),
|
newProjectRole(handler{view, bulkLimit, configs.cycleDuration("ProjectRole"), errorCount, es}),
|
||||||
|
@ -1,110 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/caos/logging"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
|
||||||
|
|
||||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/query"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/spooler"
|
|
||||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
||||||
iam_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
||||||
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
passwordComplexityPolicyTable = "auth.password_complexity_policies"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PasswordComplexityPolicy struct {
|
|
||||||
handler
|
|
||||||
subscription *v1.Subscription
|
|
||||||
}
|
|
||||||
|
|
||||||
func newPasswordComplexityPolicy(handler handler) *PasswordComplexityPolicy {
|
|
||||||
h := &PasswordComplexityPolicy{
|
|
||||||
handler: handler,
|
|
||||||
}
|
|
||||||
|
|
||||||
h.subscribe()
|
|
||||||
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) subscribe() {
|
|
||||||
p.subscription = p.es.Subscribe(p.AggregateTypes()...)
|
|
||||||
go func() {
|
|
||||||
for event := range p.subscription.Events {
|
|
||||||
query.ReduceEvent(p, event)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) ViewModel() string {
|
|
||||||
return passwordComplexityPolicyTable
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) Subscription() *v1.Subscription {
|
|
||||||
return p.subscription
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_ *PasswordComplexityPolicy) AggregateTypes() []es_models.AggregateType {
|
|
||||||
return []es_models.AggregateType{org_es_model.OrgAggregate, iam_es_model.IAMAggregate}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) CurrentSequence() (uint64, error) {
|
|
||||||
sequence, err := p.view.GetLatestPasswordComplexityPolicySequence()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return sequence.CurrentSequence, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) EventQuery() (*es_models.SearchQuery, error) {
|
|
||||||
sequence, err := p.view.GetLatestPasswordComplexityPolicySequence()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return es_models.NewSearchQuery().
|
|
||||||
AggregateTypeFilter(p.AggregateTypes()...).
|
|
||||||
LatestSequenceFilter(sequence.CurrentSequence), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) Reduce(event *es_models.Event) (err error) {
|
|
||||||
switch event.AggregateType {
|
|
||||||
case org_es_model.OrgAggregate, iam_es_model.IAMAggregate:
|
|
||||||
err = p.processPasswordComplexityPolicy(event)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) processPasswordComplexityPolicy(event *es_models.Event) (err error) {
|
|
||||||
policy := new(iam_model.PasswordComplexityPolicyView)
|
|
||||||
switch event.Type {
|
|
||||||
case iam_es_model.PasswordComplexityPolicyAdded, org_es_model.PasswordComplexityPolicyAdded:
|
|
||||||
err = policy.AppendEvent(event)
|
|
||||||
case iam_es_model.PasswordComplexityPolicyChanged, org_es_model.PasswordComplexityPolicyChanged:
|
|
||||||
policy, err = p.view.PasswordComplexityPolicyByAggregateID(event.AggregateID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = policy.AppendEvent(event)
|
|
||||||
case org_es_model.PasswordComplexityPolicyRemoved:
|
|
||||||
return p.view.DeletePasswordComplexityPolicy(event.AggregateID, event)
|
|
||||||
default:
|
|
||||||
return p.view.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return p.view.PutPasswordComplexityPolicy(policy, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) OnError(event *es_models.Event, err error) error {
|
|
||||||
logging.LogWithFields("SPOOL-6M99S", "id", event.AggregateID).WithError(err).Warn("something went wrong in passwordComplexity policy handler")
|
|
||||||
return spooler.HandleError(event, err, p.view.GetLatestPasswordComplexityPolicyFailedEvent, p.view.ProcessedPasswordComplexityPolicyFailedEvent, p.view.ProcessedPasswordComplexityPolicySequence, p.errorCountUntilSkip)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) OnSuccess() error {
|
|
||||||
return spooler.HandleSuccess(p.view.UpdatePasswordComplexityPolicySpoolerRunTimestamp)
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/caos/zitadel/internal/errors"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
||||||
"github.com/caos/zitadel/internal/iam/repository/view"
|
|
||||||
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
||||||
global_view "github.com/caos/zitadel/internal/view/repository"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
passwordComplexityPolicyTable = "auth.password_complexity_policies"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (v *View) PasswordComplexityPolicyByAggregateID(aggregateID string) (*model.PasswordComplexityPolicyView, error) {
|
|
||||||
return view.GetPasswordComplexityPolicyByAggregateID(v.Db, passwordComplexityPolicyTable, aggregateID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) PutPasswordComplexityPolicy(policy *model.PasswordComplexityPolicyView, event *models.Event) error {
|
|
||||||
err := view.PutPasswordComplexityPolicy(v.Db, passwordComplexityPolicyTable, policy)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return v.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) DeletePasswordComplexityPolicy(aggregateID string, event *models.Event) error {
|
|
||||||
err := view.DeletePasswordComplexityPolicy(v.Db, passwordComplexityPolicyTable, aggregateID)
|
|
||||||
if err != nil && !errors.IsNotFound(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return v.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) GetLatestPasswordComplexityPolicySequence() (*global_view.CurrentSequence, error) {
|
|
||||||
return v.latestSequence(passwordComplexityPolicyTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) ProcessedPasswordComplexityPolicySequence(event *models.Event) error {
|
|
||||||
return v.saveCurrentSequence(passwordComplexityPolicyTable, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) UpdatePasswordComplexityPolicySpoolerRunTimestamp() error {
|
|
||||||
return v.updateSpoolerRunSequence(passwordComplexityPolicyTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) GetLatestPasswordComplexityPolicyFailedEvent(sequence uint64) (*global_view.FailedEvent, error) {
|
|
||||||
return v.latestFailedEvent(passwordComplexityPolicyTable, sequence)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) ProcessedPasswordComplexityPolicyFailedEvent(failedEvent *global_view.FailedEvent) error {
|
|
||||||
return v.saveFailedEvent(failedEvent)
|
|
||||||
}
|
|
@ -1,9 +1,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/caos/zitadel/internal/domain"
|
|
||||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/caos/zitadel/internal/domain"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PasswordComplexityPolicyView struct {
|
type PasswordComplexityPolicyView struct {
|
||||||
@ -49,26 +49,3 @@ type PasswordComplexityPolicySearchResponse struct {
|
|||||||
Sequence uint64
|
Sequence uint64
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicyView) Check(password string) error {
|
|
||||||
if p.MinLength != 0 && uint64(len(password)) < p.MinLength {
|
|
||||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-HuJf6", "Errors.User.PasswordComplexityPolicy.MinLength")
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.HasLowercase && !hasStringLowerCase(password) {
|
|
||||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-co3Xw", "Errors.User.PasswordComplexityPolicy.HasLower")
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.HasUppercase && !hasStringUpperCase(password) {
|
|
||||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-VoaRj", "Errors.User.PasswordComplexityPolicy.HasUpper")
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.HasNumber && !hasNumber(password) {
|
|
||||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-ZBv4H", "Errors.User.PasswordComplexityPolicy.HasNumber")
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.HasSymbol && !hasSymbol(password) {
|
|
||||||
return caos_errs.ThrowInvalidArgument(nil, "MODEL-ZDLwA", "Errors.User.PasswordComplexityPolicy.HasSymbol")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -1,197 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCheckPasswordComplexityPolicy(t *testing.T) {
|
|
||||||
type args struct {
|
|
||||||
policy *PasswordComplexityPolicyView
|
|
||||||
password string
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
hasError bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "has minlength ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: false,
|
|
||||||
HasUppercase: false,
|
|
||||||
HasSymbol: false,
|
|
||||||
HasNumber: false,
|
|
||||||
MinLength: 10,
|
|
||||||
},
|
|
||||||
password: "password12",
|
|
||||||
},
|
|
||||||
hasError: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has minlength not ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: false,
|
|
||||||
HasUppercase: false,
|
|
||||||
HasSymbol: false,
|
|
||||||
HasNumber: false,
|
|
||||||
MinLength: 10,
|
|
||||||
},
|
|
||||||
password: "password",
|
|
||||||
},
|
|
||||||
hasError: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has lowercase ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: true,
|
|
||||||
HasUppercase: false,
|
|
||||||
HasSymbol: false,
|
|
||||||
HasNumber: false,
|
|
||||||
MinLength: 0,
|
|
||||||
},
|
|
||||||
password: "password",
|
|
||||||
},
|
|
||||||
hasError: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has lowercase not ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: true,
|
|
||||||
HasUppercase: false,
|
|
||||||
HasSymbol: false,
|
|
||||||
HasNumber: false,
|
|
||||||
MinLength: 0,
|
|
||||||
},
|
|
||||||
password: "PASSWORD",
|
|
||||||
},
|
|
||||||
hasError: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has uppercase ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: false,
|
|
||||||
HasUppercase: true,
|
|
||||||
HasSymbol: false,
|
|
||||||
HasNumber: false,
|
|
||||||
MinLength: 0,
|
|
||||||
},
|
|
||||||
password: "PASSWORD",
|
|
||||||
},
|
|
||||||
hasError: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has uppercase not ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: false,
|
|
||||||
HasUppercase: true,
|
|
||||||
HasSymbol: false,
|
|
||||||
HasNumber: false,
|
|
||||||
MinLength: 0,
|
|
||||||
},
|
|
||||||
password: "password",
|
|
||||||
},
|
|
||||||
hasError: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has symbol ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: false,
|
|
||||||
HasUppercase: false,
|
|
||||||
HasSymbol: true,
|
|
||||||
HasNumber: false,
|
|
||||||
MinLength: 0,
|
|
||||||
},
|
|
||||||
password: "!G$",
|
|
||||||
},
|
|
||||||
hasError: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has symbol not ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: false,
|
|
||||||
HasUppercase: false,
|
|
||||||
HasSymbol: true,
|
|
||||||
HasNumber: false,
|
|
||||||
MinLength: 0,
|
|
||||||
},
|
|
||||||
password: "PASSWORD",
|
|
||||||
},
|
|
||||||
hasError: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has number ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: false,
|
|
||||||
HasUppercase: false,
|
|
||||||
HasSymbol: false,
|
|
||||||
HasNumber: true,
|
|
||||||
MinLength: 0,
|
|
||||||
},
|
|
||||||
password: "123456",
|
|
||||||
},
|
|
||||||
hasError: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has number not ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: false,
|
|
||||||
HasUppercase: false,
|
|
||||||
HasSymbol: false,
|
|
||||||
HasNumber: true,
|
|
||||||
MinLength: 0,
|
|
||||||
},
|
|
||||||
password: "PASSWORD",
|
|
||||||
},
|
|
||||||
hasError: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has everything ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: true,
|
|
||||||
HasUppercase: true,
|
|
||||||
HasSymbol: true,
|
|
||||||
HasNumber: true,
|
|
||||||
MinLength: 10,
|
|
||||||
},
|
|
||||||
password: "Password1!",
|
|
||||||
},
|
|
||||||
hasError: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "has everything not ok",
|
|
||||||
args: args{
|
|
||||||
policy: &PasswordComplexityPolicyView{
|
|
||||||
HasLowercase: true,
|
|
||||||
HasUppercase: true,
|
|
||||||
HasSymbol: true,
|
|
||||||
HasNumber: true,
|
|
||||||
MinLength: 10,
|
|
||||||
},
|
|
||||||
password: "password",
|
|
||||||
},
|
|
||||||
hasError: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
err := tt.args.policy.Check(tt.args.password)
|
|
||||||
if !tt.hasError && err != nil {
|
|
||||||
t.Errorf("should not get err: %v", err)
|
|
||||||
}
|
|
||||||
if tt.hasError && err == nil {
|
|
||||||
t.Errorf("should have error: %v", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -19,18 +19,6 @@ type PasswordComplexityPolicy struct {
|
|||||||
HasSymbol bool `json:"hasSymbol"`
|
HasSymbol bool `json:"hasSymbol"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func PasswordComplexityPolicyFromModel(policy *iam_model.PasswordComplexityPolicy) *PasswordComplexityPolicy {
|
|
||||||
return &PasswordComplexityPolicy{
|
|
||||||
ObjectRoot: policy.ObjectRoot,
|
|
||||||
State: int32(policy.State),
|
|
||||||
MinLength: policy.MinLength,
|
|
||||||
HasLowercase: policy.HasLowercase,
|
|
||||||
HasUppercase: policy.HasUppercase,
|
|
||||||
HasNumber: policy.HasNumber,
|
|
||||||
HasSymbol: policy.HasSymbol,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func PasswordComplexityPolicyToModel(policy *PasswordComplexityPolicy) *iam_model.PasswordComplexityPolicy {
|
func PasswordComplexityPolicyToModel(policy *PasswordComplexityPolicy) *iam_model.PasswordComplexityPolicy {
|
||||||
return &iam_model.PasswordComplexityPolicy{
|
return &iam_model.PasswordComplexityPolicy{
|
||||||
ObjectRoot: policy.ObjectRoot,
|
ObjectRoot: policy.ObjectRoot,
|
||||||
@ -43,27 +31,6 @@ func PasswordComplexityPolicyToModel(policy *PasswordComplexityPolicy) *iam_mode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) Changes(changed *PasswordComplexityPolicy) map[string]interface{} {
|
|
||||||
changes := make(map[string]interface{}, 1)
|
|
||||||
|
|
||||||
if p.MinLength != changed.MinLength {
|
|
||||||
changes["minLength"] = changed.MinLength
|
|
||||||
}
|
|
||||||
if p.HasLowercase != changed.HasLowercase {
|
|
||||||
changes["hasLowercase"] = changed.HasLowercase
|
|
||||||
}
|
|
||||||
if p.HasUppercase != changed.HasUppercase {
|
|
||||||
changes["hasUppercase"] = changed.HasUppercase
|
|
||||||
}
|
|
||||||
if p.HasNumber != changed.HasNumber {
|
|
||||||
changes["hasNumber"] = changed.HasNumber
|
|
||||||
}
|
|
||||||
if p.HasSymbol != changed.HasSymbol {
|
|
||||||
changes["hasSymbol"] = changed.HasSymbol
|
|
||||||
}
|
|
||||||
return changes
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *IAM) appendAddPasswordComplexityPolicyEvent(event *es_models.Event) error {
|
func (i *IAM) appendAddPasswordComplexityPolicyEvent(event *es_models.Event) error {
|
||||||
i.DefaultPasswordComplexityPolicy = new(PasswordComplexityPolicy)
|
i.DefaultPasswordComplexityPolicy = new(PasswordComplexityPolicy)
|
||||||
err := i.DefaultPasswordComplexityPolicy.SetData(event)
|
err := i.DefaultPasswordComplexityPolicy.SetData(event)
|
||||||
|
@ -2,53 +2,10 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
|
||||||
|
|
||||||
func TestPasswordComplexityPolicyChanges(t *testing.T) {
|
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||||
type args struct {
|
)
|
||||||
existing *PasswordComplexityPolicy
|
|
||||||
new *PasswordComplexityPolicy
|
|
||||||
}
|
|
||||||
type res struct {
|
|
||||||
changesLen int
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
res res
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "loginpolicy all attributes change",
|
|
||||||
args: args{
|
|
||||||
existing: &PasswordComplexityPolicy{MinLength: 10, HasUppercase: true, HasLowercase: true, HasNumber: true, HasSymbol: true},
|
|
||||||
new: &PasswordComplexityPolicy{MinLength: 5, HasUppercase: false, HasLowercase: false, HasNumber: false, HasSymbol: false},
|
|
||||||
},
|
|
||||||
res: res{
|
|
||||||
changesLen: 5,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "no changes",
|
|
||||||
args: args{
|
|
||||||
existing: &PasswordComplexityPolicy{MinLength: 10, HasUppercase: true, HasLowercase: true, HasNumber: true, HasSymbol: true},
|
|
||||||
new: &PasswordComplexityPolicy{MinLength: 10, HasUppercase: true, HasLowercase: true, HasNumber: true, HasSymbol: true},
|
|
||||||
},
|
|
||||||
res: res{
|
|
||||||
changesLen: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
changes := tt.args.existing.Changes(tt.args.new)
|
|
||||||
if len(changes) != tt.res.changesLen {
|
|
||||||
t.Errorf("got wrong changes len: expected: %v, actual: %v ", tt.res.changesLen, len(changes))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAppendAddPasswordComplexityPolicyEvent(t *testing.T) {
|
func TestAppendAddPasswordComplexityPolicyEvent(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
|
@ -2,9 +2,11 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
org_es_model "github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||||
|
"github.com/caos/zitadel/internal/query"
|
||||||
|
|
||||||
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||||
|
|
||||||
"github.com/caos/logging"
|
"github.com/caos/logging"
|
||||||
@ -33,24 +35,9 @@ type PasswordComplexityPolicyView struct {
|
|||||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func PasswordComplexityViewFromModel(policy *model.PasswordComplexityPolicyView) *PasswordComplexityPolicyView {
|
func PasswordComplexityViewToModel(policy *query.PasswordComplexityPolicy) *model.PasswordComplexityPolicyView {
|
||||||
return &PasswordComplexityPolicyView{
|
|
||||||
AggregateID: policy.AggregateID,
|
|
||||||
Sequence: policy.Sequence,
|
|
||||||
CreationDate: policy.CreationDate,
|
|
||||||
ChangeDate: policy.ChangeDate,
|
|
||||||
MinLength: policy.MinLength,
|
|
||||||
HasLowercase: policy.HasLowercase,
|
|
||||||
HasUppercase: policy.HasUppercase,
|
|
||||||
HasSymbol: policy.HasSymbol,
|
|
||||||
HasNumber: policy.HasNumber,
|
|
||||||
Default: policy.Default,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func PasswordComplexityViewToModel(policy *PasswordComplexityPolicyView) *model.PasswordComplexityPolicyView {
|
|
||||||
return &model.PasswordComplexityPolicyView{
|
return &model.PasswordComplexityPolicyView{
|
||||||
AggregateID: policy.AggregateID,
|
AggregateID: policy.ID,
|
||||||
Sequence: policy.Sequence,
|
Sequence: policy.Sequence,
|
||||||
CreationDate: policy.CreationDate,
|
CreationDate: policy.CreationDate,
|
||||||
ChangeDate: policy.ChangeDate,
|
ChangeDate: policy.ChangeDate,
|
||||||
@ -59,7 +46,7 @@ func PasswordComplexityViewToModel(policy *PasswordComplexityPolicyView) *model.
|
|||||||
HasUppercase: policy.HasUppercase,
|
HasUppercase: policy.HasUppercase,
|
||||||
HasSymbol: policy.HasSymbol,
|
HasSymbol: policy.HasSymbol,
|
||||||
HasNumber: policy.HasNumber,
|
HasNumber: policy.HasNumber,
|
||||||
Default: policy.Default,
|
Default: policy.IsDefault,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/caos/zitadel/internal/domain"
|
|
||||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
||||||
"github.com/caos/zitadel/internal/view/repository"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PasswordComplexityPolicySearchRequest iam_model.PasswordComplexityPolicySearchRequest
|
|
||||||
type PasswordComplexityPolicySearchQuery iam_model.PasswordComplexityPolicySearchQuery
|
|
||||||
type PasswordComplexityPolicySearchKey iam_model.PasswordComplexityPolicySearchKey
|
|
||||||
|
|
||||||
func (req PasswordComplexityPolicySearchRequest) GetLimit() uint64 {
|
|
||||||
return req.Limit
|
|
||||||
}
|
|
||||||
|
|
||||||
func (req PasswordComplexityPolicySearchRequest) GetOffset() uint64 {
|
|
||||||
return req.Offset
|
|
||||||
}
|
|
||||||
|
|
||||||
func (req PasswordComplexityPolicySearchRequest) GetSortingColumn() repository.ColumnKey {
|
|
||||||
if req.SortingColumn == iam_model.PasswordComplexityPolicySearchKeyUnspecified {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return PasswordComplexityPolicySearchKey(req.SortingColumn)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (req PasswordComplexityPolicySearchRequest) GetAsc() bool {
|
|
||||||
return req.Asc
|
|
||||||
}
|
|
||||||
|
|
||||||
func (req PasswordComplexityPolicySearchRequest) GetQueries() []repository.SearchQuery {
|
|
||||||
result := make([]repository.SearchQuery, len(req.Queries))
|
|
||||||
for i, q := range req.Queries {
|
|
||||||
result[i] = PasswordComplexityPolicySearchQuery{Key: q.Key, Value: q.Value, Method: q.Method}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func (req PasswordComplexityPolicySearchQuery) GetKey() repository.ColumnKey {
|
|
||||||
return PasswordComplexityPolicySearchKey(req.Key)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (req PasswordComplexityPolicySearchQuery) GetMethod() domain.SearchMethod {
|
|
||||||
return req.Method
|
|
||||||
}
|
|
||||||
|
|
||||||
func (req PasswordComplexityPolicySearchQuery) GetValue() interface{} {
|
|
||||||
return req.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (key PasswordComplexityPolicySearchKey) ToColumnName() string {
|
|
||||||
switch iam_model.PasswordComplexityPolicySearchKey(key) {
|
|
||||||
case iam_model.PasswordComplexityPolicySearchKeyAggregateID:
|
|
||||||
return PasswordComplexityKeyAggregateID
|
|
||||||
default:
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/caos/zitadel/internal/domain"
|
|
||||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
||||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
||||||
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
||||||
"github.com/caos/zitadel/internal/view/repository"
|
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetPasswordComplexityPolicyByAggregateID(db *gorm.DB, table, aggregateID string) (*model.PasswordComplexityPolicyView, error) {
|
|
||||||
policy := new(model.PasswordComplexityPolicyView)
|
|
||||||
aggregateIDQuery := &model.PasswordComplexityPolicySearchQuery{Key: iam_model.PasswordComplexityPolicySearchKeyAggregateID, Value: aggregateID, Method: domain.SearchMethodEquals}
|
|
||||||
query := repository.PrepareGetByQuery(table, aggregateIDQuery)
|
|
||||||
err := query(db, policy)
|
|
||||||
if caos_errs.IsNotFound(err) {
|
|
||||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-2N9fs", "Errors.IAM.PasswordComplexityPolicy.NotExisting")
|
|
||||||
}
|
|
||||||
return policy, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func PutPasswordComplexityPolicy(db *gorm.DB, table string, policy *model.PasswordComplexityPolicyView) error {
|
|
||||||
save := repository.PrepareSave(table)
|
|
||||||
return save(db, policy)
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeletePasswordComplexityPolicy(db *gorm.DB, table, aggregateID string) error {
|
|
||||||
delete := repository.PrepareDeleteByKey(table, model.PasswordComplexityPolicySearchKey(iam_model.PasswordComplexityPolicySearchKeyAggregateID), aggregateID)
|
|
||||||
|
|
||||||
return delete(db)
|
|
||||||
}
|
|
@ -285,57 +285,6 @@ func (repo *OrgRepository) SearchIDPProviders(ctx context.Context, request *iam_
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *OrgRepository) GetPasswordComplexityPolicy(ctx context.Context) (*iam_model.PasswordComplexityPolicyView, error) {
|
|
||||||
policy, viewErr := repo.View.PasswordComplexityPolicyByAggregateID(authz.GetCtxData(ctx).OrgID)
|
|
||||||
if viewErr != nil && !errors.IsNotFound(viewErr) {
|
|
||||||
return nil, viewErr
|
|
||||||
}
|
|
||||||
if errors.IsNotFound(viewErr) {
|
|
||||||
policy = new(iam_view_model.PasswordComplexityPolicyView)
|
|
||||||
}
|
|
||||||
events, esErr := repo.getOrgEvents(ctx, repo.SystemDefaults.IamID, policy.Sequence)
|
|
||||||
if errors.IsNotFound(viewErr) && len(events) == 0 {
|
|
||||||
return repo.GetDefaultPasswordComplexityPolicy(ctx)
|
|
||||||
}
|
|
||||||
if esErr != nil {
|
|
||||||
logging.Log("EVENT-1Bx8s").WithError(esErr).Debug("error retrieving new events")
|
|
||||||
return iam_view_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
policyCopy := *policy
|
|
||||||
for _, event := range events {
|
|
||||||
if err := policyCopy.AppendEvent(event); err != nil {
|
|
||||||
return iam_view_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return iam_view_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *OrgRepository) GetDefaultPasswordComplexityPolicy(ctx context.Context) (*iam_model.PasswordComplexityPolicyView, error) {
|
|
||||||
policy, viewErr := repo.View.PasswordComplexityPolicyByAggregateID(repo.SystemDefaults.IamID)
|
|
||||||
if viewErr != nil && !errors.IsNotFound(viewErr) {
|
|
||||||
return nil, viewErr
|
|
||||||
}
|
|
||||||
if errors.IsNotFound(viewErr) {
|
|
||||||
policy = new(iam_view_model.PasswordComplexityPolicyView)
|
|
||||||
}
|
|
||||||
events, esErr := repo.getIAMEvents(ctx, policy.Sequence)
|
|
||||||
if errors.IsNotFound(viewErr) && len(events) == 0 {
|
|
||||||
return nil, errors.ThrowNotFound(nil, "EVENT-cmO9s", "Errors.IAM.PasswordComplexityPolicy.NotFound")
|
|
||||||
}
|
|
||||||
if esErr != nil {
|
|
||||||
logging.Log("EVENT-pL9sw").WithError(esErr).Debug("error retrieving new events")
|
|
||||||
return iam_view_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
policyCopy := *policy
|
|
||||||
for _, event := range events {
|
|
||||||
if err := policyCopy.AppendEvent(event); err != nil {
|
|
||||||
return iam_view_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
policy.Default = true
|
|
||||||
return iam_view_model.PasswordComplexityViewToModel(policy), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *OrgRepository) GetPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error) {
|
func (repo *OrgRepository) GetPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error) {
|
||||||
policy, viewErr := repo.View.PasswordAgePolicyByAggregateID(authz.GetCtxData(ctx).OrgID)
|
policy, viewErr := repo.View.PasswordAgePolicyByAggregateID(authz.GetCtxData(ctx).OrgID)
|
||||||
if viewErr != nil && !errors.IsNotFound(viewErr) {
|
if viewErr != nil && !errors.IsNotFound(viewErr) {
|
||||||
|
@ -57,8 +57,6 @@ func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es
|
|||||||
newExternalIDP(
|
newExternalIDP(
|
||||||
handler{view, bulkLimit, configs.cycleDuration("ExternalIDP"), errorCount, es},
|
handler{view, bulkLimit, configs.cycleDuration("ExternalIDP"), errorCount, es},
|
||||||
defaults),
|
defaults),
|
||||||
newPasswordComplexityPolicy(
|
|
||||||
handler{view, bulkLimit, configs.cycleDuration("PasswordComplexityPolicy"), errorCount, es}),
|
|
||||||
newPasswordAgePolicy(
|
newPasswordAgePolicy(
|
||||||
handler{view, bulkLimit, configs.cycleDuration("PasswordAgePolicy"), errorCount, es}),
|
handler{view, bulkLimit, configs.cycleDuration("PasswordAgePolicy"), errorCount, es}),
|
||||||
newLockoutPolicy(
|
newLockoutPolicy(
|
||||||
|
@ -1,109 +0,0 @@
|
|||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/caos/logging"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
|
||||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/query"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/spooler"
|
|
||||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
|
||||||
iam_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
||||||
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
passwordComplexityPolicyTable = "management.password_complexity_policies"
|
|
||||||
)
|
|
||||||
|
|
||||||
type PasswordComplexityPolicy struct {
|
|
||||||
handler
|
|
||||||
subscription *v1.Subscription
|
|
||||||
}
|
|
||||||
|
|
||||||
func newPasswordComplexityPolicy(handler handler) *PasswordComplexityPolicy {
|
|
||||||
h := &PasswordComplexityPolicy{
|
|
||||||
handler: handler,
|
|
||||||
}
|
|
||||||
|
|
||||||
h.subscribe()
|
|
||||||
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *PasswordComplexityPolicy) subscribe() {
|
|
||||||
m.subscription = m.es.Subscribe(m.AggregateTypes()...)
|
|
||||||
go func() {
|
|
||||||
for event := range m.subscription.Events {
|
|
||||||
query.ReduceEvent(m, event)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) ViewModel() string {
|
|
||||||
return passwordComplexityPolicyTable
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) Subscription() *v1.Subscription {
|
|
||||||
return p.subscription
|
|
||||||
}
|
|
||||||
|
|
||||||
func (_ *PasswordComplexityPolicy) AggregateTypes() []es_models.AggregateType {
|
|
||||||
return []es_models.AggregateType{model.OrgAggregate, iam_es_model.IAMAggregate}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) CurrentSequence() (uint64, error) {
|
|
||||||
sequence, err := p.view.GetLatestPasswordComplexityPolicySequence()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return sequence.CurrentSequence, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) EventQuery() (*es_models.SearchQuery, error) {
|
|
||||||
sequence, err := p.view.GetLatestPasswordComplexityPolicySequence()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return es_models.NewSearchQuery().
|
|
||||||
AggregateTypeFilter(p.AggregateTypes()...).
|
|
||||||
LatestSequenceFilter(sequence.CurrentSequence), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) Reduce(event *es_models.Event) (err error) {
|
|
||||||
switch event.AggregateType {
|
|
||||||
case model.OrgAggregate, iam_es_model.IAMAggregate:
|
|
||||||
err = p.processPasswordComplexityPolicy(event)
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) processPasswordComplexityPolicy(event *es_models.Event) (err error) {
|
|
||||||
policy := new(iam_model.PasswordComplexityPolicyView)
|
|
||||||
switch event.Type {
|
|
||||||
case iam_es_model.PasswordComplexityPolicyAdded, model.PasswordComplexityPolicyAdded:
|
|
||||||
err = policy.AppendEvent(event)
|
|
||||||
case iam_es_model.PasswordComplexityPolicyChanged, model.PasswordComplexityPolicyChanged:
|
|
||||||
policy, err = p.view.PasswordComplexityPolicyByAggregateID(event.AggregateID)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = policy.AppendEvent(event)
|
|
||||||
case model.PasswordComplexityPolicyRemoved:
|
|
||||||
return p.view.DeletePasswordComplexityPolicy(event.AggregateID, event)
|
|
||||||
default:
|
|
||||||
return p.view.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return p.view.PutPasswordComplexityPolicy(policy, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) OnError(event *es_models.Event, err error) error {
|
|
||||||
logging.LogWithFields("SPOOL-4Djo9", "id", event.AggregateID).WithError(err).Warn("something went wrong in passwordComplexity policy handler")
|
|
||||||
return spooler.HandleError(event, err, p.view.GetLatestPasswordComplexityPolicyFailedEvent, p.view.ProcessedPasswordComplexityPolicyFailedEvent, p.view.ProcessedPasswordComplexityPolicySequence, p.errorCountUntilSkip)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *PasswordComplexityPolicy) OnSuccess() error {
|
|
||||||
return spooler.HandleSuccess(p.view.UpdatePasswordComplexityPolicySpoolerRunTimestamp)
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
package view
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/caos/zitadel/internal/errors"
|
|
||||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
||||||
"github.com/caos/zitadel/internal/iam/repository/view"
|
|
||||||
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
|
||||||
global_view "github.com/caos/zitadel/internal/view/repository"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
passwordComplexityPolicyTable = "management.password_complexity_policies"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (v *View) PasswordComplexityPolicyByAggregateID(aggregateID string) (*model.PasswordComplexityPolicyView, error) {
|
|
||||||
return view.GetPasswordComplexityPolicyByAggregateID(v.Db, passwordComplexityPolicyTable, aggregateID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) PutPasswordComplexityPolicy(policy *model.PasswordComplexityPolicyView, event *models.Event) error {
|
|
||||||
err := view.PutPasswordComplexityPolicy(v.Db, passwordComplexityPolicyTable, policy)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return v.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) DeletePasswordComplexityPolicy(aggregateID string, event *models.Event) error {
|
|
||||||
err := view.DeletePasswordComplexityPolicy(v.Db, passwordComplexityPolicyTable, aggregateID)
|
|
||||||
if err != nil && !errors.IsNotFound(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return v.ProcessedPasswordComplexityPolicySequence(event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) GetLatestPasswordComplexityPolicySequence() (*global_view.CurrentSequence, error) {
|
|
||||||
return v.latestSequence(passwordComplexityPolicyTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) ProcessedPasswordComplexityPolicySequence(event *models.Event) error {
|
|
||||||
return v.saveCurrentSequence(passwordComplexityPolicyTable, event)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) UpdatePasswordComplexityPolicySpoolerRunTimestamp() error {
|
|
||||||
return v.updateSpoolerRunSequence(passwordComplexityPolicyTable)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) GetLatestPasswordComplexityPolicyFailedEvent(sequence uint64) (*global_view.FailedEvent, error) {
|
|
||||||
return v.latestFailedEvent(passwordComplexityPolicyTable, sequence)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (v *View) ProcessedPasswordComplexityPolicyFailedEvent(failedEvent *global_view.FailedEvent) error {
|
|
||||||
return v.saveFailedEvent(failedEvent)
|
|
||||||
}
|
|
@ -28,9 +28,6 @@ type OrgRepository interface {
|
|||||||
SearchIDPProviders(ctx context.Context, request *iam_model.IDPProviderSearchRequest) (*iam_model.IDPProviderSearchResponse, error)
|
SearchIDPProviders(ctx context.Context, request *iam_model.IDPProviderSearchRequest) (*iam_model.IDPProviderSearchResponse, error)
|
||||||
GetIDPProvidersByIDPConfigID(ctx context.Context, aggregateID, idpConfigID string) ([]*iam_model.IDPProviderView, error)
|
GetIDPProvidersByIDPConfigID(ctx context.Context, aggregateID, idpConfigID string) ([]*iam_model.IDPProviderView, error)
|
||||||
|
|
||||||
GetPasswordComplexityPolicy(ctx context.Context) (*iam_model.PasswordComplexityPolicyView, error)
|
|
||||||
GetDefaultPasswordComplexityPolicy(ctx context.Context) (*iam_model.PasswordComplexityPolicyView, error)
|
|
||||||
|
|
||||||
GetPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error)
|
GetPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error)
|
||||||
GetDefaultPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error)
|
GetDefaultPasswordAgePolicy(ctx context.Context) (*iam_model.PasswordAgePolicyView, error)
|
||||||
|
|
||||||
|
143
internal/query/password_complexity_policy.go
Normal file
143
internal/query/password_complexity_policy.go
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
package query
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
errs "errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
sq "github.com/Masterminds/squirrel"
|
||||||
|
"github.com/caos/zitadel/internal/errors"
|
||||||
|
"github.com/caos/zitadel/internal/query/projection"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PasswordComplexityPolicy struct {
|
||||||
|
ID string
|
||||||
|
Sequence uint64
|
||||||
|
CreationDate time.Time
|
||||||
|
ChangeDate time.Time
|
||||||
|
ResourceOwner string
|
||||||
|
|
||||||
|
MinLength uint64
|
||||||
|
HasLowercase bool
|
||||||
|
HasUppercase bool
|
||||||
|
HasNumber bool
|
||||||
|
HasSymbol bool
|
||||||
|
|
||||||
|
IsDefault bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) PasswordComplexityPolicyByOrg(ctx context.Context, orgID string) (*PasswordComplexityPolicy, error) {
|
||||||
|
stmt, scan := preparePasswordComplexityPolicyQuery()
|
||||||
|
query, args, err := stmt.Where(
|
||||||
|
sq.Or{
|
||||||
|
sq.Eq{
|
||||||
|
PasswordComplexityColID.identifier(): orgID,
|
||||||
|
},
|
||||||
|
sq.Eq{
|
||||||
|
PasswordComplexityColID.identifier(): q.iamID,
|
||||||
|
},
|
||||||
|
}).
|
||||||
|
OrderBy(PasswordComplexityColIsDefault.identifier()).
|
||||||
|
Limit(1).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.ThrowInternal(err, "QUERY-lDnrk", "Errors.Query.SQLStatement")
|
||||||
|
}
|
||||||
|
|
||||||
|
row := q.client.QueryRowContext(ctx, query, args...)
|
||||||
|
return scan(row)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) DefaultPasswordComplexityPolicy(ctx context.Context) (*PasswordComplexityPolicy, error) {
|
||||||
|
stmt, scan := preparePasswordComplexityPolicyQuery()
|
||||||
|
query, args, err := stmt.Where(sq.Eq{
|
||||||
|
PasswordComplexityColID.identifier(): q.iamID,
|
||||||
|
}).
|
||||||
|
OrderBy(PasswordComplexityColIsDefault.identifier()).
|
||||||
|
Limit(1).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.ThrowInternal(err, "QUERY-h4Uyr", "Errors.Query.SQLStatement")
|
||||||
|
}
|
||||||
|
|
||||||
|
row := q.client.QueryRowContext(ctx, query, args...)
|
||||||
|
return scan(row)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
passwordComplexityTable = table{
|
||||||
|
name: projection.PasswordComplexityTable,
|
||||||
|
}
|
||||||
|
PasswordComplexityColID = Column{
|
||||||
|
name: projection.ComplexityPolicyIDCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColSequence = Column{
|
||||||
|
name: projection.ComplexityPolicySequenceCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColCreationDate = Column{
|
||||||
|
name: projection.ComplexityPolicyCreationDateCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColChangeDate = Column{
|
||||||
|
name: projection.ComplexityPolicyChangeDateCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColResourceOwner = Column{
|
||||||
|
name: projection.ComplexityPolicyResourceOwnerCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColMinLength = Column{
|
||||||
|
name: projection.ComplexityPolicyMinLengthCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColHasLowercase = Column{
|
||||||
|
name: projection.ComplexityPolicyHasLowercaseCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColHasUpperCase = Column{
|
||||||
|
name: projection.ComplexityPolicyHasUppercaseCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColHasNumber = Column{
|
||||||
|
name: projection.ComplexityPolicyHasNumberCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColHasSymbol = Column{
|
||||||
|
name: projection.ComplexityPolicyHasSymbolCol,
|
||||||
|
}
|
||||||
|
PasswordComplexityColIsDefault = Column{
|
||||||
|
name: projection.ComplexityPolicyIsDefaultCol,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func preparePasswordComplexityPolicyQuery() (sq.SelectBuilder, func(*sql.Row) (*PasswordComplexityPolicy, error)) {
|
||||||
|
return sq.Select(
|
||||||
|
PasswordComplexityColID.identifier(),
|
||||||
|
PasswordComplexityColSequence.identifier(),
|
||||||
|
PasswordComplexityColCreationDate.identifier(),
|
||||||
|
PasswordComplexityColChangeDate.identifier(),
|
||||||
|
PasswordComplexityColResourceOwner.identifier(),
|
||||||
|
PasswordComplexityColMinLength.identifier(),
|
||||||
|
PasswordComplexityColHasLowercase.identifier(),
|
||||||
|
PasswordComplexityColHasUpperCase.identifier(),
|
||||||
|
PasswordComplexityColHasNumber.identifier(),
|
||||||
|
PasswordComplexityColHasSymbol.identifier(),
|
||||||
|
PasswordComplexityColIsDefault.identifier(),
|
||||||
|
).
|
||||||
|
From(passwordComplexityTable.identifier()).PlaceholderFormat(sq.Dollar),
|
||||||
|
func(row *sql.Row) (*PasswordComplexityPolicy, error) {
|
||||||
|
policy := new(PasswordComplexityPolicy)
|
||||||
|
err := row.Scan(
|
||||||
|
&policy.ID,
|
||||||
|
&policy.Sequence,
|
||||||
|
&policy.CreationDate,
|
||||||
|
&policy.ChangeDate,
|
||||||
|
&policy.ResourceOwner,
|
||||||
|
&policy.MinLength,
|
||||||
|
&policy.HasLowercase,
|
||||||
|
&policy.HasUppercase,
|
||||||
|
&policy.HasNumber,
|
||||||
|
&policy.HasSymbol,
|
||||||
|
&policy.IsDefault,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
if errs.Is(err, sql.ErrNoRows) {
|
||||||
|
return nil, errors.ThrowNotFound(err, "QUERY-63mtI", "Errors.PasswordComplexity.NotFound")
|
||||||
|
}
|
||||||
|
return nil, errors.ThrowInternal(err, "QUERY-uulCZ", "Errors.Internal")
|
||||||
|
}
|
||||||
|
return policy, nil
|
||||||
|
}
|
||||||
|
}
|
164
internal/query/projection/password_complexity_policy.go
Normal file
164
internal/query/projection/password_complexity_policy.go
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
package projection
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/caos/logging"
|
||||||
|
"github.com/caos/zitadel/internal/domain"
|
||||||
|
"github.com/caos/zitadel/internal/errors"
|
||||||
|
"github.com/caos/zitadel/internal/eventstore"
|
||||||
|
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||||
|
"github.com/caos/zitadel/internal/eventstore/handler/crdb"
|
||||||
|
"github.com/caos/zitadel/internal/repository/iam"
|
||||||
|
"github.com/caos/zitadel/internal/repository/org"
|
||||||
|
"github.com/caos/zitadel/internal/repository/policy"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PasswordComplexityProjection struct {
|
||||||
|
crdb.StatementHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
PasswordComplexityTable = "zitadel.projections.password_complexity_policies"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewPasswordComplexityProjection(ctx context.Context, config crdb.StatementHandlerConfig) *PasswordComplexityProjection {
|
||||||
|
p := &PasswordComplexityProjection{}
|
||||||
|
config.ProjectionName = PasswordComplexityTable
|
||||||
|
config.Reducers = p.reducers()
|
||||||
|
p.StatementHandler = crdb.NewStatementHandler(ctx, config)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PasswordComplexityProjection) reducers() []handler.AggregateReducer {
|
||||||
|
return []handler.AggregateReducer{
|
||||||
|
{
|
||||||
|
Aggregate: org.AggregateType,
|
||||||
|
EventRedusers: []handler.EventReducer{
|
||||||
|
{
|
||||||
|
Event: org.PasswordComplexityPolicyAddedEventType,
|
||||||
|
Reduce: p.reduceAdded,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: org.PasswordComplexityPolicyChangedEventType,
|
||||||
|
Reduce: p.reduceChanged,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: org.PasswordComplexityPolicyRemovedEventType,
|
||||||
|
Reduce: p.reduceRemoved,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Aggregate: iam.AggregateType,
|
||||||
|
EventRedusers: []handler.EventReducer{
|
||||||
|
{
|
||||||
|
Event: iam.PasswordComplexityPolicyAddedEventType,
|
||||||
|
Reduce: p.reduceAdded,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: iam.PasswordComplexityPolicyChangedEventType,
|
||||||
|
Reduce: p.reduceChanged,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PasswordComplexityProjection) reduceAdded(event eventstore.EventReader) (*handler.Statement, error) {
|
||||||
|
var policyEvent policy.PasswordComplexityPolicyAddedEvent
|
||||||
|
var isDefault bool
|
||||||
|
switch e := event.(type) {
|
||||||
|
case *org.PasswordComplexityPolicyAddedEvent:
|
||||||
|
policyEvent = e.PasswordComplexityPolicyAddedEvent
|
||||||
|
isDefault = false
|
||||||
|
case *iam.PasswordComplexityPolicyAddedEvent:
|
||||||
|
policyEvent = e.PasswordComplexityPolicyAddedEvent
|
||||||
|
isDefault = true
|
||||||
|
default:
|
||||||
|
logging.LogWithFields("PROJE-mP8AR", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.PasswordComplexityPolicyAddedEventType, iam.PasswordComplexityPolicyAddedEventType}).Error("was not an event")
|
||||||
|
return nil, errors.ThrowInvalidArgument(nil, "PROJE-KTHmJ", "reduce.wrong.event.type")
|
||||||
|
}
|
||||||
|
return crdb.NewCreateStatement(
|
||||||
|
&policyEvent,
|
||||||
|
[]handler.Column{
|
||||||
|
handler.NewCol(ComplexityPolicyCreationDateCol, policyEvent.CreationDate()),
|
||||||
|
handler.NewCol(ComplexityPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||||
|
handler.NewCol(ComplexityPolicySequenceCol, policyEvent.Sequence()),
|
||||||
|
handler.NewCol(ComplexityPolicyIDCol, policyEvent.Aggregate().ID),
|
||||||
|
handler.NewCol(ComplexityPolicyStateCol, domain.PolicyStateActive),
|
||||||
|
handler.NewCol(ComplexityPolicyMinLengthCol, policyEvent.MinLength),
|
||||||
|
handler.NewCol(ComplexityPolicyHasLowercaseCol, policyEvent.HasLowercase),
|
||||||
|
handler.NewCol(ComplexityPolicyHasUppercaseCol, policyEvent.HasUppercase),
|
||||||
|
handler.NewCol(ComplexityPolicyHasSymbolCol, policyEvent.HasSymbol),
|
||||||
|
handler.NewCol(ComplexityPolicyHasNumberCol, policyEvent.HasNumber),
|
||||||
|
handler.NewCol(ComplexityPolicyResourceOwnerCol, policyEvent.Aggregate().ResourceOwner),
|
||||||
|
handler.NewCol(ComplexityPolicyIsDefaultCol, isDefault),
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PasswordComplexityProjection) reduceChanged(event eventstore.EventReader) (*handler.Statement, error) {
|
||||||
|
var policyEvent policy.PasswordComplexityPolicyChangedEvent
|
||||||
|
switch e := event.(type) {
|
||||||
|
case *org.PasswordComplexityPolicyChangedEvent:
|
||||||
|
policyEvent = e.PasswordComplexityPolicyChangedEvent
|
||||||
|
case *iam.PasswordComplexityPolicyChangedEvent:
|
||||||
|
policyEvent = e.PasswordComplexityPolicyChangedEvent
|
||||||
|
default:
|
||||||
|
logging.LogWithFields("PROJE-L4UHn", "seq", event.Sequence(), "expectedTypes", []eventstore.EventType{org.PasswordComplexityPolicyChangedEventType, iam.PasswordComplexityPolicyChangedEventType}).Error("was not an event")
|
||||||
|
return nil, errors.ThrowInvalidArgument(nil, "PROJE-cf3Xb", "reduce.wrong.event.type")
|
||||||
|
}
|
||||||
|
cols := []handler.Column{
|
||||||
|
handler.NewCol(ComplexityPolicyChangeDateCol, policyEvent.CreationDate()),
|
||||||
|
handler.NewCol(ComplexityPolicySequenceCol, policyEvent.Sequence()),
|
||||||
|
}
|
||||||
|
if policyEvent.MinLength != nil {
|
||||||
|
cols = append(cols, handler.NewCol(ComplexityPolicyMinLengthCol, *policyEvent.MinLength))
|
||||||
|
}
|
||||||
|
if policyEvent.HasLowercase != nil {
|
||||||
|
cols = append(cols, handler.NewCol(ComplexityPolicyHasLowercaseCol, *policyEvent.HasLowercase))
|
||||||
|
}
|
||||||
|
if policyEvent.HasUppercase != nil {
|
||||||
|
cols = append(cols, handler.NewCol(ComplexityPolicyHasUppercaseCol, *policyEvent.HasUppercase))
|
||||||
|
}
|
||||||
|
if policyEvent.HasSymbol != nil {
|
||||||
|
cols = append(cols, handler.NewCol(ComplexityPolicyHasSymbolCol, *policyEvent.HasSymbol))
|
||||||
|
}
|
||||||
|
if policyEvent.HasNumber != nil {
|
||||||
|
cols = append(cols, handler.NewCol(ComplexityPolicyHasNumberCol, *policyEvent.HasNumber))
|
||||||
|
}
|
||||||
|
return crdb.NewUpdateStatement(
|
||||||
|
&policyEvent,
|
||||||
|
cols,
|
||||||
|
[]handler.Condition{
|
||||||
|
handler.NewCond(ComplexityPolicyIDCol, policyEvent.Aggregate().ID),
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PasswordComplexityProjection) reduceRemoved(event eventstore.EventReader) (*handler.Statement, error) {
|
||||||
|
policyEvent, ok := event.(*org.PasswordComplexityPolicyRemovedEvent)
|
||||||
|
if !ok {
|
||||||
|
logging.LogWithFields("PROJE-ibd0c", "seq", event.Sequence(), "expectedType", org.PasswordComplexityPolicyRemovedEventType).Error("was not an event")
|
||||||
|
return nil, errors.ThrowInvalidArgument(nil, "PROJE-wttCd", "reduce.wrong.event.type")
|
||||||
|
}
|
||||||
|
return crdb.NewDeleteStatement(
|
||||||
|
policyEvent,
|
||||||
|
[]handler.Condition{
|
||||||
|
handler.NewCond(ComplexityPolicyIDCol, policyEvent.Aggregate().ID),
|
||||||
|
}), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
ComplexityPolicyCreationDateCol = "creation_date"
|
||||||
|
ComplexityPolicyChangeDateCol = "change_date"
|
||||||
|
ComplexityPolicySequenceCol = "sequence"
|
||||||
|
ComplexityPolicyIDCol = "id"
|
||||||
|
ComplexityPolicyStateCol = "state"
|
||||||
|
ComplexityPolicyMinLengthCol = "min_length"
|
||||||
|
ComplexityPolicyHasLowercaseCol = "has_lowercase"
|
||||||
|
ComplexityPolicyHasUppercaseCol = "has_uppercase"
|
||||||
|
ComplexityPolicyHasSymbolCol = "has_symbol"
|
||||||
|
ComplexityPolicyHasNumberCol = "has_number"
|
||||||
|
ComplexityPolicyIsDefaultCol = "is_default"
|
||||||
|
ComplexityPolicyResourceOwnerCol = "resource_owner"
|
||||||
|
)
|
234
internal/query/projection/password_complexity_policy_test.go
Normal file
234
internal/query/projection/password_complexity_policy_test.go
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
package projection
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/caos/zitadel/internal/domain"
|
||||||
|
"github.com/caos/zitadel/internal/errors"
|
||||||
|
"github.com/caos/zitadel/internal/eventstore"
|
||||||
|
"github.com/caos/zitadel/internal/eventstore/handler"
|
||||||
|
"github.com/caos/zitadel/internal/eventstore/repository"
|
||||||
|
"github.com/caos/zitadel/internal/repository/iam"
|
||||||
|
"github.com/caos/zitadel/internal/repository/org"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPasswordComplexityProjection_reduces(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
event func(t *testing.T) eventstore.EventReader
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
reduce func(event eventstore.EventReader) (*handler.Statement, error)
|
||||||
|
want wantReduce
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "org.reduceAdded",
|
||||||
|
args: args{
|
||||||
|
event: getEvent(testEvent(
|
||||||
|
repository.EventType(org.PasswordComplexityPolicyAddedEventType),
|
||||||
|
org.AggregateType,
|
||||||
|
[]byte(`{
|
||||||
|
"minLength": 10,
|
||||||
|
"hasLowercase": true,
|
||||||
|
"hasUppercase": true,
|
||||||
|
"HasNumber": true,
|
||||||
|
"HasSymbol": true
|
||||||
|
}`),
|
||||||
|
), org.PasswordComplexityPolicyAddedEventMapper),
|
||||||
|
},
|
||||||
|
reduce: (&PasswordComplexityProjection{}).reduceAdded,
|
||||||
|
want: wantReduce{
|
||||||
|
aggregateType: eventstore.AggregateType("org"),
|
||||||
|
sequence: 15,
|
||||||
|
previousSequence: 10,
|
||||||
|
projection: PasswordComplexityTable,
|
||||||
|
executer: &testExecuter{
|
||||||
|
executions: []execution{
|
||||||
|
{
|
||||||
|
expectedStmt: "INSERT INTO zitadel.projections.password_complexity_policies (creation_date, change_date, sequence, id, state, min_length, has_lowercase, has_uppercase, has_symbol, has_number, resource_owner, is_default) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)",
|
||||||
|
expectedArgs: []interface{}{
|
||||||
|
anyArg{},
|
||||||
|
anyArg{},
|
||||||
|
uint64(15),
|
||||||
|
"agg-id",
|
||||||
|
domain.PolicyStateActive,
|
||||||
|
uint64(10),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
"ro-id",
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "org.reduceChanged",
|
||||||
|
reduce: (&PasswordComplexityProjection{}).reduceChanged,
|
||||||
|
args: args{
|
||||||
|
event: getEvent(testEvent(
|
||||||
|
repository.EventType(org.PasswordComplexityPolicyChangedEventType),
|
||||||
|
org.AggregateType,
|
||||||
|
[]byte(`{
|
||||||
|
"minLength": 11,
|
||||||
|
"hasLowercase": true,
|
||||||
|
"hasUppercase": true,
|
||||||
|
"HasNumber": true,
|
||||||
|
"HasSymbol": true
|
||||||
|
}`),
|
||||||
|
), org.PasswordComplexityPolicyChangedEventMapper),
|
||||||
|
},
|
||||||
|
want: wantReduce{
|
||||||
|
aggregateType: eventstore.AggregateType("org"),
|
||||||
|
sequence: 15,
|
||||||
|
previousSequence: 10,
|
||||||
|
projection: PasswordComplexityTable,
|
||||||
|
executer: &testExecuter{
|
||||||
|
executions: []execution{
|
||||||
|
{
|
||||||
|
expectedStmt: "UPDATE zitadel.projections.password_complexity_policies SET (change_date, sequence, min_length, has_lowercase, has_uppercase, has_symbol, has_number) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8)",
|
||||||
|
expectedArgs: []interface{}{
|
||||||
|
anyArg{},
|
||||||
|
uint64(15),
|
||||||
|
uint64(11),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
"agg-id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "org.reduceRemoved",
|
||||||
|
reduce: (&PasswordComplexityProjection{}).reduceRemoved,
|
||||||
|
args: args{
|
||||||
|
event: getEvent(testEvent(
|
||||||
|
repository.EventType(org.PasswordComplexityPolicyRemovedEventType),
|
||||||
|
org.AggregateType,
|
||||||
|
nil,
|
||||||
|
), org.PasswordComplexityPolicyRemovedEventMapper),
|
||||||
|
},
|
||||||
|
want: wantReduce{
|
||||||
|
aggregateType: eventstore.AggregateType("org"),
|
||||||
|
sequence: 15,
|
||||||
|
previousSequence: 10,
|
||||||
|
projection: PasswordComplexityTable,
|
||||||
|
executer: &testExecuter{
|
||||||
|
executions: []execution{
|
||||||
|
{
|
||||||
|
expectedStmt: "DELETE FROM zitadel.projections.password_complexity_policies WHERE (id = $1)",
|
||||||
|
expectedArgs: []interface{}{
|
||||||
|
"agg-id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "iam.reduceAdded",
|
||||||
|
reduce: (&PasswordComplexityProjection{}).reduceAdded,
|
||||||
|
args: args{
|
||||||
|
event: getEvent(testEvent(
|
||||||
|
repository.EventType(iam.PasswordComplexityPolicyAddedEventType),
|
||||||
|
iam.AggregateType,
|
||||||
|
[]byte(`{
|
||||||
|
"minLength": 10,
|
||||||
|
"hasLowercase": true,
|
||||||
|
"hasUppercase": true,
|
||||||
|
"HasNumber": true,
|
||||||
|
"HasSymbol": true
|
||||||
|
}`),
|
||||||
|
), iam.PasswordComplexityPolicyAddedEventMapper),
|
||||||
|
},
|
||||||
|
want: wantReduce{
|
||||||
|
aggregateType: eventstore.AggregateType("iam"),
|
||||||
|
sequence: 15,
|
||||||
|
previousSequence: 10,
|
||||||
|
projection: PasswordComplexityTable,
|
||||||
|
executer: &testExecuter{
|
||||||
|
executions: []execution{
|
||||||
|
{
|
||||||
|
expectedStmt: "INSERT INTO zitadel.projections.password_complexity_policies (creation_date, change_date, sequence, id, state, min_length, has_lowercase, has_uppercase, has_symbol, has_number, resource_owner, is_default) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)",
|
||||||
|
expectedArgs: []interface{}{
|
||||||
|
anyArg{},
|
||||||
|
anyArg{},
|
||||||
|
uint64(15),
|
||||||
|
"agg-id",
|
||||||
|
domain.PolicyStateActive,
|
||||||
|
uint64(10),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
"ro-id",
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "iam.reduceChanged",
|
||||||
|
reduce: (&PasswordComplexityProjection{}).reduceChanged,
|
||||||
|
args: args{
|
||||||
|
event: getEvent(testEvent(
|
||||||
|
repository.EventType(iam.PasswordComplexityPolicyChangedEventType),
|
||||||
|
iam.AggregateType,
|
||||||
|
[]byte(`{
|
||||||
|
"minLength": 10,
|
||||||
|
"hasLowercase": true,
|
||||||
|
"hasUppercase": true,
|
||||||
|
"HasNumber": true,
|
||||||
|
"HasSymbol": true
|
||||||
|
}`),
|
||||||
|
), iam.PasswordComplexityPolicyChangedEventMapper),
|
||||||
|
},
|
||||||
|
want: wantReduce{
|
||||||
|
aggregateType: eventstore.AggregateType("iam"),
|
||||||
|
sequence: 15,
|
||||||
|
previousSequence: 10,
|
||||||
|
projection: PasswordComplexityTable,
|
||||||
|
executer: &testExecuter{
|
||||||
|
executions: []execution{
|
||||||
|
{
|
||||||
|
expectedStmt: "UPDATE zitadel.projections.password_complexity_policies SET (change_date, sequence, min_length, has_lowercase, has_uppercase, has_symbol, has_number) = ($1, $2, $3, $4, $5, $6, $7) WHERE (id = $8)",
|
||||||
|
expectedArgs: []interface{}{
|
||||||
|
anyArg{},
|
||||||
|
uint64(15),
|
||||||
|
uint64(10),
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
"agg-id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
event := baseEvent(t)
|
||||||
|
got, err := tt.reduce(event)
|
||||||
|
if _, ok := err.(errors.InvalidArgument); !ok {
|
||||||
|
t.Errorf("no wrong event mapping: %v, got: %v", err, got)
|
||||||
|
}
|
||||||
|
|
||||||
|
event = tt.args.event(t)
|
||||||
|
got, err = tt.reduce(event)
|
||||||
|
assertReduce(t, got, err, tt.want)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -37,6 +37,7 @@ func Start(ctx context.Context, sqlClient *sql.DB, es *eventstore.Eventstore, co
|
|||||||
NewActionProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["actions"]))
|
NewActionProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["actions"]))
|
||||||
NewFlowProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["flows"]))
|
NewFlowProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["flows"]))
|
||||||
NewProjectProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["projects"]))
|
NewProjectProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["projects"]))
|
||||||
|
NewPasswordComplexityProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["password_complexities"]))
|
||||||
NewProjectGrantProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["project_grants"]))
|
NewProjectGrantProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["project_grants"]))
|
||||||
NewProjectRoleProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["project_roles"]))
|
NewProjectRoleProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["project_roles"]))
|
||||||
// owner.NewOrgOwnerProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["org_owners"]))
|
// owner.NewOrgOwnerProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["org_owners"]))
|
||||||
|
@ -5,9 +5,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/caos/zitadel/internal/auth_request/model"
|
|
||||||
"github.com/caos/zitadel/internal/domain"
|
"github.com/caos/zitadel/internal/domain"
|
||||||
"github.com/caos/zitadel/internal/errors"
|
|
||||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -74,30 +72,3 @@ func (l *Login) generatePolicyDescription(r *http.Request, authReq *domain.AuthR
|
|||||||
description += "</ul>"
|
description += "</ul>"
|
||||||
return description, nil
|
return description, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Login) checkPasswordComplexityPolicy(password string, r *http.Request, authReq *model.AuthRequest) error {
|
|
||||||
policy, err := l.authRepo.GetMyPasswordComplexityPolicy(setContext(r.Context(), authReq.UserOrgID))
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if policy.MinLength != 0 && uint64(len(password)) < policy.MinLength {
|
|
||||||
return errors.ThrowInvalidArgument(nil, "POLICY-LSo0p", "Errors.User.PasswordComplexityPolicy.MinLength")
|
|
||||||
}
|
|
||||||
|
|
||||||
if policy.HasLowercase && !hasStringLowerCase(password) {
|
|
||||||
return errors.ThrowInvalidArgument(nil, "POLICY-4Sjsf", "Errors.User.PasswordComplexityPolicy.HasLower")
|
|
||||||
}
|
|
||||||
|
|
||||||
if policy.HasUppercase && !hasStringUpperCase(password) {
|
|
||||||
return errors.ThrowInvalidArgument(nil, "POLICY-6Sjc9", "Errors.User.PasswordComplexityPolicy.HasUpper")
|
|
||||||
}
|
|
||||||
|
|
||||||
if policy.HasNumber && !hasNumber(password) {
|
|
||||||
return errors.ThrowInvalidArgument(nil, "POLICY-2Fksi", "Errors.User.PasswordComplexityPolicy.HasNumber")
|
|
||||||
}
|
|
||||||
|
|
||||||
if policy.HasSymbol && !hasSymbol(password) {
|
|
||||||
return errors.ThrowInvalidArgument(nil, "POLICY-0Js6e", "Errors.User.PasswordComplexityPolicy.HasSymbol")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/caos/zitadel/internal/crypto"
|
|
||||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
||||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
||||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/caos/zitadel/internal/crypto"
|
||||||
|
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Password struct {
|
type Password struct {
|
||||||
@ -34,22 +33,3 @@ const (
|
|||||||
func (p *Password) IsValid() bool {
|
func (p *Password) IsValid() bool {
|
||||||
return p.AggregateID != "" && p.SecretString != ""
|
return p.AggregateID != "" && p.SecretString != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Password) HashPasswordIfExisting(policy *iam_model.PasswordComplexityPolicyView, passwordAlg crypto.HashAlgorithm, onetime bool) error {
|
|
||||||
if p.SecretString == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if policy == nil {
|
|
||||||
return caos_errs.ThrowPreconditionFailed(nil, "MODEL-s8ifS", "Errors.User.PasswordComplexityPolicy.NotFound")
|
|
||||||
}
|
|
||||||
if err := policy.Check(p.SecretString); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
secret, err := crypto.Hash([]byte(p.SecretString), passwordAlg)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
p.SecretCrypto = secret
|
|
||||||
p.ChangeRequired = onetime
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
17
migrations/cockroach/V1.80__password_complexity_policy.sql
Normal file
17
migrations/cockroach/V1.80__password_complexity_policy.sql
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
CREATE TABLE zitadel.projections.password_complexity_policies (
|
||||||
|
id STRING NOT NULL,
|
||||||
|
creation_date TIMESTAMPTZ NULL,
|
||||||
|
change_date TIMESTAMPTZ NULL,
|
||||||
|
sequence INT8 NULL,
|
||||||
|
state INT2 NULL,
|
||||||
|
resource_owner TEXT,
|
||||||
|
|
||||||
|
is_default BOOLEAN,
|
||||||
|
min_length INT8 NULL,
|
||||||
|
has_lowercase BOOL NULL,
|
||||||
|
has_uppercase BOOL NULL,
|
||||||
|
has_symbol BOOL NULL,
|
||||||
|
has_number BOOL NULL,
|
||||||
|
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
Loading…
x
Reference in New Issue
Block a user