Browse Source

Rename configuration option to include a reference to groups

and structure for future claim modification additions

Signed-off-by: Oded Ben-Ozer <obenozer@wayfair.com>
pull/3056/head
Oded Ben-Ozer 3 years ago
parent
commit
a52848418a
  1. 14
      connector/oidc/oidc.go
  2. 6
      connector/oidc/oidc_test.go

14
connector/oidc/oidc.go

@ -88,12 +88,14 @@ type Config struct {
GroupsKey string `json:"groups"` // defaults to "groups" GroupsKey string `json:"groups"` // defaults to "groups"
} `json:"claimMapping"` } `json:"claimMapping"`
// List of new claim to generate based on concatinate existing claims // ClaimModifications holds all claim modifications options, current has only newGroupsFromClaims
ClaimConcatenations []ClaimConcatenation `json:"claimConcatenations"` ClaimModifications struct {
NewGroupsFromClaims []NewGroupsFromClaims `json:"newGroupsFromClaims"`
}
} }
// List of groups claim elements to create by concatenating other claims // List of groups claim elements to create by concatenating other claims
type ClaimConcatenation struct { type NewGroupsFromClaims struct {
// List of claim to join together // List of claim to join together
ClaimList []string `json:"claimList"` ClaimList []string `json:"claimList"`
@ -204,7 +206,7 @@ func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, e
preferredUsernameKey: c.ClaimMapping.PreferredUsernameKey, preferredUsernameKey: c.ClaimMapping.PreferredUsernameKey,
emailKey: c.ClaimMapping.EmailKey, emailKey: c.ClaimMapping.EmailKey,
groupsKey: c.ClaimMapping.GroupsKey, groupsKey: c.ClaimMapping.GroupsKey,
claimConcatenations: c.ClaimConcatenations, newGroupsFromClaims: c.ClaimModifications.NewGroupsFromClaims,
}, nil }, nil
} }
@ -232,7 +234,7 @@ type oidcConnector struct {
preferredUsernameKey string preferredUsernameKey string
emailKey string emailKey string
groupsKey string groupsKey string
claimConcatenations []ClaimConcatenation newGroupsFromClaims []NewGroupsFromClaims
} }
func (c *oidcConnector) Close() error { func (c *oidcConnector) Close() error {
@ -444,7 +446,7 @@ func (c *oidcConnector) createIdentity(ctx context.Context, identity connector.I
} }
} }
for _, cc := range c.claimConcatenations { for _, cc := range c.newGroupsFromClaims {
newElement := "" newElement := ""
for _, clm := range cc.ClaimList { for _, clm := range cc.ClaimList {
// Non string claim value are ignored, concatenating them doesn't really make any sense // Non string claim value are ignored, concatenating them doesn't really make any sense

6
connector/oidc/oidc_test.go

@ -62,7 +62,7 @@ func TestHandleCallback(t *testing.T) {
expectPreferredUsername string expectPreferredUsername string
expectedEmailField string expectedEmailField string
token map[string]interface{} token map[string]interface{}
claimConcatenations []ClaimConcatenation newGroupsFromClaims []NewGroupsFromClaims
}{ }{
{ {
name: "simpleCase", name: "simpleCase",
@ -297,7 +297,7 @@ func TestHandleCallback(t *testing.T) {
expectUserName: "namevalue", expectUserName: "namevalue",
expectGroups: []string{"group1", "gh::acme::pipeline-one", "tfe-acme-foobar", "bk-emailvalue"}, expectGroups: []string{"group1", "gh::acme::pipeline-one", "tfe-acme-foobar", "bk-emailvalue"},
expectedEmailField: "emailvalue", expectedEmailField: "emailvalue",
claimConcatenations: []ClaimConcatenation{ newGroupsFromClaims: []NewGroupsFromClaims{
{ // The basic functionality, should create "gh::acme::pipeline-one". { // The basic functionality, should create "gh::acme::pipeline-one".
ClaimList: []string{ ClaimList: []string{
"organization", "organization",
@ -382,11 +382,11 @@ func TestHandleCallback(t *testing.T) {
InsecureEnableGroups: true, InsecureEnableGroups: true,
BasicAuthUnsupported: &basicAuth, BasicAuthUnsupported: &basicAuth,
OverrideClaimMapping: tc.overrideClaimMapping, OverrideClaimMapping: tc.overrideClaimMapping,
ClaimConcatenations: tc.claimConcatenations,
} }
config.ClaimMapping.PreferredUsernameKey = tc.preferredUsernameKey config.ClaimMapping.PreferredUsernameKey = tc.preferredUsernameKey
config.ClaimMapping.EmailKey = tc.emailKey config.ClaimMapping.EmailKey = tc.emailKey
config.ClaimMapping.GroupsKey = tc.groupsKey config.ClaimMapping.GroupsKey = tc.groupsKey
config.ClaimModifications.NewGroupsFromClaims = tc.newGroupsFromClaims
conn, err := newConnector(config) conn, err := newConnector(config)
if err != nil { if err != nil {

Loading…
Cancel
Save