Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useful information to the authentication error #5316

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package io.apicurio.registry.rest;

import io.quarkus.security.AuthenticationFailedException;
import io.quarkus.security.UnauthorizedException;
import jakarta.annotation.Priority;
import jakarta.inject.Inject;
import jakarta.ws.rs.Priorities;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;

@Provider
@Priority(Priorities.AUTHENTICATION)
public class AuthenticationFailedExceptionMapper implements ExceptionMapper<UnauthorizedException> {

@Inject
RegistryExceptionMapper exceptionMapperService;

public class AuthenticationFailedExceptionMapper implements ExceptionMapper<AuthenticationFailedException> {
@Override
public Response toResponse(AuthenticationFailedException exception) {
return Response.status(401).build();
public Response toResponse(UnauthorizedException exception) {
Response errorHttpResponse = exceptionMapperService.toResponse(exception);
return Response.status(401).entity(errorHttpResponse).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import org.slf4j.Logger;

/**
* TODO use v1 beans when appropriate (when handling REST API v1 calls)
Expand All @@ -19,9 +18,6 @@
@Provider
public class RegistryExceptionMapper implements ExceptionMapper<Throwable> {

@Inject
Logger log;

@Inject
CoreRegistryExceptionMapperService coreMapper;

Expand Down
11 changes: 11 additions & 0 deletions app/src/test/java/io/apicurio/registry/auth/SimpleAuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.kiota.http.vertx.VertXRequestAdapter;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.vertx.core.Vertx;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
Expand Down Expand Up @@ -90,6 +91,16 @@ public void testWrongCreds() throws Exception {
assertTrue(exception.getMessage().contains("Unauthorized"));
}

@Test
public void testNoCreds() throws Exception {
var adapter = new VertXRequestAdapter(Vertx.vertx());
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);
Assertions.assertThrows(Exception.class, () -> {
client.groups().byGroupId(groupId).artifacts().get();
});
}

@Test
public void testReadOnly() throws Exception {
var adapter = new VertXRequestAdapter(
Expand Down
Loading