Skip to content

Commit

Permalink
feat(jdbc): added jdbc extension
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Aug 20, 2024
1 parent 1def690 commit 6572058
Show file tree
Hide file tree
Showing 136 changed files with 391 additions and 158 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cloudeko Zenei

Zenei is a open-source user management system that allows you to use authentication, user management and organizations
Zenei (as Vanguard from japanese) is a open-source user management system that allows you to use authentication, user management and organizations
management in your applications.

It's built with [Quarkus](https://quarkus.io) and provides authentication via OAuth2.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface EmailAddressRepository {

Optional<EmailAddress> findByEmailAddress(String emailAddress);

void confirmEmailAddress(String token);
boolean confirmEmailAddress(String token);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: External Authentication Extension
name: Zenei Quarkus Core Extension
#description: Do something useful.
metadata:
# keywords:
Expand Down
6 changes: 3 additions & 3 deletions extensions/external-authentication/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.cloudeko</groupId>
<artifactId>external-authentication-parent</artifactId>
<artifactId>external-authentication-extension-parent</artifactId>
<version>0.0.1</version>
</parent>

<name>Zenei - Extensions - External Authentication - Deployment</name>
<artifactId>external-authentication-deployment</artifactId>
<artifactId>external-authentication-extension-deployment</artifactId>

<dependencies>
<dependency>
Expand All @@ -27,7 +27,7 @@
</dependency>
<dependency>
<groupId>dev.cloudeko</groupId>
<artifactId>external-authentication</artifactId>
<artifactId>external-authentication-extension</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
2 changes: 1 addition & 1 deletion extensions/external-authentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<name>Zenei - Extensions - External Authentication - Parent</name>
<artifactId>external-authentication-parent</artifactId>
<artifactId>external-authentication-extension-parent</artifactId>
<packaging>pom</packaging>

<modules>
Expand Down
4 changes: 2 additions & 2 deletions extensions/external-authentication/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>dev.cloudeko</groupId>
<artifactId>external-authentication-parent</artifactId>
<artifactId>external-authentication-extension-parent</artifactId>
<version>0.0.1</version>
</parent>

<name>Zenei - Extensions - External Authentication - Runtime</name>
<artifactId>external-authentication</artifactId>
<artifactId>external-authentication-extension</artifactId>

<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.cloudeko.zenei.extension.external.ExternalAuthProvider;
import dev.cloudeko.zenei.extension.external.ExternalAuthResolver;
import dev.cloudeko.zenei.extension.external.config.ExternalAuthProviderConfig;
import dev.cloudeko.zenei.extension.external.config.ExternalAuthProvidersConfig;
import lombok.AllArgsConstructor;

