Browse Source

[CLOUDTRUST-2109] authorizations management

master
harture 6 years ago
committed by GitHub
parent
commit
a7d644415b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      Gopkg.lock
  2. 2
      Gopkg.toml
  3. 42
      groups.go

10
Gopkg.lock

@ -2,15 +2,15 @@
[[projects]] [[projects]]
digest = "1:5642d26fba562723106466a33c8fb7710f32dd608d54491e499b76c82387bcc7" branch = "master"
digest = "1:c3e6e91aafe6e3a12e3669b77f8fd608ddf8e61a727858ce50811daabc9600ea"
name = "github.com/cloudtrust/common-service" name = "github.com/cloudtrust/common-service"
packages = [ packages = [
".", ".",
"errors", "errors",
] ]
pruneopts = "" pruneopts = ""
revision = "ae957836daffbc39f197fa5f27201f8d100179d5" revision = "bda3eb6af01813931780dc33b49aabd0f878be19"
version = "v1.2.3"
[[projects]] [[projects]]
digest = "1:379d34d9efc755fab444199f007819fe99718640f9ccfbdd3f0430340bb02b07" digest = "1:379d34d9efc755fab444199f007819fe99718640f9ccfbdd3f0430340bb02b07"
@ -118,7 +118,7 @@
[[projects]] [[projects]]
branch = "master" branch = "master"
digest = "1:466229595e2439c31e2b3eb30f5d13782c3ffaed6b36d075d104c3ce7e9d9779" digest = "1:8dc5306c5097afa86c85335c9e981a22c164aab641ff749f88d2eecf9dbfdb93"
name = "golang.org/x/crypto" name = "golang.org/x/crypto"
packages = [ packages = [
"ed25519", "ed25519",
@ -126,7 +126,7 @@
"pbkdf2", "pbkdf2",
] ]
pruneopts = "" pruneopts = ""
revision = "6d4e4cb37c7d6416dfea8472e751c7b6615267a6" revision = "530e935923ad688be97c15eeb8e5ee42ebf2b54a"
[[projects]] [[projects]]
branch = "master" branch = "master"

2
Gopkg.toml

@ -22,7 +22,7 @@
[[constraint]] [[constraint]]
name = "github.com/cloudtrust/common-service" name = "github.com/cloudtrust/common-service"
version = "v1.2.3" branch = "master"
[[constraint]] [[constraint]]
name = "github.com/pkg/errors" name = "github.com/pkg/errors"

42
groups.go

@ -1,12 +1,15 @@
package keycloak package keycloak
import ( import (
"gopkg.in/h2non/gentleman.v2/plugins/body"
"gopkg.in/h2non/gentleman.v2/plugins/url" "gopkg.in/h2non/gentleman.v2/plugins/url"
) )
const ( const (
groupsPath = "/auth/admin/realms/:realm/groups" groupsPath = "/auth/admin/realms/:realm/groups"
groupByIDPath = "/auth/admin/realms/:realm/groups/:id" groupByIDPath = groupsPath + "/:id"
groupClientRoleMappingPath = groupByIDPath + "/role-mappings/clients/:clientId"
availableGroupClientRoleMappingPath = groupClientRoleMappingPath + "/available"
) )
// GetGroups gets all groups for the realm // GetGroups gets all groups for the realm
@ -22,3 +25,38 @@ func (c *Client) GetGroup(accessToken string, realmName string, groupID string)
var err = c.get(accessToken, &resp, url.Path(groupByIDPath), url.Param("realm", realmName), url.Param("id", groupID)) var err = c.get(accessToken, &resp, url.Path(groupByIDPath), url.Param("realm", realmName), url.Param("id", groupID))
return resp, err return resp, err
} }
// CreateGroup creates the group from its GroupRepresentation. The group name must be unique.
func (c *Client) CreateGroup(accessToken string, reqRealmName string, group GroupRepresentation) (string, error) {
return c.post(accessToken, nil, url.Path(groupsPath), url.Param("realm", reqRealmName), body.JSON(group))
}
// DeleteGroup deletes a specific group’s representation
func (c *Client) DeleteGroup(accessToken string, realmName string, groupID string) error {
return c.delete(accessToken, url.Path(groupByIDPath), url.Param("realm", realmName), url.Param("id", groupID))
}
// AssignClientRole assigns client roles to a specific group
func (c *Client) AssignClientRole(accessToken string, realmName string, groupID string, clientID string, roles []RoleRepresentation) error {
_, err := c.post(accessToken, nil, url.Path(groupClientRoleMappingPath), url.Param("realm", realmName), url.Param("id", groupID), url.Param("clientId", clientID), body.JSON(roles))
return err
}
// RemoveClientRole deletes client roles from a specific group
func (c *Client) RemoveClientRole(accessToken string, realmName string, groupID string, clientID string, roles []RoleRepresentation) error {
return c.delete(accessToken, url.Path(groupClientRoleMappingPath), url.Param("realm", realmName), url.Param("id", groupID), url.Param("clientId", clientID), body.JSON(roles))
}
// GetGroupClientRoles gets client roles assigned to a specific group
func (c *Client) GetGroupClientRoles(accessToken string, realmName string, groupID string, clientID string) ([]RoleRepresentation, error) {
var roles = []RoleRepresentation{}
var err = c.get(accessToken, &roles, url.Path(groupClientRoleMappingPath), url.Param("realm", realmName), url.Param("id", groupID), url.Param("clientId", clientID))
return roles, err
}
// GetAvailableGroupClientRoles gets client roles available in a specific group
func (c *Client) GetAvailableGroupClientRoles(accessToken string, realmName string, groupID string, clientID string) ([]RoleRepresentation, error) {
var roles = []RoleRepresentation{}
var err = c.get(accessToken, &roles, url.Path(availableGroupClientRoleMappingPath), url.Param("realm", realmName), url.Param("id", groupID), url.Param("clientId", clientID))
return roles, err
}

Loading…
Cancel
Save