mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-03 01:18:51 +00:00
feat(rt): IDP Intents Relational Table (#11374)
# Which Problems Are Solved In the context of moving our datastore to relational tables, Identity Provider Intents have no definition of a relational table nor any DB API that can be used to store the IDP intents as relational objects. # How the Problems Are Solved The PR follows the guidelines left in #11190 - A table `zitadel.identity_provider_intents` is created: it defines its relational constraints (foreign keys) with the other tables, as well as an ENUM to represent the state of the intent. - An IDP Intent repository has been created, which offers CRUD operations implemented as `Create`, `Get`, `Update` and `Delete` methods for the IDP intent. - The repository also defines all columns and conditions useful for performing DB operations on the IDP intents. - DB mocks have been added as well to ease testing on the `domain` package. - Reduction functions have been implemented for the existing IDP events so to keep the relational table in sync with the event store. # Additional Changes To allow testing LDAP intent flow, the `Session.FetchUser()` method has been extracted to a separate file. A corresponding mock has been created as well in `fetch_user_mock.go`. The files are mutually excluded and added at build time through go build tags: the mock is added when the `integration` tag is specified, while the real implementation is added when the same tag IS NOT added to the build tags. # Additional Context - Closes #11190 --------- Co-authored-by: Livio Spring <[email protected]> Co-authored-by: Silvan <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
Silvan
parent
ca9c7619c6
commit
4936bdf2c9
@@ -365,9 +365,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
||||
ldapSuccessfulWithUserID, ldapWithUserToken, ldapWithUserChangeDate, ldapWithUserSequence, err := sink.SuccessfulLDAPIntent(Instance.ID(), ldapIdpID, "id", "user")
|
||||
require.NoError(t, err)
|
||||
|
||||
samlSuccessfulID, samlToken, samlChangeDate, samlSequence, err := sink.SuccessfulSAMLIntent(Instance.ID(), samlIdpID, "id", "", expiry)
|
||||
samlSuccessfulID, samlToken, samlChangeDate, samlSequence, err := sink.SuccessfulSAMLIntent(Instance.ID(), samlIdpID, "id", "", "", expiry)
|
||||
require.NoError(t, err)
|
||||
samlSuccessfulWithUserID, samlWithUserToken, samlWithUserChangeDate, samlWithUserSequence, err := sink.SuccessfulSAMLIntent(Instance.ID(), samlIdpID, "id", "user", expiry)
|
||||
samlSuccessfulWithUserID, samlWithUserToken, samlWithUserChangeDate, samlWithUserSequence, err := sink.SuccessfulSAMLIntent(Instance.ID(), samlIdpID, "id", "user", "", expiry)
|
||||
require.NoError(t, err)
|
||||
|
||||
jwtSuccessfulID, jwtToken, jwtChangeDate, jwtSequence, err := sink.SuccessfulJWTIntent(Instance.ID(), jwtIdPID, "id", "", expiry)
|
||||
|
||||
@@ -2245,9 +2245,9 @@ func TestServer_RetrieveIdentityProviderIntent(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
ldapSuccessfulWithUserID, ldapWithUserToken, ldapWithUserChangeDate, ldapWithUserSequence, err := sink.SuccessfulLDAPIntent(Instance.ID(), ldapIdpID, "id", "user")
|
||||
require.NoError(t, err)
|
||||
samlSuccessfulID, samlToken, samlChangeDate, samlSequence, err := sink.SuccessfulSAMLIntent(Instance.ID(), samlIdpID, "id", "", expiry)
|
||||
samlSuccessfulID, samlToken, samlChangeDate, samlSequence, err := sink.SuccessfulSAMLIntent(Instance.ID(), samlIdpID, "id", "", "", expiry)
|
||||
require.NoError(t, err)
|
||||
samlSuccessfulWithUserID, samlWithUserToken, samlWithUserChangeDate, samlWithUserSequence, err := sink.SuccessfulSAMLIntent(Instance.ID(), samlIdpID, "id", "user", expiry)
|
||||
samlSuccessfulWithUserID, samlWithUserToken, samlWithUserChangeDate, samlWithUserSequence, err := sink.SuccessfulSAMLIntent(Instance.ID(), samlIdpID, "id", "user", "", expiry)
|
||||
require.NoError(t, err)
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
//go:build !integration
|
||||
|
||||
package ldap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/idp"
|
||||
)
|
||||
|
||||
// FetchUser implements the [idp.Session] interface.
|
||||
func (s *Session) FetchUser(_ context.Context) (_ idp.User, err error) {
|
||||
var user *ldap.Entry
|
||||
for _, server := range s.Provider.servers {
|
||||
user, err = tryBind(server,
|
||||
s.Provider.startTLS,
|
||||
s.Provider.bindDN,
|
||||
s.Provider.bindPassword,
|
||||
s.Provider.baseDN,
|
||||
s.Provider.getNecessaryAttributes(),
|
||||
s.Provider.userObjectClasses,
|
||||
s.Provider.userFilters,
|
||||
s.User,
|
||||
s.Password,
|
||||
s.Provider.timeout,
|
||||
s.Provider.rootCA)
|
||||
// If there were invalid credentials or multiple users with the credentials cancel process
|
||||
if err != nil && (errors.Is(err, ErrFailedLogin) || errors.Is(err, ErrNoSingleUser)) {
|
||||
return nil, err
|
||||
}
|
||||
// If a user bind was successful and user is filled continue with login, otherwise try next server
|
||||
if err == nil && user != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Entry = user
|
||||
|
||||
return mapLDAPEntryToUser(
|
||||
user,
|
||||
s.Provider.idAttribute,
|
||||
s.Provider.firstNameAttribute,
|
||||
s.Provider.lastNameAttribute,
|
||||
s.Provider.displayNameAttribute,
|
||||
s.Provider.nickNameAttribute,
|
||||
s.Provider.preferredUsernameAttribute,
|
||||
s.Provider.emailAttribute,
|
||||
s.Provider.emailVerifiedAttribute,
|
||||
s.Provider.phoneAttribute,
|
||||
s.Provider.phoneVerifiedAttribute,
|
||||
s.Provider.preferredLanguageAttribute,
|
||||
s.Provider.avatarURLAttribute,
|
||||
s.Provider.profileAttribute,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//go:build integration
|
||||
|
||||
package ldap
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/go-ldap/ldap/v3"
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/idp"
|
||||
)
|
||||
|
||||
const (
|
||||
FailingUser = "IAM FAIL"
|
||||
FailingPsw = "test failed successfully"
|
||||
)
|
||||
|
||||
// FetchUser implements the [idp.Session] interface.
|
||||
//
|
||||
// This is a mock implementation of [idp.Session.FetchUser] that is used
|
||||
// during integration tests and substitutes the real [idp.Session.FetchUser]
|
||||
// implementation.
|
||||
//
|
||||
// This has been done to allow writing integration tests against a
|
||||
// fake (external) LDAP server.
|
||||
//
|
||||
// The substitution/overloading is done through build tags.
|
||||
//
|
||||
// When the LDAP start intent is called with `username = [FailingUser]` and
|
||||
// `password = [FailingPsw]`, the method return [ErrFailedLogin] to be able
|
||||
// to mock an intent failed event.
|
||||
func (s *Session) FetchUser(_ context.Context) (_ idp.User, err error) {
|
||||
if s.User == FailingUser && s.Password == FailingPsw {
|
||||
return nil, ErrFailedLogin
|
||||
}
|
||||
|
||||
usr := NewUser(
|
||||
gofakeit.UUID(),
|
||||
gofakeit.FirstName(),
|
||||
gofakeit.LastName(),
|
||||
gofakeit.Name(),
|
||||
gofakeit.Name(),
|
||||
gofakeit.Name(),
|
||||
domain.EmailAddress(gofakeit.Email()),
|
||||
true,
|
||||
domain.PhoneNumber(gofakeit.Phone()),
|
||||
true,
|
||||
language.English,
|
||||
gofakeit.URL(),
|
||||
gofakeit.UUID(),
|
||||
)
|
||||
|
||||
s.Entry = &ldap.Entry{
|
||||
DN: s.Provider.baseDN,
|
||||
Attributes: []*ldap.EntryAttribute{
|
||||
{Name: "uid", Values: []string{gofakeit.UUID()}},
|
||||
{Name: "givenName", Values: []string{gofakeit.FirstName()}},
|
||||
{Name: "sn", Values: []string{gofakeit.LastName()}},
|
||||
{Name: "mail", Values: []string{gofakeit.Email()}},
|
||||
{Name: "telephoneNumber", Values: []string{gofakeit.Phone()}},
|
||||
{Name: "displayName", Values: []string{gofakeit.Name()}},
|
||||
},
|
||||
}
|
||||
return usr, nil
|
||||
}
|
||||
@@ -245,6 +245,7 @@ func (p *Provider) IsAutoUpdate() bool {
|
||||
return p.isAutoUpdate
|
||||
}
|
||||
|
||||
// Do not remove, used in [Session.FetchUser] @ fetch_user.go
|
||||
func (p *Provider) getNecessaryAttributes() []string {
|
||||
attributes := []string{p.userBase}
|
||||
if p.idAttribute != "" {
|
||||
|
||||
@@ -48,58 +48,11 @@ func (s *Session) PersistentParameters() map[string]any {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchUser implements the [idp.Session] interface.
|
||||
func (s *Session) FetchUser(_ context.Context) (_ idp.User, err error) {
|
||||
var user *ldap.Entry
|
||||
for _, server := range s.Provider.servers {
|
||||
user, err = tryBind(server,
|
||||
s.Provider.startTLS,
|
||||
s.Provider.bindDN,
|
||||
s.Provider.bindPassword,
|
||||
s.Provider.baseDN,
|
||||
s.Provider.getNecessaryAttributes(),
|
||||
s.Provider.userObjectClasses,
|
||||
s.Provider.userFilters,
|
||||
s.User,
|
||||
s.Password,
|
||||
s.Provider.timeout,
|
||||
s.Provider.rootCA)
|
||||
// If there were invalid credentials or multiple users with the credentials cancel process
|
||||
if err != nil && (errors.Is(err, ErrFailedLogin) || errors.Is(err, ErrNoSingleUser)) {
|
||||
return nil, err
|
||||
}
|
||||
// If a user bind was successful and user is filled continue with login, otherwise try next server
|
||||
if err == nil && user != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Entry = user
|
||||
|
||||
return mapLDAPEntryToUser(
|
||||
user,
|
||||
s.Provider.idAttribute,
|
||||
s.Provider.firstNameAttribute,
|
||||
s.Provider.lastNameAttribute,
|
||||
s.Provider.displayNameAttribute,
|
||||
s.Provider.nickNameAttribute,
|
||||
s.Provider.preferredUsernameAttribute,
|
||||
s.Provider.emailAttribute,
|
||||
s.Provider.emailVerifiedAttribute,
|
||||
s.Provider.phoneAttribute,
|
||||
s.Provider.phoneVerifiedAttribute,
|
||||
s.Provider.preferredLanguageAttribute,
|
||||
s.Provider.avatarURLAttribute,
|
||||
s.Provider.profileAttribute,
|
||||
)
|
||||
}
|
||||
|
||||
func (s *Session) ExpiresAt() time.Time {
|
||||
return time.Time{} // falls back to the default expiration time
|
||||
}
|
||||
|
||||
// Do not remove, used in [Session.FetchUser] @ fetch_user.go
|
||||
func tryBind(
|
||||
server string,
|
||||
startTLS bool,
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -108,7 +109,12 @@ func SuccessfulOIDCIntent(instanceID, idpID, idpUserID, userID string, expiry ti
|
||||
return resp.IntentID, resp.Token, resp.ChangeDate, resp.Sequence, nil
|
||||
}
|
||||
|
||||
func SuccessfulSAMLIntent(instanceID, idpID, idpUserID, userID string, expiry time.Time) (string, string, time.Time, uint64, error) {
|
||||
// SuccessfulSAMLIntent creates a SAMLIntent and then executes the flow to put it in
|
||||
// successful state.
|
||||
//
|
||||
// If intentID is not empty, the intent creation is skipped and only the flow part to switch
|
||||
// the intent to a successful state is executed.
|
||||
func SuccessfulSAMLIntent(instanceID, idpID, idpUserID, userID, intentID string, expiry time.Time) (string, string, time.Time, uint64, error) {
|
||||
u := url.URL{
|
||||
Scheme: "http",
|
||||
Host: host,
|
||||
@@ -120,6 +126,7 @@ func SuccessfulSAMLIntent(instanceID, idpID, idpUserID, userID string, expiry ti
|
||||
IDPUserID: idpUserID,
|
||||
UserID: userID,
|
||||
Expiry: expiry,
|
||||
IntentID: intentID,
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", time.Time{}, uint64(0), err
|
||||
@@ -341,6 +348,7 @@ type SuccessfulIntentRequest struct {
|
||||
IDPUserID string `json:"idp_user_id"`
|
||||
UserID string `json:"user_id"`
|
||||
Expiry time.Time `json:"expiry"`
|
||||
IntentID string `json:"intent_id"`
|
||||
}
|
||||
type SuccessfulIntentResponse struct {
|
||||
IntentID string `json:"intent_id"`
|
||||
@@ -519,7 +527,10 @@ func createSuccessfulOIDCIntent(ctx context.Context, cmd *command.Commands, req
|
||||
}
|
||||
|
||||
func createSuccessfulSAMLIntent(ctx context.Context, cmd *command.Commands, req *SuccessfulIntentRequest) (*SuccessfulIntentResponse, error) {
|
||||
intentID, err := createIntent(ctx, cmd, req.InstanceID, req.IDPID)
|
||||
intentID := strings.TrimSpace(req.IntentID)
|
||||
if intentID == "" {
|
||||
intentID, _ = createIntent(ctx, cmd, req.InstanceID, req.IDPID)
|
||||
}
|
||||
writeModel, err := cmd.GetIntentWriteModel(ctx, intentID, req.InstanceID)
|
||||
|
||||
idpUser := &saml.UserMapper{
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
package projection
|
||||
|
||||
// TODO(adlerhurst): Uncomment once users table is created and FK can be enforced
|
||||
|
||||
// import (
|
||||
// "context"
|
||||
// "database/sql"
|
||||
// "encoding/json"
|
||||
|
||||
// "github.com/zitadel/zitadel/backend/v3/domain"
|
||||
// "github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||
// v3_sql "github.com/zitadel/zitadel/backend/v3/storage/database/dialect/sql"
|
||||
// "github.com/zitadel/zitadel/backend/v3/storage/database/repository"
|
||||
// "github.com/zitadel/zitadel/internal/eventstore"
|
||||
// "github.com/zitadel/zitadel/internal/eventstore/handler/v2"
|
||||
// "github.com/zitadel/zitadel/internal/repository/idpintent"
|
||||
// "github.com/zitadel/zitadel/internal/zerrors"
|
||||
// )
|
||||
|
||||
// const (
|
||||
// IDPIntentRelationalProjectionTable = "zitadel.identity_provider_intents"
|
||||
// )
|
||||
|
||||
// type idpIntentRelationalProjection struct{}
|
||||
|
||||
// func (*idpIntentRelationalProjection) Name() string {
|
||||
// return IDPIntentRelationalProjectionTable
|
||||
// }
|
||||
|
||||
// func newIDPIntentRelationalProjection(ctx context.Context, config handler.Config) *handler.Handler {
|
||||
// return handler.NewHandler(ctx, &config, new(idpIntentRelationalProjection))
|
||||
// }
|
||||
|
||||
// // Reducers implements [handler.Projection].
|
||||
// func (i *idpIntentRelationalProjection) Reducers() []handler.AggregateReducer {
|
||||
// return []handler.AggregateReducer{
|
||||
// {
|
||||
// Aggregate: idpintent.AggregateType,
|
||||
// EventReducers: []handler.EventReducer{
|
||||
// {Event: idpintent.StartedEventType, Reduce: i.reduceStartedEvent},
|
||||
// {Event: idpintent.SucceededEventType, Reduce: i.reduceSucceededEvent},
|
||||
// {Event: idpintent.SAMLSucceededEventType, Reduce: i.reduceSAMLSucceededEvent},
|
||||
// {Event: idpintent.SAMLRequestEventType, Reduce: i.reduceSAMLRequestEvent},
|
||||
// {Event: idpintent.LDAPSucceededEventType, Reduce: i.reduceLDAPSucceededEvent},
|
||||
// {Event: idpintent.FailedEventType, Reduce: i.reduceFailedEvent},
|
||||
// {Event: idpintent.ConsumedEventType, Reduce: i.reduceConsumedEvent},
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// func (i *idpIntentRelationalProjection) reduceStartedEvent(evt eventstore.Event) (*handler.Statement, error) {
|
||||
// e, ok := evt.(*idpintent.StartedEvent)
|
||||
// if !ok {
|
||||
// return nil, zerrors.ThrowInternalf(nil, "HANDL-Lqj3HB", "reduce.wrong.event.type %s", idpintent.StartedEventType)
|
||||
// }
|
||||
// return handler.NewStatement(e, func(ctx context.Context, ex handler.Executer, _ string) error {
|
||||
// tx, ok := ex.(*sql.Tx)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInvalidArgumentf(nil, "HANDL-rirFQm", "reduce.wrong.db.pool %T", ex)
|
||||
// }
|
||||
|
||||
// repo := repository.IDPIntentRepository()
|
||||
// return repo.Create(ctx, v3_sql.SQLTx(tx), &domain.IDPIntent{
|
||||
// ID: e.Aggregate().ID,
|
||||
// InstanceID: e.Aggregate().InstanceID,
|
||||
// State: domain.IDPIntentStateStarted,
|
||||
// SuccessURL: e.SuccessURL,
|
||||
// FailureURL: e.FailureURL,
|
||||
// CreatedAt: e.CreationDate(),
|
||||
// UpdatedAt: e.CreationDate(),
|
||||
// IDPID: e.IDPID,
|
||||
// IDPArguments: e.IDPArguments,
|
||||
// })
|
||||
// }), nil
|
||||
// }
|
||||
|
||||
// func (i *idpIntentRelationalProjection) reduceSucceededEvent(evt eventstore.Event) (*handler.Statement, error) {
|
||||
// e, ok := evt.(*idpintent.SucceededEvent)
|
||||
// if !ok {
|
||||
// return nil, zerrors.ThrowInternalf(nil, "HANDL-hQSxj0", "reduce.wrong.event.type %s", idpintent.SucceededEventType)
|
||||
// }
|
||||
// return handler.NewStatement(e, func(ctx context.Context, ex handler.Executer, _ string) error {
|
||||
// tx, ok := ex.(*sql.Tx)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInvalidArgumentf(nil, "HANDL-ry4tFH", "reduce.wrong.db.pool %T", ex)
|
||||
// }
|
||||
// idpAccessToken, err := e.IDPAccessToken.Value()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// jsonIDPAccessToken, ok := idpAccessToken.([]byte)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInternal(nil, "HANDL-32XE1L", "reduce.convertion.json.failed")
|
||||
// }
|
||||
// repo := repository.IDPIntentRepository()
|
||||
|
||||
// changes := []database.Change{
|
||||
// repo.SetState(domain.IDPIntentStateSucceeded),
|
||||
// repo.SetIDPUser(e.IDPUser),
|
||||
// repo.SetIDPUserID(e.IDPUserID),
|
||||
// repo.SetIDPUsername(e.IDPUserName),
|
||||
// repo.SetUserID(e.UserID),
|
||||
// repo.SetIDPAccessToken(jsonIDPAccessToken),
|
||||
// repo.SetIDPIDToken(e.IDPIDToken),
|
||||
// repo.SetSucceededAt(e.CreationDate()),
|
||||
// repo.SetExpiresAt(e.ExpiresAt),
|
||||
// }
|
||||
|
||||
// _, err = repo.Update(
|
||||
// ctx,
|
||||
// v3_sql.SQLTx(tx),
|
||||
// repo.PrimaryKeyCondition(e.Aggregate().InstanceID, e.Aggregate().ID),
|
||||
// changes...,
|
||||
// )
|
||||
// return err
|
||||
// }), nil
|
||||
// }
|
||||
|
||||
// func (i *idpIntentRelationalProjection) reduceSAMLSucceededEvent(evt eventstore.Event) (*handler.Statement, error) {
|
||||
// e, ok := evt.(*idpintent.SAMLSucceededEvent)
|
||||
// if !ok {
|
||||
// return nil, zerrors.ThrowInternalf(nil, "HANDL-t2uaiv", "reduce.wrong.event.type %s", idpintent.SAMLSucceededEventType)
|
||||
// }
|
||||
// return handler.NewStatement(e, func(ctx context.Context, ex handler.Executer, _ string) error {
|
||||
// tx, ok := ex.(*sql.Tx)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInvalidArgumentf(nil, "HANDL-0QGPXm", "reduce.wrong.db.pool %T", ex)
|
||||
// }
|
||||
// assertion, err := e.Assertion.Value()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// jsonAssertion, ok := assertion.([]byte)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInternal(nil, "HANDL-1TFjTi", "reduce.convertion.json.failed")
|
||||
// }
|
||||
|
||||
// repo := repository.IDPIntentRepository()
|
||||
// _, err = repo.Update(
|
||||
// ctx,
|
||||
// v3_sql.SQLTx(tx),
|
||||
// repo.PrimaryKeyCondition(e.Aggregate().InstanceID, e.Aggregate().ID),
|
||||
// repo.SetState(domain.IDPIntentStateSucceeded),
|
||||
// repo.SetIDPUser(e.IDPUser),
|
||||
// repo.SetIDPUserID(e.IDPUserID),
|
||||
// repo.SetIDPUsername(e.IDPUserName),
|
||||
// repo.SetUserID(e.UserID),
|
||||
// repo.SetAssertion(jsonAssertion),
|
||||
// repo.SetSucceededAt(e.CreationDate()),
|
||||
// repo.SetExpiresAt(e.ExpiresAt),
|
||||
// )
|
||||
// return err
|
||||
// }), nil
|
||||
// }
|
||||
|
||||
// func (i *idpIntentRelationalProjection) reduceSAMLRequestEvent(evt eventstore.Event) (*handler.Statement, error) {
|
||||
// e, ok := evt.(*idpintent.SAMLRequestEvent)
|
||||
// if !ok {
|
||||
// return nil, zerrors.ThrowInternalf(nil, "HANDL-f7O6K2", "reduce.wrong.event.type %s", idpintent.SAMLRequestEventType)
|
||||
// }
|
||||
// return handler.NewStatement(e, func(ctx context.Context, ex handler.Executer, _ string) error {
|
||||
// tx, ok := ex.(*sql.Tx)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInvalidArgumentf(nil, "HANDL-ijgAPJ", "reduce.wrong.db.pool %T", ex)
|
||||
// }
|
||||
|
||||
// repo := repository.IDPIntentRepository()
|
||||
// _, err := repo.Update(
|
||||
// ctx,
|
||||
// v3_sql.SQLTx(tx),
|
||||
// repo.PrimaryKeyCondition(e.Aggregate().InstanceID, e.Aggregate().ID),
|
||||
// repo.SetRequestID(e.RequestID),
|
||||
// )
|
||||
// return err
|
||||
// }), nil
|
||||
// }
|
||||
|
||||
// func (i *idpIntentRelationalProjection) reduceLDAPSucceededEvent(evt eventstore.Event) (*handler.Statement, error) {
|
||||
// e, ok := evt.(*idpintent.LDAPSucceededEvent)
|
||||
// if !ok {
|
||||
// return nil, zerrors.ThrowInternalf(nil, "HANDL-Gw8ddW", "reduce.wrong.event.type %s", idpintent.LDAPSucceededEventType)
|
||||
// }
|
||||
// return handler.NewStatement(e, func(ctx context.Context, ex handler.Executer, _ string) error {
|
||||
// tx, ok := ex.(*sql.Tx)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInvalidArgumentf(nil, "HANDL-tNp8aa", "reduce.wrong.db.pool %T", ex)
|
||||
// }
|
||||
|
||||
// jsonAttributes, err := json.Marshal(e.EntryAttributes)
|
||||
// if err != nil {
|
||||
// return zerrors.ThrowInternal(nil, "HANDL-LuvCvD", "reduce.convertion.json.failed")
|
||||
// }
|
||||
|
||||
// repo := repository.IDPIntentRepository()
|
||||
// _, err = repo.Update(
|
||||
// ctx,
|
||||
// v3_sql.SQLTx(tx),
|
||||
// repo.PrimaryKeyCondition(e.Aggregate().InstanceID, e.Aggregate().ID),
|
||||
// repo.SetState(domain.IDPIntentStateSucceeded),
|
||||
// repo.SetIDPUser(e.IDPUser),
|
||||
// repo.SetIDPUserID(e.IDPUserID),
|
||||
// repo.SetIDPUsername(e.IDPUserName),
|
||||
// repo.SetUserID(e.UserID),
|
||||
// repo.SetIDPEntryAttributes(jsonAttributes),
|
||||
// repo.SetSucceededAt(e.CreationDate()),
|
||||
// repo.SetExpiresAt(e.ExpiresAt),
|
||||
// )
|
||||
// return err
|
||||
// }), nil
|
||||
// }
|
||||
|
||||
// func (i *idpIntentRelationalProjection) reduceFailedEvent(evt eventstore.Event) (*handler.Statement, error) {
|
||||
// e, ok := evt.(*idpintent.FailedEvent)
|
||||
// if !ok {
|
||||
// return nil, zerrors.ThrowInternalf(nil, "HANDL-x3o9LZ", "reduce.wrong.event.type %s", idpintent.FailedEventType)
|
||||
// }
|
||||
// return handler.NewStatement(e, func(ctx context.Context, ex handler.Executer, _ string) error {
|
||||
// tx, ok := ex.(*sql.Tx)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInvalidArgumentf(nil, "HANDL-iqmR8O", "reduce.wrong.db.pool %T", ex)
|
||||
// }
|
||||
|
||||
// repo := repository.IDPIntentRepository()
|
||||
// _, err := repo.Update(
|
||||
// ctx,
|
||||
// v3_sql.SQLTx(tx),
|
||||
// repo.PrimaryKeyCondition(e.Aggregate().InstanceID, e.Aggregate().ID),
|
||||
// repo.SetState(domain.IDPIntentStateFailed),
|
||||
// repo.SetFailReason(e.Reason),
|
||||
// repo.SetFailedAt(e.CreatedAt()),
|
||||
// )
|
||||
// return err
|
||||
// }), nil
|
||||
// }
|
||||
|
||||
// func (i *idpIntentRelationalProjection) reduceConsumedEvent(evt eventstore.Event) (*handler.Statement, error) {
|
||||
// e, ok := evt.(*idpintent.ConsumedEvent)
|
||||
// if !ok {
|
||||
// return nil, zerrors.ThrowInternalf(nil, "HANDL-jHZs6T", "reduce.wrong.event.type %s", idpintent.ConsumedEventType)
|
||||
// }
|
||||
// return handler.NewStatement(e, func(ctx context.Context, ex handler.Executer, _ string) error {
|
||||
// tx, ok := ex.(*sql.Tx)
|
||||
// if !ok {
|
||||
// return zerrors.ThrowInvalidArgumentf(nil, "HANDL-8X9U9w", "reduce.wrong.db.pool %T", ex)
|
||||
// }
|
||||
|
||||
// repo := repository.IDPIntentRepository()
|
||||
// _, err := repo.Delete(
|
||||
// ctx,
|
||||
// v3_sql.SQLTx(tx),
|
||||
// repo.PrimaryKeyCondition(e.Aggregate().InstanceID, e.Aggregate().ID),
|
||||
// )
|
||||
// return err
|
||||
// }), nil
|
||||
// }
|
||||
@@ -101,6 +101,8 @@ var (
|
||||
ProjectGrantRelationalProjection *handler.Handler
|
||||
SessionRelationalProjection *handler.Handler
|
||||
SettingsRelationalProjection *handler.Handler
|
||||
// TODO(adlerhurst): Uncomment once users table is created and FK can be enforced
|
||||
// IDPIntentRelationalProjection *handler.Handler
|
||||
|
||||
ProjectGrantFields *handler.FieldHandler
|
||||
OrgDomainVerifiedFields *handler.FieldHandler
|
||||
@@ -230,6 +232,8 @@ func Create(ctx context.Context, sqlClient *database.DB, es handler.EventStore,
|
||||
AuthorizationRelationalProjection = newAuthorizationRelationalProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["authorizations_relational"]))
|
||||
ProjectGrantRelationalProjection = newProjectGrantRelationalProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["project_grant_relational"]))
|
||||
SessionRelationalProjection = newSessionRelationalProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["session_relational"]))
|
||||
// TODO(adlerhurst): Uncomment once users table is created and FK can be enforced
|
||||
// IDPIntentRelationalProjection = newIDPIntentRelationalProjection(ctx, applyCustomConfig(projectionConfig, config.Customizations["idp_intent_relational"]))
|
||||
|
||||
newProjectionsList()
|
||||
newFieldsList()
|
||||
@@ -427,5 +431,7 @@ func newProjectionsList() {
|
||||
AuthorizationRelationalProjection,
|
||||
ProjectGrantRelationalProjection,
|
||||
SessionRelationalProjection,
|
||||
// TODO(adlerhurst): Uncomment once users table is created and FK can be enforced
|
||||
// IDPIntentRelationalProjection,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user