Skip to content

Commit

Permalink
[CLOUDTRUST-1692] Self-service configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
harture committed Oct 17, 2019
1 parent 09c2077 commit 34df488
Show file tree
Hide file tree
Showing 30 changed files with 989 additions and 306 deletions.
9 changes: 9 additions & 0 deletions api/account/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ type CredentialRepresentation struct {
Temporary *bool `json:"temporary,omitempty"`
}

// Configuration struct
type Configuration struct {
ShowAuthenticatorsTab *bool `json:"show_authenticators_tab"`
ShowPasswordTab *bool `json:"show_password_tab"`
ShowMailEditing *bool `json:"show_mail_editing"`
ShowAccountDeletionButton *bool `json:"show_account_deletion_button"`
}

// UpdatePasswordBody is the definition of the expected body content of UpdatePassword method
type UpdatePasswordBody struct {
CurrentPassword string `json:"currentPassword"`
NewPassword string `json:"newPassword"`
ConfirmPassword string `json:"confirmPassword"`
}

// LabelBody struct
type LabelBody struct {
Label string `json:"label,omitempty"`
}
Expand Down
23 changes: 23 additions & 0 deletions api/account/swagger-api_account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ paths:
description: Bad parameters (same old and new passwords, different new and confirm passwords, ...)
403:
description: Caller is not allowed to change the password
/account/configuration:
get:
tags:
- Credentials
summary: Get self-service configuration
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Configuration'
/account/credentials/registrators:
get:
tags:
Expand Down Expand Up @@ -184,6 +196,17 @@ components:
type: string
phoneNumber:
type: string
Configuration:
type: object
properties:
show_authenticators_tab:
type: boolean
show_password_tab:
type: boolean
show_mail_editing:
type: boolean
show_account_deletion_button:
type: boolean
securitySchemes:
openId:
type: openIdConnect
Expand Down
46 changes: 26 additions & 20 deletions api/management/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// UserRepresentation struct
type UserRepresentation struct {
Id *string `json:"id,omitempty"`
ID *string `json:"id,omitempty"`
Username *string `json:"username,omitempty"`
Email *string `json:"email,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Expand All @@ -37,7 +37,7 @@ type UsersPageRepresentation struct {

// RealmRepresentation struct
type RealmRepresentation struct {
Id *string `json:"id,omitempty"`
ID *string `json:"id,omitempty"`
KeycloakVersion *string `json:"keycloakVersion,omitempty"`
Realm *string `json:"realm,omitempty"`
DisplayName *string `json:"displayName,omitempty"`
Expand All @@ -46,17 +46,17 @@ type RealmRepresentation struct {

// ClientRepresentation struct
type ClientRepresentation struct {
Id *string `json:"id,omitempty"`
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
BaseUrl *string `json:"baseUrl,omitempty"`
ClientId *string `json:"clientId,omitempty"`
BaseURL *string `json:"baseUrl,omitempty"`
ClientID *string `json:"clientId,omitempty"`
Protocol *string `json:"protocol,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}

// CredentialRepresentation struct
type CredentialRepresentation struct {
Id *string `json:"id,omitempty"`
ID *string `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
UserLabel *string `json:"userLabel,omitempty"`
CreatedDate *int64 `json:"createdDate,omitempty"`
Expand All @@ -69,15 +69,15 @@ type CredentialRepresentation struct {
type RoleRepresentation struct {
ClientRole *bool `json:"clientRole,omitempty"`
Composite *bool `json:"composite,omitempty"`
ContainerId *string `json:"containerId,omitempty"`
ContainerID *string `json:"containerId,omitempty"`
Description *string `json:"description,omitempty"`
Id *string `json:"id,omitempty"`
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
}

// GroupRepresentation struct
type GroupRepresentation struct {
Id *string `json:"id,omitempty"`
ID *string `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
}

Expand All @@ -88,10 +88,16 @@ type PasswordRepresentation struct {

// RealmCustomConfiguration struct
type RealmCustomConfiguration struct {
DefaultClientId *string `json:"default_client_id,omitempty"`
DefaultRedirectUri *string `json:"default_redirect_uri,omitempty"`
SelfAuthenticatorMgmtEnabled *bool `json:"self_authenticator_mgmt_enabled"`
SelfPasswordChangeEnabled *bool `json:"self_password_change_enabled"`
DefaultClientID *string `json:"default_client_id"`
DefaultRedirectURI *string `json:"default_redirect_uri"`
APISelfAuthenticatorDeletionEnabled *bool `json:"api_self_authenticator_deletion_enabled"`
APISelfPasswordChangeEnabled *bool `json:"api_self_password_change_enabled"`
APISelfMailEditingEnabled *bool `json:"api_self_mail_editing_enabled"`
APISelfAccountDeletionEnabled *bool `json:"api_self_account_deletion_enabled"`
ShowAuthenticatorsTab *bool `json:"show_authenticators_tab"`
ShowPasswordTab *bool `json:"show_password_tab"`
ShowMailEditing *bool `json:"show_mail_editing"`
ShowAccountDeletionButton *bool `json:"show_account_deletion_button"`
}

// RequiredAction type
Expand All @@ -100,7 +106,7 @@ type RequiredAction string
// ConvertCredential creates an API credential from a KC credential
func ConvertCredential(credKc *kc.CredentialRepresentation) CredentialRepresentation {
var cred CredentialRepresentation
cred.Id = credKc.Id
cred.ID = credKc.Id
cred.Type = credKc.Type
cred.UserLabel = credKc.UserLabel
cred.CreatedDate = credKc.CreatedDate
Expand All @@ -115,7 +121,7 @@ func ConvertCredential(credKc *kc.CredentialRepresentation) CredentialRepresenta
func ConvertToAPIUser(userKc kc.UserRepresentation) UserRepresentation {
var userRep UserRepresentation

userRep.Id = userKc.Id
userRep.ID = userKc.Id
userRep.Username = userKc.Username
userRep.Email = userKc.Email
userRep.Enabled = userKc.Enabled
Expand Down Expand Up @@ -228,7 +234,7 @@ func ConvertToKCUser(user UserRepresentation) kc.UserRepresentation {

// Validate is a validator for UserRepresentation
func (user UserRepresentation) Validate() error {
if user.Id != nil && !matchesRegExp(*user.Id, RegExpID) {
if user.ID != nil && !matchesRegExp(*user.ID, RegExpID) {
return errors.New(internal.MsgErrInvalidParam + "." + internal.UserID)
}

Expand Down Expand Up @@ -289,7 +295,7 @@ func (user UserRepresentation) Validate() error {

// Validate is a validator for RoleRepresentation
func (role RoleRepresentation) Validate() error {
if role.Id != nil && !matchesRegExp(*role.Id, RegExpID) {
if role.ID != nil && !matchesRegExp(*role.ID, RegExpID) {
return errors.New(internal.MsgErrInvalidParam + "." + internal.RoleID)
}

Expand All @@ -301,7 +307,7 @@ func (role RoleRepresentation) Validate() error {
return errors.New(internal.MsgErrInvalidParam + "." + internal.Description)
}

if role.ContainerId != nil && !matchesRegExp(*role.ContainerId, RegExpID) {
if role.ContainerID != nil && !matchesRegExp(*role.ContainerID, RegExpID) {
return errors.New(internal.MsgErrInvalidParam + "." + internal.ContainerID)
}

Expand All @@ -319,11 +325,11 @@ func (password PasswordRepresentation) Validate() error {

// Validate is a validator for RealmCustomConfiguration
func (config RealmCustomConfiguration) Validate() error {
if config.DefaultClientId != nil && !matchesRegExp(*config.DefaultClientId, RegExpClientID) {
if config.DefaultClientID != nil && !matchesRegExp(*config.DefaultClientID, RegExpClientID) {
return errors.New(internal.MsgErrInvalidParam + "." + internal.DefaultClientID)
}

if config.DefaultRedirectUri != nil && !matchesRegExp(*config.DefaultRedirectUri, RegExpRedirectURI) {
if config.DefaultRedirectURI != nil && !matchesRegExp(*config.DefaultRedirectURI, RegExpRedirectURI) {
return errors.New(internal.MsgErrInvalidParam + "." + internal.DefaultRedirectURI)
}

Expand Down
22 changes: 11 additions & 11 deletions api/management/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestConvertCredential(t *testing.T) {
credKc.CredentialData = nil

assert.Equal(t, credKc.Type, ConvertCredential(&credKc).Type)
assert.Equal(t, credKc.Id, ConvertCredential(&credKc).Id)
assert.Equal(t, credKc.Id, ConvertCredential(&credKc).ID)
assert.Nil(t, ConvertCredential(&credKc).CredentialData)

credKc.CredentialData = &configKc
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestValidateUserRepresentation(t *testing.T) {
users = append(users, createValidUserRepresentation())
}

users[0].Id = &id
users[0].ID = &id
users[1].Username = &username
users[2].Email = &email
users[3].PhoneNumber = &phoneNumber
Expand Down Expand Up @@ -182,10 +182,10 @@ func TestValidateRoleRepresentation(t *testing.T) {
roles = append(roles, createValidRoleRepresentation())
}

roles[0].Id = &id
roles[0].ID = &id
roles[1].Name = &name
roles[2].Description = &description
roles[3].ContainerId = &id
roles[3].ContainerID = &id

for _, role := range roles {
assert.NotNil(t, role.Validate())
Expand Down Expand Up @@ -220,8 +220,8 @@ func TestValidateRealmCustomConfiguration(t *testing.T) {
configs = append(configs, createValidRealmCustomConfiguration())
}

configs[0].DefaultClientId = &defaultClientID
configs[1].DefaultRedirectUri = &defaultRedirectURI
configs[0].DefaultClientID = &defaultClientID
configs[1].DefaultRedirectURI = &defaultRedirectURI

for _, config := range configs {
assert.NotNil(t, config.Validate())
Expand Down Expand Up @@ -255,7 +255,7 @@ func createValidUserRepresentation() UserRepresentation {
locale := "en"

var user = UserRepresentation{}
user.Id = &id
user.ID = &id
user.Username = &username
user.Email = &email
user.Enabled = &boolTrue
Expand All @@ -281,10 +281,10 @@ func createValidRoleRepresentation() RoleRepresentation {
boolTrue := true

var role = RoleRepresentation{}
role.Id = &id
role.ID = &id
role.Name = &name
role.Description = &description
role.ContainerId = &id
role.ContainerID = &id
role.ClientRole = &boolTrue
role.Composite = &boolTrue

Expand All @@ -304,8 +304,8 @@ func createValidRealmCustomConfiguration() RealmCustomConfiguration {
defaultRedirectURI := "http://company.com"

return RealmCustomConfiguration{
DefaultClientId: &defaultClientID,
DefaultRedirectUri: &defaultRedirectURI,
DefaultClientID: &defaultClientID,
DefaultRedirectURI: &defaultRedirectURI,
}
}

Expand Down
18 changes: 17 additions & 1 deletion api/management/swagger-api_management.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,26 @@ components:
type: string
default_redirect_uri:
type: string
api_self_authenticator_deletion_enabled:
type: boolean
api_self_password_change_enabled:
type: boolean
api_self_mail_editing_enabled:
type: boolean
api_self_account_deletion_enabled:
type: boolean
show_authenticators_tab:
type: boolean
show_password_tab:
type: boolean
show_mail_editing:
type: boolean
show_account_deletion_button:
type: boolean
securitySchemes:
openId:
type: openIdConnect
openIdConnectUrl: http://toto.com/.well-known/openid-configuration
security:
- openId:
- todo
- todo
Loading

0 comments on commit 34df488

Please sign in to comment.