Verarbeitungssteuerungsmethode Mehrmals, wenn ich Filter zur Sicherheitskette hinzufügeJava

Java-Forum
Anonymous
 Verarbeitungssteuerungsmethode Mehrmals, wenn ich Filter zur Sicherheitskette hinzufüge

Post by Anonymous »

Das ist also mein Controller < /p>

Code: Select all

@RestController
class SyncRevokedTokensController(private val syncRevokedTokenService: SyncRevokedTokensService) {

private val log: Logger = LoggerFactory.getLogger(SyncRevokedTokensController::class.java)

@PostMapping("/sync-revoked-tokens", consumes = ["application/json"])
fun syncTokens(@RequestBody request: Mono): Mono {
log.info("Received request to sync revoked tokens")

return request
.flatMap { syncRequest ->
if (syncRequest.startSynchronization) {
log.info("Starting sync of revoked tokens")
syncRevokedTokenService.sync()
.doOnSuccess {
log.info("Completed sync service operation")
}
.onErrorResume { error ->
log.error("Error during sync operation", error)
Mono.error(error)
}
} else {
log.info(
"Synchronization not started as startSynchronization is false "
)
Mono.empty()
}
}
.doOnSuccess {
log.info("Successfully completed sync tokens request")
}
.onErrorResume { error ->
log.error("Error processing sync request", error)
Mono.error(error)
}
}
}
< /code>
und basierend auf dem Protokoll wird versucht, diese Methode zweimal zu verarbeiten. Zum ersten Mal wird sie korrekt verarbeitet und wirft diese Ausnahme im zweiten Mal aus. /Code> und Ergebnisse mit 400 schlechter Anforderung. < /p>
Das liegt daran    @Bean
@Order(2)
fun syncRevokedTokensFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
return http
.securityMatcher(ServerWebExchangeMatchers.pathMatchers(HttpMethod.POST, "/sync-revoked-tokens"))
.authorizeExchange { exchanges ->
exchanges.anyExchange().authenticated()
}
.addFilterAt(MfaEndpointsAuthorizationWebFilter(), SecurityWebFiltersOrder.LAST)
.oauth2ResourceServer { oauth2 ->
oauth2
.bearerTokenConverter(ServerBearerTokenAuthenticationConverter())
.authenticationManagerResolver(customAuthenticationOauth2ManagerResolver())
}
.csrf { it.disable() }
.headers { it.disable() }
.build()
}
falls ich diese Codezeile lösche: .AddFilterat (mfaendpointsAuthorizationWebFilter (), SecurityWebFiltersOrder.last) Ich erhalte 200 von meiner API 200 und es wird nicht versucht, verarbeitet zu werden, um zu verarbeiten Mehrfaches. < /p>
Hier ist auch ein Filter: < /p>

Code: Select all

class MfaEndpointsAuthorizationWebFilter : WebFilter {

companion object {
private val log = LoggerFactory.getLogger(MfaEndpointsAuthorizationWebFilter::class.java)
}

private fun isMfaScopeSupportedEndpoint(path: String): Boolean {
//TODO on purpose delete logic because of security reasons
return true
}

override fun filter(exchange: ServerWebExchange, chain: WebFilterChain): Mono {
log.info("Starting MfaEndpointsAuthorizationWebFilter for path: {}", exchange.request.path)
return ReactiveSecurityContextHolder.getContext()
.flatMap { securityContext: SecurityContext ->
if (securityContext.authentication is CustomAuthentication) {
val customAuthentication = securityContext.authentication as CustomAuthentication
val scope = customAuthentication.tokenScope

if ("totp_authenticator" == scope && !isMfaScopeSupportedEndpoint(exchange.request.path.value())) {
exchange.response.setStatusCode(HttpStatus.UNAUTHORIZED)
return@flatMap Mono.error(OAuth2AuthenticationException("MFA scope is not supported for called url"))
}
}
chain.filter(exchange)
}
.switchIfEmpty(chain.filter(exchange)) // Proceed with the filter chain if no security context is present
.onErrorResume(OAuth2AuthenticationException::class.java) { _: OAuth2AuthenticationException? -> Mono.empty() }
}
}
Wie ich schon sagte>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post