Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Commit efe359d

Browse files
authored
Merge pull request #97 from matskiv/INTLY-2987-cp-v1.7
INTLY-2987 - add users realmRoles reconciliation (v1.7)
2 parents 2eac696 + 720689b commit efe359d

File tree

10 files changed

+430
-72
lines changed

10 files changed

+430
-72
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CONSUMER_NAMESPACES=${NAMESPACE}
44
PROJECT=keycloak-operator
55
REG=quay.io
66
SHELL=/bin/bash
7-
TAG=v1.7.5
7+
TAG=v1.7.6
88
PKG=github.com/integr8ly/keycloak-operator
99
TEST_DIRS?=$(shell sh -c "find $(TOP_SRC_DIRS) -name \\*_test.go -exec dirname {} \\; | sort | uniq")
1010
TEST_POD_NAME=keycloak-operator-test

deploy/operator.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414
spec:
1515
containers:
1616
- name: keycloak-operator
17-
image: quay.io/integreatly/keycloak-operator:v1.7.5
17+
image: quay.io/integreatly/keycloak-operator:v1.7.6
1818
ports:
1919
- containerPort: 60000
2020
name: metrics

deploy/test-pod.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ spec:
66
restartPolicy: Never
77
containers:
88
- name: keycloak-operator-test
9-
image: quay.io/integreatly/keycloak-operator:v1.7.5
9+
image: quay.io/integreatly/keycloak-operator:v1.7.6
1010
imagePullPolicy: Always
1111
command: ["/go-test.sh"]
1212
env:

pkg/apis/aerogear/v1alpha1/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ type KeycloakUserPair struct {
154154
SpecUser *KeycloakUser
155155
}
156156

157-
type KeycloakUserClientRole struct {
157+
type KeycloakUserRole struct {
158158
ID string `json:"id,omitempty"`
159159
Name string `json:"name,omitempty"`
160160
Description string `json:"description,omitempty"`

pkg/apis/aerogear/v1alpha1/zz_generated.deepcopy.go

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/keycloak/client.go

+59-14
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,39 @@ func (c *Client) CreateUser(user *v1alpha1.KeycloakUser, realmName string) error
9191
return c.create(user.KeycloakApiUser, fmt.Sprintf("realms/%s/users", realmName), "user")
9292
}
9393

94-
func (c *Client) CreateUserClientRole(role *v1alpha1.KeycloakUserClientRole, realmName, clientID, userId string) error {
94+
func (c *Client) CreateUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userId string) error {
9595
return c.create(
96-
[]*v1alpha1.KeycloakUserClientRole{role},
96+
[]*v1alpha1.KeycloakUserRole{role},
9797
fmt.Sprintf("realms/%s/users/%s/role-mappings/clients/%s", realmName, userId, clientID),
9898
"user-client-role",
9999
)
100100
}
101+
func (c *Client) CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userId string) error {
102+
return c.create(
103+
[]*v1alpha1.KeycloakUserRole{role},
104+
fmt.Sprintf("realms/%s/users/%s/role-mappings/realm", realmName, userId),
105+
"user-realm-role",
106+
)
107+
}
101108

102109
func (c *Client) CreateAuthenticatorConfig(authenticatorConfig *v1alpha1.AuthenticatorConfig, realmName, executionID string) error {
103110
return c.create(authenticatorConfig, fmt.Sprintf("realms/%s/authentication/executions/%s/config", realmName, executionID), "AuthenticatorConfig")
104111
}
105112

106-
func (c *Client) DeleteUserClientRole(role *v1alpha1.KeycloakUserClientRole, realmName, clientID, userId string) error {
113+
func (c *Client) DeleteUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userId string) error {
107114
err := c.delete(
108115
fmt.Sprintf("realms/%s/users/%s/role-mappings/clients/%s", realmName, userId, clientID),
109116
"user-client-role",
110-
[]*v1alpha1.KeycloakUserClientRole{role},
117+
[]*v1alpha1.KeycloakUserRole{role},
118+
)
119+
return err
120+
}
121+
122+
func (c *Client) DeleteUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userId string) error {
123+
err := c.delete(
124+
fmt.Sprintf("realms/%s/users/%s/role-mappings/realm", realmName, userId),
125+
"user-realm-role",
126+
[]*v1alpha1.KeycloakUserRole{role},
111127
)
112128
return err
113129
}
@@ -512,28 +528,52 @@ func (c *Client) ListIdentityProviders(realmName string) ([]*v1alpha1.KeycloakId
512528
return result.([]*v1alpha1.KeycloakIdentityProvider), err
513529
}
514530