Expand All @@ -14,7 +15,7 @@ public class ConfigurationExternalAuthResolver implements ExternalAuthResolver {

@Override
public Optional<ExternalAuthProvider> getAuthProvider(String providerName) {
final var providerConfig = config.providers().get(providerName.toLowerCase());
ExternalAuthProviderConfig providerConfig = config.providers().get(providerName.toLowerCase());

if (providerConfig == null || !providerConfig.enabled()) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import dev.cloudeko.zenei.extension.external.config.ExternalAuthProviderConfig;
import dev.cloudeko.zenei.extension.external.endpoint.ProviderEndpoints;
import dev.cloudeko.zenei.extension.external.web.client.ExternalProviderAccessToken;
import dev.cloudeko.zenei.extension.external.web.external.BaseExternalClient;
import dev.cloudeko.zenei.extension.external.web.external.discord.DiscordClient;
import dev.cloudeko.zenei.extension.external.web.external.discord.DiscordUser;
import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder;

import java.net.URI;
Expand All @@ -15,19 +17,19 @@ public record DiscordExternalAuthProvider(ExternalAuthProviderConfig config) imp

@Override
public ExternalUserProfile getExternalUserProfile(ExternalProviderAccessToken accessToken) {
final var client = QuarkusRestClientBuilder.newBuilder()
BaseExternalClient<DiscordUser> client = QuarkusRestClientBuilder.newBuilder()
.baseUri(URI.create(getBaseEndpoint()))
.build(DiscordClient.class);

final var user = client.getCurrentlyLoggedInUser("Bearer " + accessToken.getAccessToken());
DiscordUser user = client.getCurrentlyLoggedInUser("Bearer " + accessToken.getAccessToken());

// Avatar URL handling
String avatarUrl;
if (user.getAvatar() == null || user.getAvatar().isEmpty()) {
final var discriminator = Integer.parseInt(user.getDiscriminator());
int discriminator = Integer.parseInt(user.getDiscriminator());
avatarUrl = String.format("https://cdn.discordapp.com/embed/avatars/%d.png", discriminator % 5);
} else {
final var extension = user.getAvatar().startsWith("a_") ? "gif" : "png";
String extension = user.getAvatar().startsWith("a_") ? "gif" : "png";
avatarUrl = String.format("https://cdn.discordapp.com/avatars/%s/%s.%s", user.getId(), user.getAvatar(), extension);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@
import dev.cloudeko.zenei.extension.external.endpoint.ProviderEndpoints;
import dev.cloudeko.zenei.extension.external.web.client.ExternalProviderAccessToken;
import dev.cloudeko.zenei.extension.external.web.external.github.GithubClient;
import dev.cloudeko.zenei.extension.external.web.external.github.GithubUser;
import dev.cloudeko.zenei.extension.external.web.external.github.GithubUserEmail;
import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder;

import java.net.URI;
import java.util.List;

public record GithubExternalAuthProvider(ExternalAuthProviderConfig config) implements ExternalAuthProvider {

@Override
public ExternalUserProfile getExternalUserProfile(ExternalProviderAccessToken accessToken) {
final var client = QuarkusRestClientBuilder.newBuilder()
GithubClient client = QuarkusRestClientBuilder.newBuilder()
.baseUri(URI.create(getBaseEndpoint()))
.build(GithubClient.class);

final var externalUserBuilder = ExternalUserProfile.builder();
final var user = client.getCurrentlyLoggedInUser("Bearer " + accessToken.getAccessToken());
ExternalUserProfile.ExternalUserProfileBuilder externalUserBuilder = ExternalUserProfile.builder();
GithubUser user = client.getCurrentlyLoggedInUser("Bearer " + accessToken.getAccessToken());

externalUserBuilder.id(user.getId().toString());
externalUserBuilder.username(user.getLogin());
externalUserBuilder.avatarUrl(user.getAvatarUrl());

final var emails = client.getUserEmails("Bearer " + accessToken.getAccessToken());
final var externalUserEmails = emails.stream()
List<GithubUserEmail> emails = client.getUserEmails("Bearer " + accessToken.getAccessToken());
List<ExternalUserProfile.ExternalUserEmail> externalUserEmails = emails.stream()
.map(email -> new ExternalUserProfile.ExternalUserEmail(
email.getEmail(),
email.isPrimary(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import dev.cloudeko.zenei.extension.external.config.ExternalAuthProviderConfig;
import dev.cloudeko.zenei.extension.external.endpoint.ProviderEndpoints;
import dev.cloudeko.zenei.extension.external.web.client.ExternalProviderAccessToken;
import dev.cloudeko.zenei.extension.external.web.external.BaseExternalClient;
import dev.cloudeko.zenei.extension.external.web.external.google.GoogleClient;
import dev.cloudeko.zenei.extension.external.web.external.google.GoogleUser;
import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder;

import java.net.URI;
Expand All @@ -15,11 +17,11 @@ public record GoogleExternalAuthProvider(ExternalAuthProviderConfig config) impl

@Override
public ExternalUserProfile getExternalUserProfile(ExternalProviderAccessToken accessToken) {
final var client = QuarkusRestClientBuilder.newBuilder()
BaseExternalClient<GoogleUser> client = QuarkusRestClientBuilder.newBuilder()
.baseUri(URI.create(getBaseEndpoint()))
.build(GoogleClient.class);

final var user = client.getCurrentlyLoggedInUser("Bearer " + accessToken.getAccessToken());
GoogleUser user = client.getCurrentlyLoggedInUser("Bearer " + accessToken.getAccessToken());

return ExternalUserProfile.builder()
.id(user.getId())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.cloudeko.zenei.extension.external.web.external;

public interface BaseExternalClient<T> {
T getCurrentlyLoggedInUser(String token);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.cloudeko.zenei.extension.external.web.external.discord;

import dev.cloudeko.zenei.extension.external.web.external.BaseExternalClient;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.Path;

@Path("/")
public interface DiscordClient {
public interface DiscordClient extends BaseExternalClient<DiscordUser> {

@GET
@Path("/users/@me")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.cloudeko.zenei.extension.external.web.external.github;

import dev.cloudeko.zenei.extension.external.web.external.BaseExternalClient;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.Path;

import java.util.List;

@Path("/")
public interface GithubClient {
public interface GithubClient extends BaseExternalClient<GithubUser> {

@GET
@Path("/user")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dev.cloudeko.zenei.extension.external.web.external.google;

import dev.cloudeko.zenei.extension.external.web.external.BaseExternalClient;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.Path;

@Path("/")
public interface GoogleClient {
public interface GoogleClient extends BaseExternalClient<GoogleUser> {

@GET
@Path("/userinfo/v2/me")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: External Authentication Extension
name: Zenei Quarkus External Authentication Extension
#description: Do something useful.
metadata:
# keywords:
Expand Down
62 changes: 62 additions & 0 deletions extensions/jdbc-panache/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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>jdbc-panache-extension-parent</artifactId>
<version>0.0.1</version>
</parent>

<name>Zenei - Extensions - Jdbc Panache - Deployment</name>
<artifactId>jdbc-panache-extension-deployment</artifactId>

<dependencies>
<!-- Zenei Dependencies -->
<dependency>
<groupId>dev.cloudeko</groupId>
<artifactId>core-extension-deployment</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache-deployment</artifactId>
</dependency>
<dependency>
<groupId>dev.cloudeko</groupId>
<artifactId>jdbc-panache-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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.cloudeko.zenei.extension.jdbc.panache.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;

public class JdbcPanacheBuildSteps {

private static final String FEATURE = "jdbc-panache";

@BuildStep
public FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
}
20 changes: 20 additions & 0 deletions extensions/jdbc-panache/pom.xml
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 - Jdbc Panache - Parent</name>
<artifactId>jdbc-panache-extension-parent</artifactId>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
Loading

0 comments on commit 6572058

Please sign in to comment.