Authorization
- add SecurityConfiguration - add JwtAuthenticationManager - add JwtAuthenticationConverter - add JwtAuthenticationToken - add JwtUserDetails
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package ltd.hlaeja.security
|
||||
|
||||
import org.springframework.security.authentication.ReactiveAuthenticationManager
|
||||
import org.springframework.security.core.Authentication
|
||||
import org.springframework.security.core.AuthenticationException
|
||||
import org.springframework.stereotype.Component
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Component
|
||||
class JwtAuthenticationManager : ReactiveAuthenticationManager {
|
||||
|
||||
override fun authenticate(
|
||||
authentication: Authentication,
|
||||
): Mono<Authentication> = if (authentication is JwtAuthenticationToken) {
|
||||
handleJwtToken(authentication)
|
||||
} else {
|
||||
Mono.error(object : AuthenticationException("Unsupported authentication type") {})
|
||||
}
|
||||
|
||||
private fun handleJwtToken(
|
||||
token: JwtAuthenticationToken,
|
||||
): Mono<Authentication> = if (token.isAuthenticated) {
|
||||
Mono.just(token)
|
||||
} else {
|
||||
Mono.error(object : AuthenticationException("Invalid or expired JWT token") {})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user