Skip to content

Commit

Permalink
Merge pull request #367 from simioa/add_user-attr-template
Browse files Browse the repository at this point in the history
Add LDAP user attr template
  • Loading branch information
moliware authored May 20, 2019
2 parents f73e745 + fe6ae60 commit 6a3e60e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ LDAP_BIND_PWD=adminpass
# Attribute that represent the user, for example uid or mail
# LDAP_USER_ATTR=mail

# If left unset LDAP_USER_TEMPLATE will be used
# LDAP_USER_ATTR_TEMPLATE=%s

# Filter that tests membership of the group. If this property is empty then there is no group membership check
# AD example => memberOf=CN=mygroup,ou=ouofthegroup,DC=domain,DC=com
# OpenLDAP example => CN=mygroup
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/auth/ldap/LDAPAuthConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class LDAPAuthConfig(config: Configuration) extends AuthConfig {
LDAPGroupSearchConfig(
groupAuthConfig.getOptional[String]("base-dn").getOrElse(baseDN),
getSetting("user-attr")(groupAuthConfig),
groupAuthConfig.getOptional[String]("user-attr-template").getOrElse(userTemplate),
group
)
}
}
}

case class LDAPGroupSearchConfig(baseDN: String, userAttr: String, group: String)
case class LDAPGroupSearchConfig(baseDN: String, userAttr: String, userAttrTemplate:String, group: String)
2 changes: 1 addition & 1 deletion app/controllers/auth/ldap/LDAPAuthService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class LDAPAuthService @Inject()(globalConfig: Configuration) extends AuthService
props.put(Context.SECURITY_PRINCIPAL, config.bindDN)
props.put(Context.SECURITY_CREDENTIALS, config.bindPwd)
props.put(Context.REFERRAL, "follow")
val user = config.userTemplate.format(username, config.baseDN)
val user = groupConfig.userAttrTemplate.format(username, config.baseDN)
val controls = new SearchControls()
controls.setSearchScope(SearchControls.SUBTREE_SCOPE)
try {
Expand Down
3 changes: 3 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ auth = {
base-dn = ${?LDAP_GROUP_BASE_DN}
// Attribute that represent the user, for example uid or mail
user-attr = ${?LDAP_USER_ATTR}
// Define a separate template for user-attr
// If left unset parent's user-template will be used
user-attr-template = ${?LDAP_USER_ATTR_TEMPLATE}
// Filter that tests membership of the group. If this property is empty then there is no group membership check
// AD example => memberOf=CN=mygroup,ou=ouofthegroup,DC=domain,DC=com
// OpenLDAP example => CN=mygroup
Expand Down

0 comments on commit 6a3e60e

Please sign in to comment.