Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions api/management/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ type CtxKeyConfigRepresentation struct {
Onboarding CtxKeyOnboardingRepresentation `json:"onboarding"`
Accreditation CtxKeyAccreditationRepresentation `json:"accreditation"`
AutoVoucher CtxKeyAutoVoucherRepresentation `json:"autovoucher"`
IDNow CtxKeyIDNowRepresentation `json:"idnow"`
}

// CtxKeyOnboardingRepresentation struct
Expand All @@ -430,6 +431,11 @@ type CtxKeyAutoVoucherRepresentation struct {
BilledRealm *string `json:"billedRealm"`
}

// CtxKeyIDNowRepresentation struct
type CtxKeyIDNowRepresentation struct {
DesktopRedirectURI *string `json:"desktopRedirectUri"`
}

// RequiredAction type
type RequiredAction string

Expand Down Expand Up @@ -1472,6 +1478,7 @@ func ConvertToAPIContextKeyConfig(config configuration.ContextKeyConfiguration)
Onboarding: ConvertToAPIContextKeyOnboarding(config.Onboarding),
Accreditation: ConvertToAPIContextKeyAccreditation(config.Accreditation),
AutoVoucher: ConvertToAPIContextKeyAutovoucher(config.AutoVoucher),
IDNow: ConvertToAPIContextKeyIDNow(config.IDNow),
}
}

Expand All @@ -1480,12 +1487,14 @@ func (c *CtxKeyConfigRepresentation) ToDatabaseModel() configuration.ContextKeyC
onboarding := c.Onboarding.ToDatabaseModel()
accreditation := c.Accreditation.ToDatabaseModel()
autovoucher := c.AutoVoucher.ToDatabaseModel()
idnow := c.IDNow.ToDatabaseModel()

return configuration.ContextKeyConfiguration{
IdentificationURI: c.IdentificationURI,
Onboarding: onboarding,
Accreditation: accreditation,
AutoVoucher: autovoucher,
IDNow: idnow,
}
}

Expand Down Expand Up @@ -1585,3 +1594,27 @@ func (c *CtxKeyAutoVoucherRepresentation) Validate() error {
ValidateParameterRegExp("billedRealm", c.BilledRealm, constants.RegExpRealmName, false).
Status()
}

// ConvertToAPIContextKeyIDNow converts context key idnow configuration from database model to API model
func ConvertToAPIContextKeyIDNow(idnowCfg *configuration.ContextKeyConfIDNow) CtxKeyIDNowRepresentation {
if idnowCfg == nil {
return CtxKeyIDNowRepresentation{}
}
return CtxKeyIDNowRepresentation{
DesktopRedirectURI: idnowCfg.DesktopRedirectURI,
}
}

// ToDatabaseModel converts a context key autovoucher configuration to the database model
func (c *CtxKeyIDNowRepresentation) ToDatabaseModel() *configuration.ContextKeyConfIDNow {
return &configuration.ContextKeyConfIDNow{
DesktopRedirectURI: c.DesktopRedirectURI,
}
}

// Validate is a validator for CtxKeyAutoVoucherRepresentation
func (c *CtxKeyIDNowRepresentation) Validate() error {
return validation.NewParameterValidator().
ValidateParameterRegExp("desktopRedirectUri", c.DesktopRedirectURI, constants.RegExpRedirectURI, false).
Status()
}
33 changes: 33 additions & 0 deletions api/management/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ func TestContextKeyConvertions(t *testing.T) {
IdentificationURI: nil,
AutoVoucher: &configuration.ContextKeyConfAutovoucher{},
Accreditation: &configuration.ContextKeyConfAccreditation{},
IDNow: &configuration.ContextKeyConfIDNow{},
})
assert.Nil(t, config.Accreditation.EmailThemeRealm)
assert.Nil(t, config.AutoVoucher.ServiceType)
Expand All @@ -1287,6 +1288,7 @@ func TestContextKeyConvertions(t *testing.T) {
assert.Nil(t, config.Onboarding.ClientID)
assert.Nil(t, config.Onboarding.RedirectURI)
assert.Nil(t, config.Onboarding.IsRedirectMode)
assert.Nil(t, config.IDNow.DesktopRedirectURI)
})

t.Run("Config fields are nil empty config", func(t *testing.T) {
Expand All @@ -1300,6 +1302,7 @@ func TestContextKeyConvertions(t *testing.T) {
assert.Nil(t, config.Onboarding.ClientID)
assert.Nil(t, config.Onboarding.RedirectURI)
assert.Nil(t, config.Onboarding.IsRedirectMode)
assert.Nil(t, config.IDNow.DesktopRedirectURI)
})
}

