forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runtime configuration for HTTP permissions, policy, form auth and realm
closes quarkusio#19162 but mainly this is preparation for quarkusio#16728
- Loading branch information
1 parent
bc39d8a
commit 94d4528
Showing
12 changed files
with
248 additions
and
73 deletions.
There are no files selected for viewing
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
77 changes: 77 additions & 0 deletions
77
.../vertx-http/deployment/src/test/java/io/quarkus/vertx/http/RuntimeRouteCandidateTest.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,77 @@ | ||
package io.quarkus.vertx.http; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem; | ||
import io.quarkus.vertx.http.deployment.RouteBuildItem; | ||
import io.restassured.RestAssured; | ||
import io.vertx.core.Handler; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class RuntimeRouteCandidateTest { | ||
|
||
private static final String APP_PROPS = "" + | ||
"quarkus.http.root-path=/api\n" + | ||
"route[1]=/build-time-route"; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource(new StringAsset(APP_PROPS), "application.properties")) | ||
.addBuildChainCustomizer(buildCustomizer()) | ||
.overrideRuntimeConfigKey("route[1]", "/runtime-route"); | ||
|
||
static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<BuildChainBuilder>() { | ||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(RouteBuildItem.builder() | ||
.route(new PathSupplier()) | ||
.handler(new MyHandler()) | ||
.build()); | ||
} | ||
}).produces(RouteBuildItem.class) | ||
.consumes(NonApplicationRootPathBuildItem.class) | ||
.build(); | ||
} | ||
}; | ||
} | ||
|
||
public static class MyHandler implements Handler<RoutingContext> { | ||
@Override | ||
public void handle(RoutingContext routingContext) { | ||
routingContext.response() | ||
.setStatusCode(200) | ||
.end(routingContext.request().path()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRouteCreatedFromRuntimeProperty() { | ||
RestAssured.given().get("/runtime-route").then().statusCode(200).body(Matchers.equalTo("/api/runtime-route")); | ||
RestAssured.given().get("/build-time-route").then().statusCode(404); | ||
} | ||
|
||
public static class PathSupplier implements Supplier<String> { | ||
|
||
@Override | ||
public String get() { | ||
return ConfigProvider.getConfig().getConfigValue("route[1]").getRawValue(); | ||
} | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...s/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/AuthBuildTimeConfig.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,38 @@ | ||
package io.quarkus.vertx.http.runtime; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
/** | ||
* Authentication mechanism information used for configuring HTTP auth | ||
* instance for the deployment. | ||
*/ | ||
@ConfigGroup | ||
public class AuthBuildTimeConfig { | ||
|
||
/** | ||
* If basic auth should be enabled. If both basic and form auth is enabled then basic auth will be enabled in silent mode. | ||
* | ||
* If no authentication mechanisms are configured basic auth is the default. | ||
*/ | ||
@ConfigItem | ||
public Optional<Boolean> basic; | ||
|
||
/** | ||
* If form authentication is enabled. | ||
*/ | ||
@ConfigItem(name = "form.enabled") | ||
public boolean form; | ||
|
||
/** | ||
* If this is true and credentials are present then a user will always be authenticated | ||
* before the request progresses. | ||
* | ||
* If this is false then an attempt will only be made to authenticate the user if a permission | ||
* check is performed or the current user is required for some other reason. | ||
*/ | ||
@ConfigItem(defaultValue = "true") | ||
public boolean proactive; | ||
} |
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
43 changes: 43 additions & 0 deletions
43
...nsions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/RouteCandidate.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,43 @@ | ||
package io.quarkus.vertx.http.runtime; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
import io.vertx.ext.web.Route; | ||
import io.vertx.ext.web.Router; | ||
|
||
/** | ||
* Creates {@link Function<Router, Route>} if {@link #path} underlying value | ||
* is not null during runtime init. | ||
*/ | ||
public class RouteCandidate implements Function<Router, Route> { | ||
|
||
private Supplier<String> path; | ||
|
||
public RouteCandidate() { | ||
} | ||
|
||
public RouteCandidate(Supplier<String> path) { | ||
Objects.requireNonNull(path); | ||
this.path = path; | ||
} | ||
|
||
public Supplier<String> getPath() { | ||
return path; | ||
} | ||
|
||
public void setPath(Supplier<String> path) { | ||
this.path = path; | ||
} | ||
|
||
/* RUNTIME_INIT */ | ||
@Override | ||
public Route apply(Router router) { | ||
final String resolvedPath = path.get(); | ||
if (resolvedPath == null) { | ||
return null; | ||
} | ||
return router.route(resolvedPath); | ||
} | ||
} |
Oops, something went wrong.