@@ -111,23 +111,39 @@ func (c *Client) GetUserFederatedIdentities(userID string, realmName string) ([]
111
111
return result .([]v1alpha1.FederatedIdentity ), err
112
112
}
113
113
114
- func (c * Client ) CreateUserClientRole (role * v1alpha1.KeycloakUserClientRole , realmName , clientID , userId string ) error {
114
+ func (c * Client ) CreateUserClientRole (role * v1alpha1.KeycloakUserRole , realmName , clientID , userId string ) error {
115
115
return c .create (
116
- []* v1alpha1.KeycloakUserClientRole {role },
116
+ []* v1alpha1.KeycloakUserRole {role },
117
117
fmt .Sprintf ("realms/%s/users/%s/role-mappings/clients/%s" , realmName , userId , clientID ),
118
118
"user-client-role" ,
119
119
)
120
120
}
121
+ func (c * Client ) CreateUserRealmRole (role * v1alpha1.KeycloakUserRole , realmName , userId string ) error {
122
+ return c .create (
123
+ []* v1alpha1.KeycloakUserRole {role },
124
+ fmt .Sprintf ("realms/%s/users/%s/role-mappings/realm" , realmName , userId ),
125
+ "user-realm-role" ,
126
+ )
127
+ }
121
128
122
129
func (c * Client ) CreateAuthenticatorConfig (authenticatorConfig * v1alpha1.AuthenticatorConfig , realmName , executionID string ) error {
123
130
return c .create (authenticatorConfig , fmt .Sprintf ("realms/%s/authentication/executions/%s/config" , realmName , executionID ), "AuthenticatorConfig" )
124
131
}
125
132
126
- func (c * Client ) DeleteUserClientRole (role * v1alpha1.KeycloakUserClientRole , realmName , clientID , userId string ) error {
133
+ func (c * Client ) DeleteUserClientRole (role * v1alpha1.KeycloakUserRole , realmName , clientID , userId string ) error {
127
134
err := c .delete (
128
135
fmt .Sprintf ("realms/%s/users/%s/role-mappings/clients/%s" , realmName , userId , clientID ),
129
136
"user-client-role" ,
130
- []* v1alpha1.KeycloakUserClientRole {role },
137
+ []* v1alpha1.KeycloakUserRole {role },
138
+ )
139
+ return err
140
+ }
141
+
142
+ func (c * Client ) DeleteUserRealmRole (role * v1alpha1.KeycloakUserRole , realmName , userId string ) error {
143
+ err := c .delete (
144
+ fmt .Sprintf ("realms/%s/users/%s/role-mappings/realm" , realmName , userId ),
145
+ "user-realm-role" ,
146
+ []* v1alpha1.KeycloakUserRole {role },
131
147
)
132
148
return err
133
149
}
@@ -532,28 +548,52 @@ func (c *Client) ListIdentityProviders(realmName string) ([]*v1alpha1.KeycloakId
532
548
return result .([]* v1alpha1.KeycloakIdentityProvider ), err
533
549
}
534
550
535
- func (c * Client ) ListUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserClientRole , error ) {
551
+ func (c * Client ) ListUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserRole , error ) {
536
552
objects , err := c .list ("realms/" + realmName + "/users/" + userID + "/role-mappings/clients/" + clientID , "userClientRoles" , func (body []byte ) (t T , e error ) {
537
- var userClientRoles []* v1alpha1.KeycloakUserClientRole
553
+ var userClientRoles []* v1alpha1.KeycloakUserRole
538
554
err := json .Unmarshal (body , & userClientRoles )
539
555
return userClientRoles , err
540
556
})
541
557
if err != nil {
542
558
return nil , err
543
559
}
544
- return objects .([]* v1alpha1.KeycloakUserClientRole ), err
560
+ return objects .([]* v1alpha1.KeycloakUserRole ), err
545
561
}
546
562
547
- func (c * Client ) ListAvailableUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserClientRole , error ) {
563
+ func (c * Client ) ListAvailableUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserRole , error ) {
548
564
objects , err := c .list ("realms/" + realmName + "/users/" + userID + "/role-mappings/clients/" + clientID + "/available" , "userClientRoles" , func (body []byte ) (t T , e error ) {
549
- var userClientRoles []* v1alpha1.KeycloakUserClientRole
565
+ var userClientRoles []* v1alpha1.KeycloakUserRole
550
566
err := json .Unmarshal (body , & userClientRoles )
551
567
return userClientRoles , err
552
568
})
553
569
if err != nil {
554
570
return nil , err
555
571
}
556
- return objects .([]* v1alpha1.KeycloakUserClientRole ), err
572
+ return objects .([]* v1alpha1.KeycloakUserRole ), err
573
+ }
574
+
575
+ func (c * Client ) ListUserRealmRoles (realmName , userID string ) ([]* v1alpha1.KeycloakUserRole , error ) {
576
+ objects , err := c .list ("realms/" + realmName + "/users/" + userID + "/role-mappings/realm" , "userRealmRoles" , func (body []byte ) (t T , e error ) {
577
+ var userRealmRoles []* v1alpha1.KeycloakUserRole
578
+ err := json .Unmarshal (body , & userRealmRoles )
579
+ return userRealmRoles , err
580
+ })
581
+ if err != nil {
582
+ return nil , err
583
+ }
584
+ return objects .([]* v1alpha1.KeycloakUserRole ), err
585
+ }
586
+
587
+ func (c * Client ) ListAvailableUserRealmRoles (realmName , userID string ) ([]* v1alpha1.KeycloakUserRole , error ) {
588
+ objects , err := c .list ("realms/" + realmName + "/users/" + userID + "/role-mappings/realm/available" , "userClientRoles" , func (body []byte ) (t T , e error ) {
589
+ var userRealmRoles []* v1alpha1.KeycloakUserRole
590
+ err := json .Unmarshal (body , & userRealmRoles )
591
+ return userRealmRoles , err
592
+ })
593
+ if err != nil {
594
+ return nil , err
595
+ }
596
+ return objects .([]* v1alpha1.KeycloakUserRole ), err
557
597
}
558
598
559
599
func (c * Client ) ListAuthenticationExecutionsForFlow (flowAlias , realmName string ) ([]* v1alpha1.AuthenticationExecutionInfo , error ) {
@@ -683,10 +723,15 @@ type KeycloakInterface interface {
683
723
DeleteIdentityProvider (alias , realmName string ) error
684
724
ListIdentityProviders (realmName string ) ([]* v1alpha1.KeycloakIdentityProvider , error )
685
725
686
- CreateUserClientRole (role * v1alpha1.KeycloakUserClientRole , realmName , clientID , userId string ) error
687
- ListUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserClientRole , error )
688
- ListAvailableUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserClientRole , error )
689
- DeleteUserClientRole (role * v1alpha1.KeycloakUserClientRole , realmName , clientID , userID string ) error
726
+ CreateUserClientRole (role * v1alpha1.KeycloakUserRole , realmName , clientID , userId string ) error
727
+ ListUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserRole , error )
728
+ ListAvailableUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserRole , error )
729
+ DeleteUserClientRole (role * v1alpha1.KeycloakUserRole , realmName , clientID , userID string ) error
730
+
731
+ CreateUserRealmRole (role * v1alpha1.KeycloakUserRole , realmName , userId string ) error
732
+ ListUserRealmRoles (realmName , userID string ) ([]* v1alpha1.KeycloakUserRole , error )
733
+ ListAvailableUserRealmRoles (realmName , userID string ) ([]* v1alpha1.KeycloakUserRole , error )
734
+ DeleteUserRealmRole (role * v1alpha1.KeycloakUserRole , realmName , userID string ) error
690
735
691
736
ListAuthenticationExecutionsForFlow (flowAlias , realmName string ) ([]* v1alpha1.AuthenticationExecutionInfo , error )
692
737
0 commit comments