Skip to content

Commit 815d07b

Browse files
committed
Review fixes
1 parent b8a6169 commit 815d07b

19 files changed

Lines changed: 48 additions & 174 deletions

File tree

reference/common/src/main/java/org/a2aproject/sdk/server/common/quarkus/VertxSecurityHelper.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import io.quarkus.arc.Arc;
88
import io.quarkus.arc.ManagedContext;
99
import io.quarkus.security.identity.CurrentIdentityAssociation;
10+
import io.quarkus.vertx.http.runtime.security.ChallengeData;
1011
import io.quarkus.vertx.http.runtime.security.HttpAuthenticator;
12+
import io.vertx.core.Context;
1113
import io.vertx.ext.web.RoutingContext;
1214

1315
/**
@@ -48,7 +50,7 @@
4850
* myAuthenticatedMethod(); // Has @Authenticated annotation
4951
* });
5052
* } catch (UnauthorizedException | ForbiddenException e) {
51-
* VertxSecurityHelper.handleAuthError(ctx, e);
53+
* securityHelper.handleAuthError(ctx, e);
5254
* } catch (Exception e) {
5355
* VertxSecurityHelper.handleGenericError(ctx);
5456
* }
@@ -68,9 +70,8 @@ public final class VertxSecurityHelper {
6870
@Inject
6971
Instance<CurrentIdentityAssociation> currentIdentityAssociation;
7072

71-
7273
public VertxSecurityHelper() {
73-
// Utility class - no instantiation
74+
// CDI-managed constructor
7475
}
7576

7677
/**
@@ -98,6 +99,10 @@ public VertxSecurityHelper() {
9899
* @throws RuntimeException if the task throws an exception
99100
*/
100101
public void runInRequestContext(RoutingContext ctx, Runnable task) {
102+
if (Context.isOnEventLoopThread()) {
103+
throw new IllegalStateException(
104+
"Cannot perform blocking authentication on event loop thread. Use blockingHandler().");
105+
}
101106
ManagedContext requestContext = Arc.container().requestContext();
102107
boolean wasActive = requestContext.isActive();
103108
if (!wasActive) {
@@ -124,22 +129,31 @@ public void runInRequestContext(RoutingContext ctx, Runnable task) {
124129
*
125130
* <ul>
126131
* <li>{@code ForbiddenException} → HTTP 403 Forbidden</li>
127-
* <li>All other auth errors → HTTP 401 Unauthorized with {@code WWW-Authenticate: Basic} header</li>
132+
* <li>All other auth errors → delegates to {@link HttpAuthenticator#getChallenge} to obtain
133+
* the correct {@code WWW-Authenticate} header for the configured auth mechanism
134+
* (Basic, Bearer, etc.) and sends HTTP 401 with the challenge header</li>
128135
* </ul>
129136
*
130137
* @param ctx the routing context
131138
* @param e the authentication or authorization exception
132139
*/
133-
public static void handleAuthError(RoutingContext ctx, Exception e) {
140+
public void handleAuthError(RoutingContext ctx, Exception e) {
134141
if (!ctx.response().ended()) {
135142
if (e instanceof io.quarkus.security.ForbiddenException) {
136143
ctx.response()
137144
.setStatusCode(403)
138145
.end();
139146
} else {
147+
int status = 401;
148+
if (!httpAuthenticator.isUnsatisfied()) {
149+
ChallengeData challenge = httpAuthenticator.get().getChallenge(ctx).await().indefinitely();
150+
if (challenge != null) {
151+
status = challenge.status;
152+
ctx.response().putHeader(challenge.headerName, challenge.headerContent);
153+
}
154+
}
140155
ctx.response()
141-
.setStatusCode(401)
142-
.putHeader("WWW-Authenticate", "Basic realm=\"Quarkus\"")
156+
.setStatusCode(status)
143157
.end();
144158
}
145159
}

reference/grpc/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@
105105
<artifactId>quarkus-elytron-security-properties-file</artifactId>
106106
<scope>test</scope>
107107
</dependency>
108-
<dependency>
109-
<groupId>io.quarkus</groupId>
110-
<artifactId>quarkus-test-security</artifactId>
111-
<scope>test</scope>
112-
</dependency>
113108
</dependencies>
114109

115-
</project>
110+
</project>

reference/grpc/src/test/java/org/a2aproject/sdk/server/grpc/quarkus/AuthTestProfile.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

reference/grpc/src/test/java/org/a2aproject/sdk/server/grpc/quarkus/QuarkusA2AGrpcWithAuthTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.a2aproject.sdk.client.transport.spi.interceptors.auth.AuthInterceptor;
99
import org.a2aproject.sdk.server.PublicAgentCard;
1010
import org.a2aproject.sdk.server.apps.common.AbstractA2AServerWithAuthTest;
11+
import org.a2aproject.sdk.server.apps.common.AuthTestProfile;
1112
import org.a2aproject.sdk.spec.AgentCard;
1213
import org.a2aproject.sdk.spec.TransportProtocol;
1314
import io.grpc.ManagedChannel;

reference/jsonrpc/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,5 @@
110110
<artifactId>quarkus-elytron-security-properties-file</artifactId>
111111
<scope>test</scope>
112112
</dependency>
113-
<dependency>
114-
<groupId>io.quarkus</groupId>
115-
<artifactId>quarkus-test-security</artifactId>
116-
<scope>test</scope>
117-
</dependency>
118113
</dependencies>
119114
</project>

reference/jsonrpc/src/main/java/org/a2aproject/sdk/server/apps/quarkus/A2AServerRoutes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void setupRoutes(@Observes Router router) {
216216
invokeJSONRPCHandler(ctx.body().asString(), ctx);
217217
});
218218
} catch (UnauthorizedException | ForbiddenException e) {
219-
VertxSecurityHelper.handleAuthError(ctx, e);
219+
vertxSecurityHelper.handleAuthError(ctx, e);
220220
} catch (Exception e) {
221221
VertxSecurityHelper.handleGenericError(ctx);
222222
}

reference/jsonrpc/src/test/java/org/a2aproject/sdk/server/apps/quarkus/QuarkusA2AJSONRPCWithAuthJdkTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.a2aproject.sdk.client.transport.jsonrpc.JSONRPCTransportConfigBuilder;
88
import org.a2aproject.sdk.client.transport.spi.interceptors.auth.AuthInterceptor;
99
import org.a2aproject.sdk.server.apps.common.AbstractA2AServerWithAuthTest;
10+
import org.a2aproject.sdk.server.apps.common.AuthTestProfile;
1011
import org.a2aproject.sdk.spec.TransportProtocol;
1112
import io.quarkus.test.junit.QuarkusTest;
1213
import io.quarkus.test.junit.TestProfile;

reference/jsonrpc/src/test/java/org/a2aproject/sdk/server/apps/quarkus/QuarkusA2AJSONRPCWithAuthVertxTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.a2aproject.sdk.client.transport.jsonrpc.JSONRPCTransportConfigBuilder;
88
import org.a2aproject.sdk.client.transport.spi.interceptors.auth.AuthInterceptor;
99
import org.a2aproject.sdk.server.apps.common.AbstractA2AServerWithAuthTest;
10+
import org.a2aproject.sdk.server.apps.common.AuthTestProfile;
1011
import org.a2aproject.sdk.spec.TransportProtocol;
1112
import io.quarkus.test.junit.QuarkusTest;
1213
import io.quarkus.test.junit.TestProfile;

reference/jsonrpc/src/test/resources/application.properties

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,3 @@ quarkus.arc.selected-alternatives=org.a2aproject.sdk.server.apps.common.TestHttp
44
quarkus.log.category."org.a2aproject.sdk.server.events".level=DEBUG
55
quarkus.log.category."org.a2aproject.sdk.server.requesthandlers".level=DEBUG
66
quarkus.log.category."org.a2aproject.sdk.server.tasks".level=DEBUG
7-
8-
# Security configuration for regular tests
9-
# Provide a test identity provider that always authenticates
10-
# AuthTestProfile overrides this to require real HTTP Basic Auth
11-
%test.quarkus.test-security.test-enabled=true
12-
%test.quarkus.test-security.user=testuser
13-
%test.quarkus.test-security.roles=user

reference/rest/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@
114114
<artifactId>quarkus-elytron-security-properties-file</artifactId>
115115
<scope>test</scope>
116116
</dependency>
117-
<dependency>
118-
<groupId>io.quarkus</groupId>
119-
<artifactId>quarkus-test-security</artifactId>
120-
<scope>test</scope>
121-
</dependency>
122117
</dependencies>
123118

124119
<build>

0 commit comments

Comments
 (0)