-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8249377
commit 6656966
Showing
6 changed files
with
59 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
.../za/co/absa/loginsvc/rest/provider/kerberos/ActiveDirectoryLdapAuthoritiesPopulator.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...rc/main/scala/za/co/absa/loginsvc/rest/provider/kerberos/KerberosUserDetailsService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package za.co.absa.loginsvc.rest.provider.kerberos | ||
|
||
import org.slf4j.LoggerFactory | ||
import org.springframework.security.authentication.BadCredentialsException | ||
import org.springframework.security.core.userdetails.{UserDetails, UserDetailsService} | ||
import za.co.absa.loginsvc.rest.config.auth.ActiveDirectoryLDAPConfig | ||
import za.co.absa.loginsvc.rest.model.KerberosUserDetails | ||
import za.co.absa.loginsvc.rest.service.search.LdapUserRepository | ||
|
||
case class KerberosUserDetailsService(activeDirectoryLDAPConfig: ActiveDirectoryLDAPConfig) extends UserDetailsService { | ||
|
||
private val logger = LoggerFactory.getLogger(classOf[KerberosUserDetailsService]) | ||
|
||
override def loadUserByUsername(username: String): UserDetails = | ||
{ | ||
val name = if(username.contains("@")) { | ||
username.split("@").head | ||
} else { | ||
username | ||
} | ||
|
||
val ldapContext = new LdapUserRepository(activeDirectoryLDAPConfig) | ||
logger.info(s"Searching for user:$name") | ||
val userOption = ldapContext.searchForUser(name) | ||
|
||
if(userOption.isEmpty) | ||
throw new BadCredentialsException(s"Cannot Find User, $name, in Ldap") | ||
|
||
val user = userOption.get | ||
logger.info(s"Found Kerberos User: ${user.name}") | ||
KerberosUserDetails(user) | ||
} | ||
} | ||
|