Return 401 for auth failures and log verify
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 27s
This commit is contained in:
@@ -80,10 +80,12 @@ class Auth(
|
|||||||
val decoded = try {
|
val decoded = try {
|
||||||
FirebaseAuth.getInstance().verifyIdToken(token)
|
FirebaseAuth.getInstance().verifyIdToken(token)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
|
logger.warn("Auth verify failed: {}", ex.message)
|
||||||
throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "Invalid token")
|
throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "Invalid token")
|
||||||
}
|
}
|
||||||
val user = appUserRepo.findByFirebaseUid(decoded.uid)
|
val user = appUserRepo.findByFirebaseUid(decoded.uid)
|
||||||
?: throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "User not found")
|
?: throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "User not found")
|
||||||
|
logger.info("Auth verify resolved uid={}, userId={}", decoded.uid, user.id)
|
||||||
return MyPrincipal(
|
return MyPrincipal(
|
||||||
userId = user.id ?: throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "User id missing"),
|
userId = user.id ?: throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "User id missing"),
|
||||||
firebaseUid = decoded.uid
|
firebaseUid = decoded.uid
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity
|
|||||||
import org.springframework.security.config.http.SessionCreationPolicy
|
import org.springframework.security.config.http.SessionCreationPolicy
|
||||||
import org.springframework.security.web.SecurityFilterChain
|
import org.springframework.security.web.SecurityFilterChain
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
|
||||||
|
import org.springframework.security.web.authentication.HttpStatusEntryPoint
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@EnableMethodSecurity
|
@EnableMethodSecurity
|
||||||
@@ -22,6 +24,12 @@ class SecurityConfig(
|
|||||||
it.requestMatchers("/", "/health", "/auth/**").permitAll()
|
it.requestMatchers("/", "/health", "/auth/**").permitAll()
|
||||||
it.anyRequest().authenticated()
|
it.anyRequest().authenticated()
|
||||||
}
|
}
|
||||||
|
.exceptionHandling {
|
||||||
|
it.authenticationEntryPoint(HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))
|
||||||
|
it.accessDeniedHandler { _, response, _ ->
|
||||||
|
response.sendError(HttpStatus.UNAUTHORIZED.value(), "Unauthorized")
|
||||||
|
}
|
||||||
|
}
|
||||||
.httpBasic { it.disable() }
|
.httpBasic { it.disable() }
|
||||||
.formLogin { it.disable() }
|
.formLogin { it.disable() }
|
||||||
.addFilterBefore(firebaseAuthFilter, UsernamePasswordAuthenticationFilter::class.java)
|
.addFilterBefore(firebaseAuthFilter, UsernamePasswordAuthenticationFilter::class.java)
|
||||||
|
|||||||
Reference in New Issue
Block a user