Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLydonKing committed Feb 5, 2024
1 parent c9849c1 commit c24dc2d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions api/src/main/resources/example.application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ loginsvc:
- "groupB"
attributes:
displayname: "Test User, A.C.E."
mail: "[email protected]"
email: "[email protected]"
ldap:
# Auth Protocol
# Set the order of the protocol starting from 1
Expand All @@ -62,8 +62,8 @@ loginsvc:
url: "ldaps://some.domain.com:636/"
search-filter: "(samaccountname={1})"
attributes:
- "mail"
- "displayname"
mail: "email"
displayname: "displayname"

# App Config
spring:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import za.co.absa.loginsvc.rest.config.validation.{ConfigValidatable, ConfigVali
* @param url URL to AD LDAP, ex. "ldaps://some.domain.com:636/"
* @param searchFilter LDAP filter used when searching for groups, ex. "(samaccountname={1})"
*/
case class ActiveDirectoryLDAPConfig(domain: String, url: String, searchFilter: String, order: Int, attributes: Option[Array[String]])
case class ActiveDirectoryLDAPConfig(domain: String, url: String, searchFilter: String, order: Int, attributes: Option[Map[String, String]])
extends ConfigValidatable with DynamicAuthOrder
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ActiveDirectoryLDAPAuthenticationProvider(config: ActiveDirectoryLDAPConfi
val impl = new SpringSecurityActiveDirectoryLdapAuthenticationProvider(config.domain, config.url)

impl.setSearchFilter(config.searchFilter)
impl.setUserDetailsContextMapper(new LDAPUserDetailsContextMapperWithOptions(config.attributes.getOrElse(Array.empty)))
impl.setUserDetailsContextMapper(new LDAPUserDetailsContextMapperWithOptions(config.attributes.getOrElse(Map.empty)))

impl
}
Expand Down Expand Up @@ -90,7 +90,7 @@ class ActiveDirectoryLDAPAuthenticationProvider(config: ActiveDirectoryLDAPConfi
override def isEnabled: Boolean = userDetails.isEnabled
}

private class LDAPUserDetailsContextMapperWithOptions(attributes: Array[String]) extends LdapUserDetailsMapper {
private class LDAPUserDetailsContextMapperWithOptions(attributes: Map[String, String]) extends LdapUserDetailsMapper {

override def mapUserFromContext(
ctx: DirContextOperations,
Expand All @@ -99,9 +99,9 @@ class ActiveDirectoryLDAPAuthenticationProvider(config: ActiveDirectoryLDAPConfi
): UserDetails = {
val fromBase = super.mapUserFromContext(ctx, username, authorities)
val extraAttributes = attributes.map { attr =>
val value = Option(ctx.getAttributes().get(attr)).map(_.get())
attr -> value
}.toMap
val value = Option(ctx.getAttributes().get(attr._1)).map(_.get())
attr._2 -> value
}

UserDetailsWithExtras(fromBase, extraAttributes)
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ loginsvc:
url: "ldaps://some.domain.com:636/"
search-filter: "(samaccountname={1})"
attributes:
- "mail"
- "displayname"
mail: "email"
displayname: "displayname"
# Users (config-defined)
users:
order: 0
Expand Down

0 comments on commit c24dc2d

Please sign in to comment.