Expand Down Expand Up @@ -1524,3 +1527,33 @@ func TestConvertToThemeConfiguration(t *testing.T) {
assert.Equal(t, expectedFavicon, *res.Favicon)
})
}

func TestContextKeyIDNowConversions(t *testing.T) {
idnowConfig := configuration.ContextKeyConfIDNow{
DesktopRedirectURI: ptr("http://redirect.uri/after/idnow"),
}

apiConfig := ConvertToAPIContextKeyIDNow(&idnowConfig)
assert.Equal(t, idnowConfig.DesktopRedirectURI, apiConfig.DesktopRedirectURI)

dbConfig := apiConfig.ToDatabaseModel()
assert.Equal(t, idnowConfig.DesktopRedirectURI, dbConfig.DesktopRedirectURI)
}

func TestValidateCtxKeyIDNowRepresentation(t *testing.T) {
t.Run("Valid configuration", func(t *testing.T) {
config := configuration.ContextKeyConfIDNow{
DesktopRedirectURI: ptr("http://redirect.uri?theme=mytheme"),
}
apiConfig := ConvertToAPIContextKeyIDNow(&config)
assert.Nil(t, apiConfig.Validate())
})

t.Run("Invalid configuration", func(t *testing.T) {
config := configuration.ContextKeyConfIDNow{
DesktopRedirectURI: ptr("not.a.valid.uri"),
}
apiConfig := ConvertToAPIContextKeyIDNow(&config)
assert.NotNil(t, apiConfig.Validate())
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cloudtrust/keycloak-bridge
go 1.25.3

require (
github.com/cloudtrust/common-service/v2 v2.16.0
github.com/cloudtrust/common-service/v2 v2.16.1-0.20260119081002-90e64c424e8f
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update this before merging

github.com/cloudtrust/httpclient v1.6.0
github.com/cloudtrust/kafka-client v1.7.2
github.com/cloudtrust/keycloak-client/v2 v2.17.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
github.com/IBM/sarama v1.46.3/go.mod h1:GTUYiF9DMOZVe3FwyGT+dtSPceGFIgA+sPc5u6CBwko=
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
github.com/cloudtrust/common-service/v2 v2.16.0 h1:1ckA+qKOODQj6ygkH0x0qZogk4HmF1DO2UD6g4zOG5M=
github.com/cloudtrust/common-service/v2 v2.16.0/go.mod h1:2cFLwdEsh2D4mS3mq4K8qWoTYBRLp/gKtTuSP2nglW8=
github.com/cloudtrust/common-service/v2 v2.16.1-0.20260119081002-90e64c424e8f h1:3P7W9XRhW25BCer535KdXm19a8tYk9gxgkP8smUorSg=
github.com/cloudtrust/common-service/v2 v2.16.1-0.20260119081002-90e64c424e8f/go.mod h1:2cFLwdEsh2D4mS3mq4K8qWoTYBRLp/gKtTuSP2nglW8=
github.com/cloudtrust/httpclient v1.6.0 h1:/E/y2wZNyUIjADbP3RLI2pLTWdNvcFSLe1MeRD6RlN4=
github.com/cloudtrust/httpclient v1.6.0/go.mod h1:CK0idOHAQ2CiN2GFOwIYP5hDl2tfUgGdTI9n7Ygbnrs=
github.com/cloudtrust/kafka-client v1.7.2 h1:wezQkWb4nMA2u6PP+x8e54GrZTvEOHQkFuyOziB7Ea0=
Expand Down
1 change: 1 addition & 0 deletions pkg/validation/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type EventsReporterModule interface {
// ConfigurationDBModule is the interface of the configuration module.
type ConfigurationDBModule interface {
GetAdminConfiguration(context.Context, string) (configuration.RealmAdminConfiguration, error)
GetContextKeysForCustomerRealm(ctx context.Context, customerRealm string) ([]configuration.RealmContextKey, error)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to add this ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not needed and was a leftover from a past version, thanks for pointing this out

}

// AccreditationsServiceClient interface
Expand Down
15 changes: 15 additions & 0 deletions pkg/validation/mock/component.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ github.com/IBM/sarama
# github.com/VividCortex/gohistogram v1.0.0
## explicit
github.com/VividCortex/gohistogram
# github.com/cloudtrust/common-service/v2 v2.16.0
# github.com/cloudtrust/common-service/v2 v2.16.1-0.20260119081002-90e64c424e8f
## explicit; go 1.25.3
github.com/cloudtrust/common-service/v2
github.com/cloudtrust/common-service/v2/configuration
Expand Down