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

Make error message thrown when Quarkus REST and RESTEasy Classic are combined user-friendly again #40718

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
@@ -0,0 +1,31 @@
package io.quarkus.resteasy.test;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.builder.Version;
import io.quarkus.deployment.Capability;
import io.quarkus.maven.dependency.Dependency;
import io.quarkus.test.QuarkusUnitTest;

class UserFriendlyQuarkusRESTCapabilityCombinationTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-rest-deployment", Version.getVersion())))
.assertException(t -> {
assertTrue(t.getMessage().contains("only one provider of the following capabilities"), t.getMessage());
assertTrue(t.getMessage().contains("capability %s is provided by".formatted(Capability.REST)), t.getMessage());
});

@Test
public void test() {
fail();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import io.quarkus.arc.processor.BuildExtension;
import io.quarkus.arc.processor.ObserverInfo;
import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand Down Expand Up @@ -519,6 +520,7 @@ void transformSecurityAnnotations(BuildProducer<AnnotationsTransformerBuildItem>
}
}

@Consume(Capabilities.class) // make sure extension combinations are validated before default security check
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
void gatherSecurityChecks(BuildProducer<SyntheticBeanBuildItem> syntheticBeans,
Expand All @@ -529,7 +531,7 @@ void gatherSecurityChecks(BuildProducer<SyntheticBeanBuildItem> syntheticBeans,
BuildProducer<RunTimeConfigBuilderBuildItem> configBuilderProducer,
List<AdditionalSecuredMethodsBuildItem> additionalSecuredMethods,
SecurityCheckRecorder recorder,
Optional<DefaultSecurityCheckBuildItem> defaultSecurityCheckBuildItem,
List<DefaultSecurityCheckBuildItem> defaultSecurityCheckBuildItem,
BuildProducer<ReflectiveClassBuildItem> reflectiveClassBuildItemBuildProducer,
List<AdditionalSecurityCheckBuildItem> additionalSecurityChecks, SecurityBuildTimeConfig config) {
classPredicate.produce(new ApplicationClassPredicateBuildItem(new SecurityCheckStorageAppPredicate()));
Expand Down Expand Up @@ -563,8 +565,14 @@ void gatherSecurityChecks(BuildProducer<SyntheticBeanBuildItem> syntheticBeans,
methodEntry.getValue());
}

if (defaultSecurityCheckBuildItem.isPresent()) {
var roles = defaultSecurityCheckBuildItem.get().getRolesAllowed();
if (!defaultSecurityCheckBuildItem.isEmpty()) {
if (defaultSecurityCheckBuildItem.size() > 1) {
int itemCount = defaultSecurityCheckBuildItem.size();
throw new IllegalStateException("Found %d DefaultSecurityCheckBuildItem items, ".formatted(itemCount)
+ "please make sure the item is produced exactly once");
}

var roles = defaultSecurityCheckBuildItem.get(0).getRolesAllowed();
if (roles == null) {
recorder.registerDefaultSecurityCheck(builder, recorder.denyAll());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
import java.util.List;
import java.util.Objects;

import io.quarkus.builder.item.SimpleBuildItem;

public final class DefaultSecurityCheckBuildItem extends SimpleBuildItem {
import io.quarkus.builder.item.MultiBuildItem;

/**
* Registers default SecurityCheck with the SecurityCheckStorage.
* Please make sure this build item is produced exactly once or validation will fail and exception will be thrown.
*/
public final class DefaultSecurityCheckBuildItem
// we make this Multi to run CapabilityAggregationStep#aggregateCapabilities first
// so that user-friendly error message is logged when Quarkus REST and RESTEasy are used together
extends MultiBuildItem {

public final List<String> rolesAllowed;

Expand Down
Loading