From c24dc2d8cff9f0d89f3909c1488116dead780a31 Mon Sep 17 00:00:00 2001 From: TheLydonKing Date: Mon, 5 Feb 2024 14:56:35 +0200 Subject: [PATCH] Initial commit --- api/src/main/resources/example.application.yaml | 6 +++--- .../rest/config/auth/ActiveDirectoryLDAPConfig.scala | 2 +- .../ActiveDirectoryLDAPAuthenticationProvider.scala | 10 +++++----- api/src/test/resources/application.yaml | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/src/main/resources/example.application.yaml b/api/src/main/resources/example.application.yaml index 4cabcae..226ab7c 100644 --- a/api/src/main/resources/example.application.yaml +++ b/api/src/main/resources/example.application.yaml @@ -51,7 +51,7 @@ loginsvc: - "groupB" attributes: displayname: "Test User, A.C.E." - mail: "test@abs.com" + email: "test@abs.com" ldap: # Auth Protocol # Set the order of the protocol starting from 1 @@ -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: diff --git a/api/src/main/scala/za/co/absa/loginsvc/rest/config/auth/ActiveDirectoryLDAPConfig.scala b/api/src/main/scala/za/co/absa/loginsvc/rest/config/auth/ActiveDirectoryLDAPConfig.scala index 2a3ea09..27f5bd7 100644 --- a/api/src/main/scala/za/co/absa/loginsvc/rest/config/auth/ActiveDirectoryLDAPConfig.scala +++ b/api/src/main/scala/za/co/absa/loginsvc/rest/config/auth/ActiveDirectoryLDAPConfig.scala @@ -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 { diff --git a/api/src/main/scala/za/co/absa/loginsvc/rest/provider/ad/ldap/ActiveDirectoryLDAPAuthenticationProvider.scala b/api/src/main/scala/za/co/absa/loginsvc/rest/provider/ad/ldap/ActiveDirectoryLDAPAuthenticationProvider.scala index d3cf57c..d8aeadb 100644 --- a/api/src/main/scala/za/co/absa/loginsvc/rest/provider/ad/ldap/ActiveDirectoryLDAPAuthenticationProvider.scala +++ b/api/src/main/scala/za/co/absa/loginsvc/rest/provider/ad/ldap/ActiveDirectoryLDAPAuthenticationProvider.scala @@ -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 } @@ -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, @@ -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) } diff --git a/api/src/test/resources/application.yaml b/api/src/test/resources/application.yaml index 5a26b03..9daa0be 100644 --- a/api/src/test/resources/application.yaml +++ b/api/src/test/resources/application.yaml @@ -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