diff --git a/modules/security-api/src/main/java/org/fireflyframework/security/api/domain/BearerToken.java b/modules/security-api/src/main/java/org/fireflyframework/security/api/domain/BearerToken.java
index 38757b055..29fd82b43 100644
--- a/modules/security-api/src/main/java/org/fireflyframework/security/api/domain/BearerToken.java
+++ b/modules/security-api/src/main/java/org/fireflyframework/security/api/domain/BearerToken.java
@@ -40,6 +40,11 @@ private static TokenType classify(String value) {
return dots == 2 ? TokenType.JWT : TokenType.OPAQUE;
}
+ @Override
+ public final String toString() {
+ return "BearerToken[REDACTED]";
+ }
+
/** @return the token value masked for safe logging. */
public String masked() {
if (value == null || value.length() <= 8) {
diff --git a/modules/security-api/src/test/java/org/fireflyframework/security/api/domain/BearerTokenRenderingTest.java b/modules/security-api/src/test/java/org/fireflyframework/security/api/domain/BearerTokenRenderingTest.java
new file mode 100644
index 000000000..654701198
--- /dev/null
+++ b/modules/security-api/src/test/java/org/fireflyframework/security/api/domain/BearerTokenRenderingTest.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2024-2026 Firefly Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.fireflyframework.security.api.domain;
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Test;
+class BearerTokenRenderingTest {
+ @Test void diagnosticRenderingNeverExposesCredentialOrFragments(){var token=BearerToken.of("PRIVATE_ACCESS_TOKEN_HEAD.middle.PRIVATE_TAIL");assertEquals("BearerToken[REDACTED]",token.toString());assertFalse(token.toString().contains("PRIVATE"));}
+ @Test void credentialComponentsAndClassificationRemainAvailableToTheInternalPort(){var token=BearerToken.of("a.b.c");assertEquals("a.b.c",token.value());assertEquals(BearerToken.TokenType.JWT,token.type());assertEquals("****",token.masked());}
+ @Test void redactedOverrideRetainsPublishedFinalModifier()throws Exception{assertTrue(java.lang.reflect.Modifier.isFinal(BearerToken.class.getDeclaredMethod("toString").getModifiers()));}
+}
diff --git a/modules/security-resource-server/docs/live-active-state-admission.md b/modules/security-resource-server/docs/live-active-state-admission.md
new file mode 100644
index 000000000..b3b987138
--- /dev/null
+++ b/modules/security-resource-server/docs/live-active-state-admission.md
@@ -0,0 +1,41 @@
+# Optional LIVE JWT admission
+
+This source addition requires a matching qualified whole-framework release. It is not included in version 26.10.23.
+
+LIVE adds optional current-state admission after local JWT verification. Confirm the provider response contract and qualify the application security chain before enabling this mode in a deployment.
+
+`LOCAL_JWT` remains the general default. It retains signature, issuer, audience and time validation. An unexpired locally verified JWT does not by itself establish that its provider account or session is currently active.
+
+Explicit `LIVE` first uses the existing JWT decoder and then calls `TokenValidationPort.validateLive` for the same credential on each subscription. Existing port implementations refuse this additive method by default. The owned implementation uses Spring Security's native remote introspector, standard JDK HTTPS transport and managed Jackson3 codecs. No IdP name, adapter class, client alias, cache health or local token parser implies LIVE support.
+
+```yaml
+firefly:
+ security:
+ resource-server:
+ admission-mode: LIVE
+ issuer: ${OIDC_EXPECTED_ISSUER}
+ audiences: [${OIDC_RESOURCE_AUDIENCE}]
+ live-state:
+ introspection-uri: ${OIDC_INTROSPECTION_HTTPS_URI}
+ introspection-client-id: ${OIDC_INTROSPECTION_CLIENT_ID}
+ introspection-client-secret: ${OIDC_INTROSPECTION_CLIENT_SECRET}
+ token-client-claim: ${OIDC_SIGNED_CLIENT_CLAIM}
+ allowed-clients: [${OIDC_ALLOWED_CLIENT}]
+ timeout: 5s
+```
+
+Use one explicitly configured signed client claim, such as the exact `azp` or `client_id` defined by the trusted issuer. There is no automatic alias or token-derived endpoint discovery. Configuration and credentials are snapshotted when the adapter/decorator is constructed. Rotate them through a newly constructed configured instance.
+
+The active response must contain actual Boolean `active` and correctly typed issuer, opaque subject, client_id, audience and integral expiration. The verified issuer, subject, client, audience set and expiration must match exactly; a signed token ID must also match. Opaque identifiers are not UUIDs and are not trimmed or normalized. Missing, malformed, duplicate, ambiguous or mismatched metadata refuses. Active=false may omit identity metadata and still refuses. Identity metadata is used only for the check: the exact locally verified Jwt continues to the existing principal converter, without provider role, claim or tenant merging.
+
+The original per-subscription authentication window includes local verification and live admission. It is at most 5 seconds and additionally clipped to the verified token's original expiration. Timeout, empty, unsupported or failed results cannot become local/stale success. There is no positive cache or retry. Response bytes, including error bodies, are limited to 16 KiB before native coercion; duplicate keys, invalid UTF-8 and wrong wire types refuse. Errors have fixed messages without raw causes. The native Jackson codec receives Spring's supported suppress-logging hint. The existing internal BearerToken carrier renders a constant redaction; its value/type/masked APIs remain available and must not be logged.
+
+The owned client uses an explicit HTTPS endpoint with ordinary platform trust/hostname validation, redirects disabled and finite connect/read timeouts. It owns only the client it constructs. A supplied custom introspector remains caller-owned and must actually implement the uncached current-state contract. Close/cancel propagate through supported APIs; no guarantee of physical socket/thread termination or provider revocation follows from this mode.
+
+## Custom security chains
+
+The default Jafly chain wraps its injected decoder in LIVE mode. An application that completely replaces SecurityWebFilterChain must explicitly use `new LiveActiveJwtDecoder(localDecoder, livePort, properties)` in its own native Spring JWT DSL and qualify actual protected routes. A property or port bean alone cannot prove arbitrary custom-chain adoption. The retained direct five-argument default-chain factory supports LOCAL_JWT; it refuses a LIVE request without the explicit port.
+
+## Deployment verification
+
+Verify actual protected routes with the configured issuer, audience, signed client claim and current-state response. Provider acceptance must prove the required disable, logout and permanent-account-block behavior with old unexpired credentials and new session attempts. RFC 7662 active-state semantics alone do not establish that behavior. Account locking, SCA recovery, delegation and token exchange require their own application and identity-service contracts.
diff --git a/modules/security-resource-server/pom.xml b/modules/security-resource-server/pom.xml
index 5b18064e0..7b377e900 100644
--- a/modules/security-resource-server/pom.xml
+++ b/modules/security-resource-server/pom.xml
@@ -53,6 +53,12 @@
provided
+
+
+ tools.jackson.core
+ jackson-databind
+
+
org.springframework.boot
diff --git a/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/LiveActiveJwtDecoder.java b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/LiveActiveJwtDecoder.java
new file mode 100644
index 000000000..7e0da935d
--- /dev/null
+++ b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/LiveActiveJwtDecoder.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2024-2026 Firefly Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.fireflyframework.security.rs;
+
+import org.fireflyframework.security.api.domain.BearerToken;
+import org.fireflyframework.security.api.domain.SecurityPrincipal;
+import org.fireflyframework.security.spi.TokenValidationPort;
+import org.springframework.security.oauth2.jwt.BadJwtException;
+import org.springframework.security.oauth2.jwt.Jwt;
+import org.springframework.security.oauth2.jwt.ReactiveJwtDecoder;
+import reactor.core.publisher.Mono;
+
+import java.time.Clock;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.function.LongSupplier;
+
+/** Adds uncached current-state admission to a locally verified JWT without replacing its claims. */
+public final class LiveActiveJwtDecoder implements ReactiveJwtDecoder {
+ private final ReactiveJwtDecoder local;
+ private final TokenValidationPort live;
+ private final Settings settings;
+ private final Clock clock;
+ private final LongSupplier nanos;
+
+ public LiveActiveJwtDecoder(ReactiveJwtDecoder local, TokenValidationPort live,
+ ResourceServerProperties properties) {
+ this(local, live, properties, Clock.systemUTC(), System::nanoTime);
+ }
+
+ public LiveActiveJwtDecoder(ReactiveJwtDecoder local, TokenValidationPort live,
+ ResourceServerProperties properties, Clock clock, LongSupplier nanos) {
+ this.local = Objects.requireNonNull(local);
+ this.live = Objects.requireNonNull(live);
+ this.settings = Settings.from(properties);
+ this.clock = Objects.requireNonNull(clock);
+ this.nanos = Objects.requireNonNull(nanos);
+ }
+
+ @Override
+ public Mono decode(String token) {
+ return Mono.defer(() -> {
+ long start = nanos.getAsLong();
+ return Mono.defer(() -> local.decode(token))
+ .switchIfEmpty(Mono.error(refused()))
+ .flatMap(jwt -> {
+ Binding original = Binding.local(jwt, settings);
+ Duration remaining = remaining(start, original.expiration());
+ return Mono.defer(() -> live.validateLive(BearerToken.of(token)))
+ .switchIfEmpty(Mono.error(refused()))
+ .timeout(remaining)
+ .map(principal -> {
+ Binding observed = Binding.remote(principal, settings);
+ if (!original.matches(observed)) {
+ throw refused();
+ }
+ if (!original.equals(Binding.local(jwt, settings))) {
+ throw refused();
+ }
+ remaining(start, original.expiration());
+ return jwt;
+ });
+ })
+ .timeout(settings.timeout())
+ .onErrorMap(error -> refused());
+ }).onErrorMap(error -> refused());
+ }
+
+ private Duration remaining(long start, Instant expiration) {
+ long elapsed = nanos.getAsLong() - start;
+ if (elapsed < 0 || elapsed >= settings.timeout().toNanos()) {
+ throw refused();
+ }
+ Duration untilExpiration = Duration.between(clock.instant(), expiration);
+ Duration work = Duration.ofNanos(settings.timeout().toNanos() - elapsed);
+ Duration remaining = work.compareTo(untilExpiration) < 0 ? work : untilExpiration;
+ if (remaining.isNegative() || remaining.isZero()) {
+ throw refused();
+ }
+ return remaining;
+ }
+
+ private static BadJwtException refused() {
+ return new BadJwtException("Live token admission refused");
+ }
+
+ static String text(Object value) {
+ if (!(value instanceof String text) || text.isBlank() || text.length() > 2048) {
+ throw new IllegalArgumentException("Invalid live token metadata");
+ }
+ for (int i = 0; i < text.length(); i++) {
+ char c = text.charAt(i);
+ if (Character.isISOControl(c) || Character.isLowSurrogate(c)) {
+ throw new IllegalArgumentException("Invalid live token metadata");
+ }
+ if (Character.isHighSurrogate(c)) {
+ if (++i == text.length() || !Character.isLowSurrogate(text.charAt(i))) {
+ throw new IllegalArgumentException("Invalid live token metadata");
+ }
+ }
+ }
+ return text;
+ }
+
+ static Set audience(Object value) {
+ if (!(value instanceof List> list) || list.isEmpty() || list.size() > 32) {
+ throw new IllegalArgumentException("Invalid live token audience");
+ }
+ Set result = new HashSet<>();
+ for (Object item : list) {
+ if (!result.add(text(item))) {
+ throw new IllegalArgumentException("Invalid live token audience");
+ }
+ }
+ return Set.copyOf(result);
+ }
+
+ record Settings(String issuer, Set audiences, Set clients, String clientClaim,
+ Duration timeout) {
+ static Settings from(ResourceServerProperties properties) {
+ if (properties == null || properties.getAdmissionMode() != ResourceServerProperties.JwtAdmissionMode.LIVE
+ || properties.getLiveState() == null) {
+ throw new IllegalArgumentException("Live admission configuration is required");
+ }
+ var live = properties.getLiveState();
+ Duration timeout = live.getTimeout();
+ if (timeout == null || timeout.isZero() || timeout.isNegative()
+ || timeout.compareTo(Duration.ofSeconds(5)) > 0) {
+ throw new IllegalArgumentException("Live admission timeout must be positive and at most five seconds");
+ }
+ return new Settings(text(properties.getIssuer()), audience(properties.getAudiences()),
+ audience(live.getAllowedClients()), text(live.getTokenClientClaim()), timeout);
+ }
+ @Override public String toString() { return "LiveSettings[REDACTED]"; }
+ }
+
+ record Binding(String issuer, String subject, Set audiences, String client,
+ Instant expiration, String tokenId) {
+ static Binding local(Jwt jwt, Settings settings) {
+ return read(jwt.getClaims(), settings.clientClaim(), settings);
+ }
+ static Binding remote(SecurityPrincipal principal, Settings settings) {
+ Binding binding = read(principal.claims(), "client_id", settings);
+ if (!binding.issuer().equals(principal.issuer()) || !binding.subject().equals(principal.subject())) {
+ throw refused();
+ }
+ return binding;
+ }
+ private static Binding read(Map claims, String clientClaim, Settings settings) {
+ String issuer = text(claims.get("iss"));
+ String subject = text(claims.get("sub"));
+ Set audiences = audience(claims.get("aud"));
+ String client = text(claims.get(clientClaim));
+ if (!(claims.get("exp") instanceof Instant expiration)
+ || !issuer.equals(settings.issuer()) || !settings.clients().contains(client)
+ || audiences.stream().noneMatch(settings.audiences()::contains)) {
+ throw refused();
+ }
+ String tokenId = claims.containsKey("jti") ? text(claims.get("jti")) : null;
+ return new Binding(issuer, subject, audiences, client, expiration, tokenId);
+ }
+ boolean matches(Binding observed) {
+ return issuer.equals(observed.issuer) && subject.equals(observed.subject)
+ && audiences.equals(observed.audiences) && client.equals(observed.client)
+ && expiration.equals(observed.expiration)
+ && (tokenId == null || tokenId.equals(observed.tokenId));
+ }
+ @Override public String toString() { return "LiveBinding[REDACTED]"; }
+ }
+}
diff --git a/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/LiveIntrospectionResponseGuard.java b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/LiveIntrospectionResponseGuard.java
new file mode 100644
index 000000000..b048b7190
--- /dev/null
+++ b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/LiveIntrospectionResponseGuard.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright 2024-2026 Firefly Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.fireflyframework.security.rs;
+
+import org.springframework.core.io.buffer.DataBufferUtils;
+import org.springframework.http.MediaType;
+import org.springframework.security.oauth2.server.resource.introspection.OAuth2IntrospectionException;
+import org.springframework.web.reactive.function.client.ClientRequest;
+import org.springframework.web.reactive.function.client.ClientResponse;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
+import org.springframework.web.reactive.function.client.ExchangeFunction;
+import reactor.core.publisher.Mono;
+import tools.jackson.core.StreamReadConstraints;
+import tools.jackson.core.StreamReadFeature;
+import tools.jackson.core.json.JsonFactory;
+import tools.jackson.databind.DeserializationFeature;
+import tools.jackson.databind.JsonNode;
+import tools.jackson.databind.json.JsonMapper;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.CodingErrorAction;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.util.HashSet;
+
+/** Validates bounded wire types before the native introspector performs claim coercion. */
+public final class LiveIntrospectionResponseGuard implements ExchangeFilterFunction {
+ public static final int MAX_RESPONSE_BYTES = 16 * 1024;
+ private final JsonMapper mapper = JsonMapper.builder(JsonFactory.builder()
+ .enable(StreamReadFeature.STRICT_DUPLICATE_DETECTION)
+ .streamReadConstraints(StreamReadConstraints.builder()
+ .maxDocumentLength(MAX_RESPONSE_BYTES).maxNestingDepth(16).maxTokenCount(4096)
+ .maxNameLength(256).maxStringLength(MAX_RESPONSE_BYTES).maxNumberLength(32).build())
+ .build()).enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS).build();
+
+ @Override
+ public Mono filter(ClientRequest request, ExchangeFunction next) {
+ return Mono.defer(() -> next.exchange(request))
+ .flatMap(response -> DataBufferUtils.join(response.bodyToFlux(org.springframework.core.io.buffer.DataBuffer.class),
+ MAX_RESPONSE_BYTES)
+ .switchIfEmpty(Mono.error(refused()))
+ .map(buffer -> {
+ byte[] bytes;
+ try {
+ bytes = new byte[buffer.readableByteCount()];
+ buffer.read(bytes);
+ } finally {
+ DataBufferUtils.release(buffer);
+ }
+ try {
+ if (response.statusCode().value() != 200) {
+ throw refused();
+ }
+ MediaType type = response.headers().contentType().orElseThrow(LiveIntrospectionResponseGuard::refused);
+ if (!MediaType.APPLICATION_JSON.isCompatibleWith(type)
+ || (type.getCharset() != null && !StandardCharsets.UTF_8.equals(type.getCharset()))) {
+ throw refused();
+ }
+ String body = StandardCharsets.UTF_8.newDecoder()
+ .onMalformedInput(CodingErrorAction.REPORT)
+ .onUnmappableCharacter(CodingErrorAction.REPORT)
+ .decode(ByteBuffer.wrap(bytes)).toString();
+ validate(mapper.readTree(body));
+ return response.mutate().body(body).build();
+ } catch (Exception error) {
+ throw refused();
+ }
+ }))
+ .onErrorMap(error -> refused());
+ }
+
+ private static void validate(JsonNode root) {
+ if (!root.isObject() || root.get("active") == null || !root.get("active").isBoolean()) {
+ throw refused();
+ }
+ if (!root.get("active").asBoolean()) {
+ return;
+ }
+ string(root.get("iss"));
+ string(root.get("sub"));
+ string(root.get("client_id"));
+ JsonNode audience = root.get("aud");
+ if (audience == null) {
+ throw refused();
+ }
+ if (audience.isString()) {
+ string(audience);
+ } else if (audience.isArray() && audience.size() > 0 && audience.size() <= 32) {
+ var seen = new HashSet();
+ for (int i = 0; i < audience.size(); i++) {
+ if (!seen.add(string(audience.get(i)))) {
+ throw refused();
+ }
+ }
+ } else {
+ throw refused();
+ }
+ time(root.get("exp"));
+ for (String optional : new String[]{"iat", "nbf"}) {
+ if (root.get(optional) != null) {
+ time(root.get(optional));
+ }
+ }
+ for (String optional : new String[]{"jti", "scope"}) {
+ if (root.get(optional) != null) {
+ string(root.get(optional));
+ }
+ }
+ }
+
+ private static String string(JsonNode node) {
+ if (node == null || !node.isString()) {
+ throw refused();
+ }
+ return LiveActiveJwtDecoder.text(node.stringValue());
+ }
+
+ private static void time(JsonNode node) {
+ if (node == null || !node.isIntegralNumber() || !node.canConvertToLong() || node.asLong() <= 0) {
+ throw refused();
+ }
+ Instant.ofEpochSecond(node.asLong());
+ }
+
+ private static OAuth2IntrospectionException refused() {
+ return new OAuth2IntrospectionException("Live introspection response refused");
+ }
+}
diff --git a/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/ResourceServerAutoConfiguration.java b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/ResourceServerAutoConfiguration.java
index ce3da6b46..b10ab3263 100644
--- a/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/ResourceServerAutoConfiguration.java
+++ b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/ResourceServerAutoConfiguration.java
@@ -31,6 +31,7 @@
import org.fireflyframework.security.spi.KeyManagementPort;
import org.fireflyframework.security.spi.PolicyDecisionPort;
import org.fireflyframework.security.spi.SecurityContextPort;
+import org.fireflyframework.security.spi.TokenValidationPort;
import org.fireflyframework.security.webflux.authentication.FireflyAuthenticationToken;
import org.fireflyframework.security.webflux.authz.PolicyAuthorizationManager;
import org.fireflyframework.security.webflux.context.ReactorSecurityContextAdapter;
@@ -188,9 +189,46 @@ private static List> buildValidators(ResourceServerPro
return validators;
}
+ @Bean(destroyMethod = "close")
+ @ConditionalOnMissingBean(TokenValidationPort.class)
+ @ConditionalOnProperty(prefix = "firefly.security.resource-server", name = "admission-mode", havingValue = "LIVE")
+ public SpringLiveTokenValidationAdapter fireflyLiveTokenValidationPort(ResourceServerProperties properties) {
+ return SpringLiveTokenValidationAdapter.create(properties);
+ }
+
+ /** Retains the direct LOCAL factory API; LIVE callers must supply the explicit port. */
+ public SecurityWebFilterChain fireflySecurityWebFilterChain(
+ ServerHttpSecurity http,
+ ReactiveJwtDecoder jwtDecoder,
+ Converter> jwtAuthenticationConverter,
+ PolicyDecisionPort policyDecisionPort,
+ ResourceServerProperties properties) {
+ if (properties.getAdmissionMode() != ResourceServerProperties.JwtAdmissionMode.LOCAL_JWT) {
+ throw new IllegalArgumentException("An explicit live validation port is required");
+ }
+ return buildSecurityWebFilterChain(http, jwtDecoder, jwtAuthenticationConverter, policyDecisionPort, properties);
+ }
+
@Bean
@ConditionalOnMissingBean
public SecurityWebFilterChain fireflySecurityWebFilterChain(
+ ServerHttpSecurity http,
+ ReactiveJwtDecoder jwtDecoder,
+ Converter> jwtAuthenticationConverter,
+ PolicyDecisionPort policyDecisionPort,
+ ResourceServerProperties properties,
+ ObjectProvider livePorts) {
+ ReactiveJwtDecoder selected = jwtDecoder;
+ if (properties.getAdmissionMode() == ResourceServerProperties.JwtAdmissionMode.LIVE) {
+ TokenValidationPort live = livePorts.getObject();
+ selected = new LiveActiveJwtDecoder(jwtDecoder, live, properties);
+ } else if (properties.getAdmissionMode() != ResourceServerProperties.JwtAdmissionMode.LOCAL_JWT) {
+ throw new IllegalArgumentException("A valid JWT admission mode is required");
+ }
+ return buildSecurityWebFilterChain(http, selected, jwtAuthenticationConverter, policyDecisionPort, properties);
+ }
+
+ private SecurityWebFilterChain buildSecurityWebFilterChain(
ServerHttpSecurity http,
ReactiveJwtDecoder jwtDecoder,
Converter> jwtAuthenticationConverter,
diff --git a/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/ResourceServerProperties.java b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/ResourceServerProperties.java
index e21ea5d35..ef42c7a5d 100644
--- a/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/ResourceServerProperties.java
+++ b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/ResourceServerProperties.java
@@ -31,6 +31,25 @@
@ConfigurationProperties(prefix = "firefly.security.resource-server")
public class ResourceServerProperties {
+ public enum JwtAdmissionMode { LOCAL_JWT, LIVE }
+
+ /** Existing local verification remains the general default. */
+ private JwtAdmissionMode admissionMode = JwtAdmissionMode.LOCAL_JWT;
+ private LiveState liveState = new LiveState();
+
+ /** No generated toString: these settings include an introspection credential. */
+ @lombok.Getter
+ @lombok.Setter
+ public static class LiveState {
+ private String introspectionUri;
+ private String introspectionClientId;
+ private String introspectionClientSecret;
+ private String tokenClientClaim;
+ private List allowedClients = new ArrayList<>();
+ private java.time.Duration timeout = java.time.Duration.ofSeconds(5);
+ }
+
+
/** Ant-style path patterns that are publicly accessible without authentication. */
private List permitMatchers = new ArrayList<>();
diff --git a/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/SpringLiveTokenValidationAdapter.java b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/SpringLiveTokenValidationAdapter.java
new file mode 100644
index 000000000..8bed1f5b2
--- /dev/null
+++ b/modules/security-resource-server/src/main/java/org/fireflyframework/security/rs/SpringLiveTokenValidationAdapter.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2024-2026 Firefly Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.fireflyframework.security.rs;
+
+import org.fireflyframework.security.api.domain.BearerToken;
+import org.fireflyframework.security.api.domain.SecurityPrincipal;
+import org.fireflyframework.security.api.exception.TokenValidationException;
+import org.fireflyframework.security.spi.TokenValidationPort;
+import org.springframework.http.client.reactive.JdkClientHttpConnector;
+import org.springframework.http.client.reactive.ClientHttpConnector;
+import org.reactivestreams.Publisher;
+import org.springframework.core.ResolvableType;
+import org.springframework.core.codec.Hints;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.util.MimeType;
+import reactor.core.publisher.Flux;
+import org.springframework.http.codec.json.JacksonJsonDecoder;
+import org.springframework.security.oauth2.server.resource.introspection.ReactiveOpaqueTokenIntrospector;
+import org.springframework.security.oauth2.server.resource.introspection.SpringReactiveOpaqueTokenIntrospector;
+import org.springframework.web.reactive.function.client.WebClient;
+import reactor.core.publisher.Mono;
+
+import java.net.URI;
+import java.net.URLEncoder;
+import java.net.http.HttpClient;
+import java.nio.charset.StandardCharsets;
+import java.time.Clock;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/** An uncached native Spring introspection client. Provider revocation behavior needs separate acceptance. */
+public final class SpringLiveTokenValidationAdapter implements TokenValidationPort, AutoCloseable {
+ private final ReactiveOpaqueTokenIntrospector introspector;
+ private final LiveActiveJwtDecoder.Settings settings;
+ private final Clock clock;
+ private final HttpClient ownedClient;
+ private final AtomicBoolean closed = new AtomicBoolean();
+
+ /** The supplied introspector must perform an uncached current-state exchange for each call. */
+ public SpringLiveTokenValidationAdapter(ReactiveOpaqueTokenIntrospector introspector,
+ ResourceServerProperties properties) {
+ this(introspector, properties, Clock.systemUTC());
+ }
+
+ public SpringLiveTokenValidationAdapter(ReactiveOpaqueTokenIntrospector introspector,
+ ResourceServerProperties properties, Clock clock) {
+ this(introspector, LiveActiveJwtDecoder.Settings.from(properties), clock, null);
+ }
+
+ private SpringLiveTokenValidationAdapter(ReactiveOpaqueTokenIntrospector introspector,
+ LiveActiveJwtDecoder.Settings settings, Clock clock, HttpClient ownedClient) {
+ this.introspector = Objects.requireNonNull(introspector);
+ this.settings = settings;
+ this.clock = Objects.requireNonNull(clock);
+ this.ownedClient = ownedClient;
+ }
+
+ public static SpringLiveTokenValidationAdapter create(ResourceServerProperties properties) {
+ var settings = LiveActiveJwtDecoder.Settings.from(properties);
+ var live = properties.getLiveState();
+ URI endpoint;
+ String clientId;
+ String secret;
+ try {
+ endpoint = URI.create(LiveActiveJwtDecoder.text(live.getIntrospectionUri()));
+ clientId = LiveActiveJwtDecoder.text(live.getIntrospectionClientId());
+ secret = LiveActiveJwtDecoder.text(live.getIntrospectionClientSecret());
+ if (!"https".equals(endpoint.getScheme()) || endpoint.getHost() == null
+ || endpoint.getRawUserInfo() != null || endpoint.getRawQuery() != null
+ || endpoint.getRawFragment() != null || endpoint.getPort() == 0 || endpoint.getPort() > 65535) {
+ throw new IllegalArgumentException();
+ }
+ } catch (RuntimeException error) {
+ throw new IllegalArgumentException("Valid explicit HTTPS introspection configuration is required");
+ }
+ HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.NEVER)
+ .connectTimeout(settings.timeout()).build();
+ try {
+ JdkClientHttpConnector connector = new JdkClientHttpConnector(client);
+ connector.setReadTimeout(settings.timeout());
+ WebClient webClient = ownedWebClientBuilder(connector, clientId, secret).build();
+ return new SpringLiveTokenValidationAdapter(new SpringReactiveOpaqueTokenIntrospector(endpoint.toASCIIString(), webClient),
+ settings, Clock.systemUTC(), client);
+ } catch (RuntimeException error) {
+ client.shutdownNow();
+ throw new IllegalArgumentException("Live introspection client configuration refused");
+ }
+ }
+
+ @Override
+ public Mono validate(BearerToken token) {
+ return validateLive(token);
+ }
+
+ @Override
+ public Mono validateLive(BearerToken token) {
+ return Mono.defer(() -> {
+ long started = System.nanoTime();
+ if (closed.get() || token == null || token.type() != BearerToken.TokenType.JWT
+ || token.value() == null || token.value().isBlank()) {
+ return Mono.error(refused());
+ }
+ return Mono.defer(() -> introspector.introspect(token.value()))
+ .switchIfEmpty(Mono.error(refused()))
+ .timeout(settings.timeout())
+ .map(observed -> {
+ Map claims = new HashMap<>();
+ Map remote = observed.getAttributes();
+ if (!Boolean.TRUE.equals(remote.get("active"))) {
+ throw refused();
+ }
+ for (String name : new String[]{"iss", "sub", "aud", "exp", "client_id", "jti"}) {
+ if (remote.containsKey(name)) {
+ claims.put(name, remote.get(name));
+ }
+ }
+ // Copy and validate the allowed tuple; arbitrary provider attributes never become authentication claims.
+ var principal = SecurityPrincipal.builder()
+ .issuer(LiveActiveJwtDecoder.text(claims.get("iss")))
+ .subject(LiveActiveJwtDecoder.text(claims.get("sub")))
+ .claims(claims).build();
+ var binding = LiveActiveJwtDecoder.Binding.remote(principal, settings);
+ if (!clock.instant().isBefore(binding.expiration()) || closed.get()) {
+ throw refused();
+ }
+ claims.put("aud", java.util.List.copyOf(binding.audiences()));
+ SecurityPrincipal result = principal.toBuilder().claims(claims).build();
+ long elapsed = System.nanoTime() - started;
+ if (elapsed < 0 || elapsed >= settings.timeout().toNanos()
+ || !clock.instant().isBefore(binding.expiration()) || closed.get()) {
+ throw refused();
+ }
+ return result;
+ });
+ }).onErrorMap(error -> refused());
+ }
+
+ @Override
+ public void close() {
+ if (closed.compareAndSet(false, true) && ownedClient != null) {
+ ownedClient.shutdownNow();
+ }
+ }
+
+ static WebClient.Builder ownedWebClientBuilder(ClientHttpConnector connector, String clientId, String secret) {
+ return WebClient.builder().clientConnector(connector)
+ .codecs(codecs -> {
+ codecs.defaultCodecs().maxInMemorySize(LiveIntrospectionResponseGuard.MAX_RESPONSE_BYTES);
+ codecs.defaultCodecs().enableLoggingRequestDetails(false);
+ codecs.defaultCodecs().jacksonJsonDecoder(nativeJsonDecoder());
+ })
+ .defaultHeaders(headers -> headers.setBasicAuth(
+ URLEncoder.encode(clientId, StandardCharsets.UTF_8),
+ URLEncoder.encode(secret, StandardCharsets.UTF_8)))
+ .filter(new LiveIntrospectionResponseGuard());
+ }
+
+ static JacksonJsonDecoder nativeJsonDecoder() {
+ return new QuietJacksonJsonDecoder();
+ }
+
+ /** The native codec honors this public hint before rendering decoded identity attributes. */
+ private static final class QuietJacksonJsonDecoder extends JacksonJsonDecoder {
+ @Override
+ public Flux