Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dex
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
dex
Commits
ee54a509
Commit
ee54a509
authored
6 years ago
by
Daniel Kessler
Browse files
Options
Downloads
Patches
Plain Diff
LDAP connector - add emailSuffix config option
parent
27f66e79
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
connector/ldap/ldap.go
+12
-5
12 additions, 5 deletions
connector/ldap/ldap.go
connector/ldap/ldap_test.go
+62
-0
62 additions, 0 deletions
connector/ldap/ldap_test.go
with
74 additions
and
5 deletions
connector/ldap/ldap.go
+
12
−
5
View file @
ee54a509
...
@@ -107,6 +107,10 @@ type Config struct {
...
@@ -107,6 +107,10 @@ type Config struct {
IDAttr
string
`json:"idAttr"`
// Defaults to "uid"
IDAttr
string
`json:"idAttr"`
// Defaults to "uid"
EmailAttr
string
`json:"emailAttr"`
// Defaults to "mail"
EmailAttr
string
`json:"emailAttr"`
// Defaults to "mail"
NameAttr
string
`json:"nameAttr"`
// No default.
NameAttr
string
`json:"nameAttr"`
// No default.
// If this is set, the email claim of the id token will be constructed from the idAttr and
// value of emailSuffix. This should not include the @ character.
EmailSuffix
string
`json:"emailSuffix"`
// No default.
}
`json:"userSearch"`
}
`json:"userSearch"`
// Group search configuration.
// Group search configuration.
...
@@ -331,11 +335,6 @@ func (c *ldapConnector) identityFromEntry(user ldap.Entry) (ident connector.Iden
...
@@ -331,11 +335,6 @@ func (c *ldapConnector) identityFromEntry(user ldap.Entry) (ident connector.Iden
if
ident
.
UserID
=
getAttr
(
user
,
c
.
UserSearch
.
IDAttr
);
ident
.
UserID
==
""
{
if
ident
.
UserID
=
getAttr
(
user
,
c
.
UserSearch
.
IDAttr
);
ident
.
UserID
==
""
{
missing
=
append
(
missing
,
c
.
UserSearch
.
IDAttr
)
missing
=
append
(
missing
,
c
.
UserSearch
.
IDAttr
)
}
}
if
ident
.
Email
=
getAttr
(
user
,
c
.
UserSearch
.
EmailAttr
);
ident
.
Email
==
""
{
missing
=
append
(
missing
,
c
.
UserSearch
.
EmailAttr
)
}
// TODO(ericchiang): Let this value be set from an attribute.
ident
.
EmailVerified
=
true
if
c
.
UserSearch
.
NameAttr
!=
""
{
if
c
.
UserSearch
.
NameAttr
!=
""
{
if
ident
.
Username
=
getAttr
(
user
,
c
.
UserSearch
.
NameAttr
);
ident
.
Username
==
""
{
if
ident
.
Username
=
getAttr
(
user
,
c
.
UserSearch
.
NameAttr
);
ident
.
Username
==
""
{
...
@@ -343,6 +342,14 @@ func (c *ldapConnector) identityFromEntry(user ldap.Entry) (ident connector.Iden
...
@@ -343,6 +342,14 @@ func (c *ldapConnector) identityFromEntry(user ldap.Entry) (ident connector.Iden
}
}
}
}
if
c
.
UserSearch
.
EmailSuffix
!=
""
{
ident
.
Email
=
ident
.
Username
+
"@"
+
c
.
UserSearch
.
EmailSuffix
}
else
if
ident
.
Email
=
getAttr
(
user
,
c
.
UserSearch
.
EmailAttr
);
ident
.
Email
==
""
{
missing
=
append
(
missing
,
c
.
UserSearch
.
EmailAttr
)
}
// TODO(ericchiang): Let this value be set from an attribute.
ident
.
EmailVerified
=
true
if
len
(
missing
)
!=
0
{
if
len
(
missing
)
!=
0
{
err
:=
fmt
.
Errorf
(
"ldap: entry %q missing following required attribute(s): %q"
,
user
.
DN
,
missing
)
err
:=
fmt
.
Errorf
(
"ldap: entry %q missing following required attribute(s): %q"
,
user
.
DN
,
missing
)
return
connector
.
Identity
{},
err
return
connector
.
Identity
{},
err
...
...
This diff is collapsed.
Click to expand it.
connector/ldap/ldap_test.go
+
62
−
0
View file @
ee54a509
...
@@ -123,6 +123,68 @@ userpassword: bar
...
@@ -123,6 +123,68 @@ userpassword: bar
runTests
(
t
,
schema
,
connectLDAP
,
c
,
tests
)
runTests
(
t
,
schema
,
connectLDAP
,
c
,
tests
)
}
}
func
TestQueryWithEmailSuffix
(
t
*
testing
.
T
)
{
schema
:=
`
dn: dc=example,dc=org
objectClass: dcObject
objectClass: organization
o: Example Company
dc: example
dn: ou=People,dc=example,dc=org
objectClass: organizationalUnit
ou: People
dn: cn=jane,ou=People,dc=example,dc=org
objectClass: person
objectClass: inetOrgPerson
sn: doe
cn: jane
mail: janedoe@example.com
userpassword: foo
dn: cn=john,ou=People,dc=example,dc=org
objectClass: person
objectClass: inetOrgPerson
sn: doe
cn: john
userpassword: bar
`
c
:=
&
Config
{}
c
.
UserSearch
.
BaseDN
=
"ou=People,dc=example,dc=org"
c
.
UserSearch
.
NameAttr
=
"cn"
c
.
UserSearch
.
EmailSuffix
=
"test.example.com"
c
.
UserSearch
.
IDAttr
=
"DN"
c
.
UserSearch
.
Username
=
"cn"
tests
:=
[]
subtest
{
{
name
:
"ignoremailattr"
,
username
:
"jane"
,
password
:
"foo"
,
want
:
connector
.
Identity
{
UserID
:
"cn=jane,ou=People,dc=example,dc=org"
,
Username
:
"jane"
,
Email
:
"jane@test.example.com"
,
EmailVerified
:
true
,
},
},
{
name
:
"nomailattr"
,
username
:
"john"
,
password
:
"bar"
,
want
:
connector
.
Identity
{
UserID
:
"cn=john,ou=People,dc=example,dc=org"
,
Username
:
"john"
,
Email
:
"john@test.example.com"
,
EmailVerified
:
true
,
},
},
}
runTests
(
t
,
schema
,
connectLDAP
,
c
,
tests
)
}
func
TestGroupQuery
(
t
*
testing
.
T
)
{
func
TestGroupQuery
(
t
*
testing
.
T
)
{
schema
:=
`
schema
:=
`
dn: dc=example,dc=org
dn: dc=example,dc=org
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment