-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
OpenAPI: Always run OpenIDConnectSecurityFilter at runtime #38231
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
310 changes: 151 additions & 159 deletions
310
...oyment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
...ent/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OIDCSecurityAutoAddTestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.smallrye.openapi.test.jaxrs; | ||
|
||
import java.util.List; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.Version; | ||
import io.quarkus.maven.dependency.Dependency; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
class OIDCSecurityAutoAddTestTest extends OIDCSecurityTestBase { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(OpenApiResource.class, ResourceBean.class) | ||
.addAsResource( | ||
new StringAsset("" | ||
+ "quarkus.smallrye-openapi.security-scheme-name=OIDCCompanyAuthentication\n" | ||
+ "quarkus.smallrye-openapi.security-scheme-description=OIDC Authentication\n" | ||
+ "quarkus.smallrye-openapi.oidc-open-id-connect-url=BUILD-TIME-OVERRIDDEN\n" | ||
+ "quarkus.http.auth.permission.\"oidc\".policy=authenticated\n" | ||
+ "quarkus.http.auth.permission.\"oidc\".paths=/resource/*\n" | ||
+ "quarkus.oidc.auth-server-url=BUILD-TIME-OVERRIDDEN\n" | ||
+ "quarkus.devservices.enabled=false"), | ||
"application.properties")) | ||
.setForcedDependencies(List.of( | ||
Dependency.of("io.quarkus", "quarkus-oidc", Version.getVersion()))) | ||
.overrideRuntimeConfigKey("quarkus.oidc.auth-server-url", "http://localhost:8081/auth/realms/OpenAPIOIDC"); | ||
} |
24 changes: 24 additions & 0 deletions
24
...deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OIDCSecurityTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.smallrye.openapi.test.jaxrs; | ||
|
||
import static org.hamcrest.Matchers.allOf; | ||
import static org.hamcrest.Matchers.hasEntry; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.restassured.RestAssured; | ||
|
||
abstract class OIDCSecurityTestBase { | ||
|
||
@Test | ||
void testOIDCAuthentication() { | ||
RestAssured.given().header("Accept", "application/json") | ||
.when().get("/q/openapi") | ||
.then().body("components.securitySchemes.OIDCCompanyAuthentication", | ||
allOf( | ||
hasEntry("type", "openIdConnect"), | ||
hasEntry("description", "OIDC Authentication"), | ||
hasEntry("openIdConnectUrl", | ||
"http://localhost:8081/auth/realms/OpenAPIOIDC/.well-known/openid-configuration"))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,9 @@ | |
*/ | ||
int priority() default 1; | ||
|
||
static enum RunStage { | ||
enum RunStage { | ||
BUILD, | ||
RUN, | ||
BOTH | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is great PR, but isn't it bit strange that you can override
quarkus.smallrye-openapi.oidc-open-id-connect-url=BUILD-TIME-OVERRIDDEN
withquarkus.oidc.auth-server-url
? If users want to override it, why are setting it at the first place? If they set thequarkus.smallrye-openapi.oidc-open-id-connect-url
maybe they want to generate OpenAPI document for different environment from local computer?I can find arguments against my suggestion, but at least you should document this behavior.
Users can always go wild and do something like
quarkus.smallrye-openapi.oidc-open-id-connect-url=${dev-env-url:${quarkus.oidc.auth-server-url}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalvavrik
Right, this is an existing relationship/functionality. This change enables the override to work even when the application does not use
@RolesAllowed
or@Authenticated
annotations.Almost all of the
quarkus.smallrye-openapi.
configurations are build-time. Eventually, those that modify the final OpenAPI document likequarkus.smallrye-openapi.oidc-open-id-connect-url
should probably be applied at runtime, but that is bigger change. My hope here is to remove a small roadblock that requires users to provide anOASFilter
to set this URL at runtime when they are not using the annotations.I agree that is a likely usage. I think ultimately once
quarkus.smallrye-openapi.oidc-open-id-connect-url
is a runtime config, it would take precedence overquarkus.oidc.auth-server-url
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy that, thanks