JwtAuthorizationFilter.getAuthenticationToken(String) retourne null si aucun employé avec l'identifiant donné n'a été trouvé.

This commit is contained in:
FyloZ 2021-02-16 13:59:25 -05:00
parent 0efef85949
commit f02e4179fd
2 changed files with 6 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package dev.fyloz.trial.colorrecipesexplorer.config
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.fyloz.trial.colorrecipesexplorer.exception.model.EntityNotFoundRestException
import dev.fyloz.trial.colorrecipesexplorer.model.Employee
import dev.fyloz.trial.colorrecipesexplorer.model.EmployeeLoginRequest
import dev.fyloz.trial.colorrecipesexplorer.model.EmployeePermission
@ -53,7 +54,6 @@ import javax.servlet.http.HttpServletResponse
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableConfigurationProperties(SecurityConfigurationProperties::class)
class WebSecurityConfig(
val restAuthenticationEntryPoint: RestAuthenticationEntryPoint,
val securityConfigurationProperties: SecurityConfigurationProperties,
@Lazy val userDetailsService: EmployeeUserDetailsServiceImpl,
@Lazy val employeeService: EmployeeServiceImpl,
@ -288,9 +288,11 @@ class JwtAuthorizationFilter(
}
}
private fun getAuthenticationToken(employeeId: String): UsernamePasswordAuthenticationToken {
private fun getAuthenticationToken(employeeId: String): UsernamePasswordAuthenticationToken? = try {
val employeeDetails = userDetailsService.loadUserByEmployeeId(employeeId.toLong(), false)
return UsernamePasswordAuthenticationToken(employeeDetails.username, null, employeeDetails.authorities)
UsernamePasswordAuthenticationToken(employeeDetails.username, null, employeeDetails.authorities)
} catch (_: EntityNotFoundRestException) {
null
}
}

View File

@ -322,8 +322,7 @@ class EmployeeGroupServiceImpl(
@Service
class EmployeeUserDetailsServiceImpl(
val employeeService: EmployeeService,
val securityConfigurationProperties: SecurityConfigurationProperties
val employeeService: EmployeeService
) :
EmployeeUserDetailsService {
override fun loadUserByUsername(username: String): UserDetails {