From f02e4179fdbdf793771544f4c303f1f04d17e02a Mon Sep 17 00:00:00 2001 From: FyloZ Date: Tue, 16 Feb 2021 13:59:25 -0500 Subject: [PATCH] =?UTF-8?q?JwtAuthorizationFilter.getAuthenticationToken(S?= =?UTF-8?q?tring)=20retourne=20null=20si=20aucun=20employ=C3=A9=20avec=20l?= =?UTF-8?q?'identifiant=20donn=C3=A9=20n'a=20=C3=A9t=C3=A9=20trouv=C3=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../colorrecipesexplorer/config/WebSecurityConfig.kt | 8 +++++--- .../trial/colorrecipesexplorer/service/AccountService.kt | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/config/WebSecurityConfig.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/config/WebSecurityConfig.kt index 928c7e9..7f3e210 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/config/WebSecurityConfig.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/config/WebSecurityConfig.kt @@ -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 } } diff --git a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountService.kt b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountService.kt index fbd32d0..366bc19 100644 --- a/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountService.kt +++ b/src/main/kotlin/dev/fyloz/trial/colorrecipesexplorer/service/AccountService.kt @@ -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 {