Skip to content

Commit

Permalink
Add authentication header
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLydonKing committed Nov 15, 2024
1 parent b3231b3 commit f102387
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions api/src/main/scala/za/co/absa/loginsvc/rest/SecurityConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import org.springframework.security.web.authentication.www.BasicAuthenticationFi
import za.co.absa.loginsvc.rest.config.provider.AuthConfigProvider
import za.co.absa.loginsvc.rest.provider.kerberos.KerberosSPNEGOAuthenticationProvider

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import org.springframework.security.core.AuthenticationException

@Configuration
@EnableWebSecurity
class SecurityConfig @Autowired()(authConfigsProvider: AuthConfigProvider) {
Expand Down Expand Up @@ -58,13 +62,20 @@ class SecurityConfig @Autowired()(authConfigsProvider: AuthConfigProvider) {
if(ldapConfig != null)
{
if(ldapConfig.enableKerberos.isDefined)
{
val kerberos = new KerberosSPNEGOAuthenticationProvider(ldapConfig)
{
val kerberos = new KerberosSPNEGOAuthenticationProvider(ldapConfig)

http.addFilterBefore(
http.addFilterBefore(
kerberos.spnegoAuthenticationProcessingFilter,
classOf[BasicAuthenticationFilter])
}
.exceptionHandling()
.authenticationEntryPoint((request: HttpServletRequest,
response: HttpServletResponse,
authException: AuthenticationException) => {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED)
response.addHeader("WWW-Authenticate", "Negotiate")
})
}
}

http.build()
Expand Down

0 comments on commit f102387

Please sign in to comment.