515-
func (c *Client) ListUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserClientRole, error) {
531+
func (c *Client) ListUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserRole, error) {
516532
objects, err := c.list("realms/"+realmName+"/users/"+userID+"/role-mappings/clients/"+clientID, "userClientRoles", func(body []byte) (t T, e error) {
517-
var userClientRoles []*v1alpha1.KeycloakUserClientRole
533+
var userClientRoles []*v1alpha1.KeycloakUserRole
518534
err := json.Unmarshal(body, &userClientRoles)
519535
return userClientRoles, err
520536
})
521537
if err != nil {
522538
return nil, err
523539
}
524-
return objects.([]*v1alpha1.KeycloakUserClientRole), err
540+
return objects.([]*v1alpha1.KeycloakUserRole), err
525541
}
526542

527-
func (c *Client) ListAvailableUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserClientRole, error) {
543+
func (c *Client) ListAvailableUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserRole, error) {
528544
objects, err := c.list("realms/"+realmName+"/users/"+userID+"/role-mappings/clients/"+clientID+"/available", "userClientRoles", func(body []byte) (t T, e error) {
529-
var userClientRoles []*v1alpha1.KeycloakUserClientRole
545+
var userClientRoles []*v1alpha1.KeycloakUserRole
530546
err := json.Unmarshal(body, &userClientRoles)
531547
return userClientRoles, err
532548
})
533549
if err != nil {
534550
return nil, err
535551
}
536-
return objects.([]*v1alpha1.KeycloakUserClientRole), err
552+
return objects.([]*v1alpha1.KeycloakUserRole), err
553+
}
554+
555+
func (c *Client) ListUserRealmRoles(realmName, userID string) ([]*v1alpha1.KeycloakUserRole, error) {
556+
objects, err := c.list("realms/"+realmName+"/users/"+userID+"/role-mappings/realm", "userRealmRoles", func(body []byte) (t T, e error) {
557+
var userRealmRoles []*v1alpha1.KeycloakUserRole
558+
err := json.Unmarshal(body, &userRealmRoles)
559+
return userRealmRoles, err
560+
})
561+
if err != nil {
562+
return nil, err
563+
}
564+
return objects.([]*v1alpha1.KeycloakUserRole), err
565+
}
566+
567+
func (c *Client) ListAvailableUserRealmRoles(realmName, userID string) ([]*v1alpha1.KeycloakUserRole, error) {
568+
objects, err := c.list("realms/"+realmName+"/users/"+userID+"/role-mappings/realm/available", "userClientRoles", func(body []byte) (t T, e error) {
569+
var userRealmRoles []*v1alpha1.KeycloakUserRole
570+
err := json.Unmarshal(body, &userRealmRoles)
571+
return userRealmRoles, err
572+
})
573+
if err != nil {
574+
return nil, err
575+
}
576+
return objects.([]*v1alpha1.KeycloakUserRole), err
537577
}
538578

539579
func (c *Client) ListAuthenticationExecutionsForFlow(flowAlias, realmName string) ([]*v1alpha1.AuthenticationExecutionInfo, error) {
@@ -660,10 +700,15 @@ type KeycloakInterface interface {
660700
DeleteIdentityProvider(alias, realmName string) error
661701
ListIdentityProviders(realmName string) ([]*v1alpha1.KeycloakIdentityProvider, error)
662702

663-
CreateUserClientRole(role *v1alpha1.KeycloakUserClientRole, realmName, clientID, userId string) error
664-
ListUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserClientRole, error)
665-
ListAvailableUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserClientRole, error)
666-
DeleteUserClientRole(role *v1alpha1.KeycloakUserClientRole, realmName, clientID, userID string) error
703+
CreateUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userId string) error
704+
ListUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserRole, error)
705+
ListAvailableUserClientRoles(realmName, clientID, userID string) ([]*v1alpha1.KeycloakUserRole, error)
706+
DeleteUserClientRole(role *v1alpha1.KeycloakUserRole, realmName, clientID, userID string) error
707+
708+
CreateUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userId string) error
709+
ListUserRealmRoles(realmName, userID string) ([]*v1alpha1.KeycloakUserRole, error)
710+
ListAvailableUserRealmRoles(realmName, userID string) ([]*v1alpha1.KeycloakUserRole, error)
711+
DeleteUserRealmRole(role *v1alpha1.KeycloakUserRole, realmName, userID string) error
667712

668713
ListAuthenticationExecutionsForFlow(flowAlias, realmName string) ([]*v1alpha1.AuthenticationExecutionInfo, error)
669714

0 commit comments

Comments
 (0)