-
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.
feat(rest): added rest extension with user info handler
- Loading branch information
1 parent
e8515e7
commit ade002f
Showing
9 changed files
with
264 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>dev.cloudeko</groupId> | ||
<artifactId>rest-extension-parent</artifactId> | ||
<version>0.0.1</version> | ||
</parent> | ||
|
||
<name>Zenei - Extensions - Rest - Deployment</name> | ||
<artifactId>rest-extension-deployment</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>dev.cloudeko</groupId> | ||
<artifactId>core-extension-deployment</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-jackson-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-reactive-jackson-deployment</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>dev.cloudeko</groupId> | ||
<artifactId>rest-extension</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
25 changes: 25 additions & 0 deletions
25
...nt/src/main/java/dev/cloudeko/zenei/extension/rest/deployment/ExternalAuthBuildSteps.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,25 @@ | ||
package dev.cloudeko.zenei.extension.rest.deployment; | ||
|
||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem; | ||
import io.quarkus.vertx.http.deployment.RouteBuildItem; | ||
|
||
public class ExternalAuthBuildSteps { | ||
|
||
private static final String FEATURE = "core"; | ||
|
||
@BuildStep | ||
public FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep | ||
public RouteBuildItem route(NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) { | ||
return nonApplicationRootPathBuildItem.routeBuilder() | ||
.route("custom-endpoint") | ||
.handler(new MyCustomHandler()) | ||
.displayOnNotFoundPage() | ||
.build(); | ||
} | ||
} |
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>dev.cloudeko</groupId> | ||
<artifactId>extensions</artifactId> | ||
<version>0.0.1</version> | ||
</parent> | ||
|
||
<name>Zenei - Extensions - Rest - Parent</name> | ||
<artifactId>rest-extension-parent</artifactId> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
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,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>dev.cloudeko</groupId> | ||
<artifactId>rest-extension-parent</artifactId> | ||
<version>0.0.1</version> | ||
</parent> | ||
|
||
<name>Zenei - Extensions - Rest - Runtime</name> | ||
<artifactId>rest-extension</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>dev.cloudeko</groupId> | ||
<artifactId>core-extension</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-reactive-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${org.projectlombok.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-maven-plugin</artifactId> | ||
<version>${quarkus.version}</version> | ||
<executions> | ||
<execution> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>extension-descriptor</goal> | ||
</goals> | ||
<configuration> | ||
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version} | ||
</deployment> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<compilerArgs> | ||
<arg>-parameters</arg> | ||
</compilerArgs> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${org.projectlombok.version}</version> | ||
</path> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
55 changes: 55 additions & 0 deletions
55
...time/src/main/java/dev/cloudeko/zenei/extension/rest/endpoint/client/UserInfoHandler.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,55 @@ | ||
package dev.cloudeko.zenei.extension.rest.endpoint.client; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import dev.cloudeko.zenei.extension.core.feature.FindUserByIdentifier; | ||
import dev.cloudeko.zenei.extension.core.model.user.User; | ||
import io.quarkus.arc.Arc; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
import io.quarkus.vertx.http.runtime.security.QuarkusHttpUser; | ||
import io.vertx.core.Handler; | ||
import io.vertx.core.http.HttpMethod; | ||
import io.vertx.core.http.HttpServerRequest; | ||
import io.vertx.core.http.HttpServerResponse; | ||
import io.vertx.ext.web.RoutingContext; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
/** | ||
* Handler that serves the user information of the authenticated user. | ||
*/ | ||
public class UserInfoHandler implements Handler<RoutingContext> { | ||
|
||
private static final String ALLOWED_METHODS = "GET, HEAD, OPTIONS"; | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
private volatile FindUserByIdentifier findUserByIdentifier; | ||
|
||
@Override | ||
public void handle(RoutingContext routingContext) { | ||
HttpServerRequest req = routingContext.request(); | ||
HttpServerResponse resp = routingContext.response(); | ||
|
||
QuarkusHttpUser quarkusUser = (QuarkusHttpUser) routingContext.user(); | ||
|
||
if (req.method().equals(HttpMethod.OPTIONS)) { | ||
resp.headers().set("Allow", ALLOWED_METHODS); | ||
routingContext.next(); | ||
} else { | ||
resp.headers().set("Content-Type", MediaType.APPLICATION_JSON + ";charset=UTF-8"); | ||
SecurityIdentity securityIdentity = quarkusUser.getSecurityIdentity(); | ||
User user = findUserByIdentifier(securityIdentity.getPrincipal().getName()); | ||
try { | ||
resp.end(objectMapper.writeValueAsString(user)); | ||
} catch (Exception e) { | ||
resp.setStatusCode(500).end(); | ||
} | ||
} | ||
} | ||
|
||
public User findUserByIdentifier(String identifier) { | ||
if (this.findUserByIdentifier == null) { | ||
this.findUserByIdentifier = Arc.container().instance(FindUserByIdentifier.class).get(); | ||
} | ||
|
||
return this.findUserByIdentifier.handle(identifier); | ||
} | ||
} |
Empty file.
9 changes: 9 additions & 0 deletions
9
extensions/rest/runtime/src/main/resources/META-INF/quarkus-extension.yaml
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,9 @@ | ||
name: Zenei Quarkus Rest Extension | ||
#description: Do something useful. | ||
metadata: | ||
# keywords: | ||
# - "key-auth" | ||
# guide: ... # To create and publish this guide, see https://github.com/quarkiverse/quarkiverse/wiki#documenting-your-extension | ||
# categories: | ||
# - "miscellaneous" | ||
# status: "preview" |
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