@@ -91,23 +91,39 @@ func (c *Client) CreateUser(user *v1alpha1.KeycloakUser, realmName string) error
91
91
return c .create (user .KeycloakApiUser , fmt .Sprintf ("realms/%s/users" , realmName ), "user" )
92
92
}
93
93
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 {
95
95
return c .create (
96
- []* v1alpha1.KeycloakUserClientRole {role },
96
+ []* v1alpha1.KeycloakUserRole {role },
97
97
fmt .Sprintf ("realms/%s/users/%s/role-mappings/clients/%s" , realmName , userId , clientID ),
98
98
"user-client-role" ,
99
99
)
100
100
}
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
+ }
101
108
102
109
func (c * Client ) CreateAuthenticatorConfig (authenticatorConfig * v1alpha1.AuthenticatorConfig , realmName , executionID string ) error {
103
110
return c .create (authenticatorConfig , fmt .Sprintf ("realms/%s/authentication/executions/%s/config" , realmName , executionID ), "AuthenticatorConfig" )
104
111
}
105
112
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 {
107
114
err := c .delete (
108
115
fmt .Sprintf ("realms/%s/users/%s/role-mappings/clients/%s" , realmName , userId , clientID ),
109
116
"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 },
111
127
)
112
128
return err
113
129
}
@@ -512,28 +528,52 @@ func (c *Client) ListIdentityProviders(realmName string) ([]*v1alpha1.KeycloakId
512
528
return result .([]* v1alpha1.KeycloakIdentityProvider ), err
513
529
}
514
530
515
- func (c * Client ) ListUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserClientRole , error ) {
531
+ func (c * Client ) ListUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserRole , error ) {
516
532
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
518
534
err := json .Unmarshal (body , & userClientRoles )
519
535
return userClientRoles , err
520
536
})
521
537
if err != nil {
522
538
return nil , err
523
539
}
524
- return objects .([]* v1alpha1.KeycloakUserClientRole ), err
540
+ return objects .([]* v1alpha1.KeycloakUserRole ), err
525
541
}
526
542
527
- func (c * Client ) ListAvailableUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserClientRole , error ) {
543
+ func (c * Client ) ListAvailableUserClientRoles (realmName , clientID , userID string ) ([]* v1alpha1.KeycloakUserRole , error ) {
528
544
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
530
546
err := json .Unmarshal (body , & userClientRoles )
531
547
return userClientRoles , err
532
548
})
533
549
if err != nil {
534
550
return nil , err
535
551
}
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
537
577
}
538
578
539
579
func (c * Client ) ListAuthenticationExecutionsForFlow (flowAlias , realmName string ) ([]* v1alpha1.AuthenticationExecutionInfo , error ) {
@@ -660,10 +700,15 @@ type KeycloakInterface interface {
660
700
DeleteIdentityProvider (alias , realmName string ) error
661
701
ListIdentityProviders (realmName string ) ([]* v1alpha1.KeycloakIdentityProvider , error )
662
702
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
667
712
668
713
ListAuthenticationExecutionsForFlow (flowAlias , realmName string ) ([]* v1alpha1.AuthenticationExecutionInfo , error )
669
714
0 commit comments