move jwt user and jwt authentication
This commit is contained in:
@@ -4,6 +4,8 @@ import io.github.oshai.kotlinlogging.KotlinLogging
|
|||||||
import io.jsonwebtoken.JwtException
|
import io.jsonwebtoken.JwtException
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import ltd.hlaeja.jwt.service.PublicJwtService
|
import ltd.hlaeja.jwt.service.PublicJwtService
|
||||||
|
import ltd.hlaeja.security.user.JwtAuthentication
|
||||||
|
import ltd.hlaeja.security.user.JwtUserDetails
|
||||||
import org.springframework.http.HttpStatus.UNAUTHORIZED
|
import org.springframework.http.HttpStatus.UNAUTHORIZED
|
||||||
import org.springframework.security.core.Authentication
|
import org.springframework.security.core.Authentication
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority
|
import org.springframework.security.core.authority.SimpleGrantedAuthority
|
||||||
@@ -40,7 +42,7 @@ class JwtAuthenticationConverter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun jwtAuthenticationToken(token: String) = publicJwtService.verify(token) { claims ->
|
private fun jwtAuthenticationToken(token: String) = publicJwtService.verify(token) { claims ->
|
||||||
JwtAuthenticationToken(
|
JwtAuthentication(
|
||||||
JwtUserDetails(
|
JwtUserDetails(
|
||||||
UUID.fromString(claims.payload["id"] as String),
|
UUID.fromString(claims.payload["id"] as String),
|
||||||
claims.payload["username"] as String,
|
claims.payload["username"] as String,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ltd.hlaeja.security
|
package ltd.hlaeja.security
|
||||||
|
|
||||||
|
import ltd.hlaeja.security.user.JwtAuthentication
|
||||||
import org.springframework.security.authentication.ReactiveAuthenticationManager
|
import org.springframework.security.authentication.ReactiveAuthenticationManager
|
||||||
import org.springframework.security.core.Authentication
|
import org.springframework.security.core.Authentication
|
||||||
import org.springframework.security.core.AuthenticationException
|
import org.springframework.security.core.AuthenticationException
|
||||||
@@ -11,14 +12,14 @@ class JwtAuthenticationManager : ReactiveAuthenticationManager {
|
|||||||
|
|
||||||
override fun authenticate(
|
override fun authenticate(
|
||||||
authentication: Authentication,
|
authentication: Authentication,
|
||||||
): Mono<Authentication> = if (authentication is JwtAuthenticationToken) {
|
): Mono<Authentication> = if (authentication is JwtAuthentication) {
|
||||||
handleJwtToken(authentication)
|
handleJwtToken(authentication)
|
||||||
} else {
|
} else {
|
||||||
Mono.error(object : AuthenticationException("Unsupported authentication type") {})
|
Mono.error(object : AuthenticationException("Unsupported authentication type") {})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleJwtToken(
|
private fun handleJwtToken(
|
||||||
token: JwtAuthenticationToken,
|
token: JwtAuthentication,
|
||||||
): Mono<Authentication> = if (token.isAuthenticated) {
|
): Mono<Authentication> = if (token.isAuthenticated) {
|
||||||
Mono.just(token)
|
Mono.just(token)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package ltd.hlaeja.security
|
package ltd.hlaeja.security.user
|
||||||
|
|
||||||
import org.springframework.security.core.Authentication
|
import org.springframework.security.core.Authentication
|
||||||
import org.springframework.security.core.GrantedAuthority
|
import org.springframework.security.core.GrantedAuthority
|
||||||
|
|
||||||
data class JwtAuthenticationToken(
|
data class JwtAuthentication(
|
||||||
private val jwtUserDetails: JwtUserDetails,
|
private val jwtUserDetails: JwtUserDetails,
|
||||||
private val token: String,
|
private val token: String,
|
||||||
private var authorities: MutableCollection<out GrantedAuthority>,
|
private var authorities: MutableCollection<out GrantedAuthority>,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ltd.hlaeja.security
|
package ltd.hlaeja.security.user
|
||||||
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
Reference in New Issue
Block a user