-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add @TenantExclude annotation for tenant resolver
- Loading branch information
1 parent
46e7956
commit 407a96d
Showing
44 changed files
with
1,009 additions
and
181 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
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,70 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>org.tkit.quarkus.lib</groupId> | ||
<artifactId>tkit-quarkus-rest-context-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>tkit-quarkus-rest-context-deployment</artifactId> | ||
<name>tkit-quarkus-rest-context-deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-core-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-smallrye-jwt-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.tkit.quarkus.lib</groupId> | ||
<artifactId>tkit-quarkus-rest-context</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- TEST --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
14 changes: 14 additions & 0 deletions
14
...loyment/src/main/java/org/tkit/quarkus/rs/context/deployment/AnnotationDataBuildItem.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,14 @@ | ||
package org.tkit.quarkus.rs.context.deployment; | ||
|
||
import org.tkit.quarkus.rs.context.runtime.TenantAnnotationData; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
public final class AnnotationDataBuildItem extends SimpleBuildItem { | ||
|
||
TenantAnnotationData data; | ||
|
||
public AnnotationDataBuildItem(TenantAnnotationData data) { | ||
this.data = data; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ployment/src/main/java/org/tkit/quarkus/rs/context/deployment/RestContextBuildConfig.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,32 @@ | ||
package org.tkit.quarkus.rs.context.deployment; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigPhase; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
/** | ||
* Rest context build configuration. | ||
*/ | ||
@ConfigRoot(prefix = "tkit", name = "rs.context.build", phase = ConfigPhase.BUILD_TIME) | ||
public class RestContextBuildConfig { | ||
|
||
/** | ||
* Auto-discovery configuration. | ||
*/ | ||
@ConfigItem(name = "tenant") | ||
public TenantBuildTimeConfig tenant; | ||
|
||
/** | ||
* Build tenant annotation config. | ||
*/ | ||
@ConfigGroup | ||
public static class TenantBuildTimeConfig { | ||
/** | ||
* Enable tenant annotation discovery | ||
*/ | ||
@ConfigItem(name = "enabled", defaultValue = "true") | ||
public boolean enabled; | ||
} | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
...deployment/src/main/java/org/tkit/quarkus/rs/context/deployment/RestContextProcessor.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,76 @@ | ||
package org.tkit.quarkus.rs.context.deployment; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.MethodInfo; | ||
import org.tkit.quarkus.rs.context.runtime.RestContextTenantRecorder; | ||
import org.tkit.quarkus.rs.context.runtime.TenantAnnotationData; | ||
import org.tkit.quarkus.rs.context.tenant.TenantExclude; | ||
|
||
import io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem; | ||
import io.quarkus.arc.deployment.BeanRegistrationPhaseBuildItem; | ||
import io.quarkus.arc.processor.BeanInfo; | ||
import io.quarkus.deployment.annotations.*; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.builditem.RuntimeConfigSetupCompleteBuildItem; | ||
|
||
public class RestContextProcessor { | ||
|
||
private static final DotName TENANT_EXCLUDE = DotName.createSimple(TenantExclude.class.getName()); | ||
static final String FEATURE_NAME = "tkit-rest-context"; | ||
|
||
@BuildStep | ||
void build(BuildProducer<FeatureBuildItem> feature) { | ||
feature.produce(new FeatureBuildItem(FEATURE_NAME)); | ||
} | ||
|
||
@BuildStep | ||
@Record(ExecutionTime.RUNTIME_INIT) | ||
@Consume(RuntimeConfigSetupCompleteBuildItem.class) | ||
public void restContextInit(RestContextTenantRecorder recorder, AnnotationDataBuildItem dataBuildItem) { | ||
recorder.init(dataBuildItem.data); | ||
} | ||
|
||
@BuildStep | ||
void services(BeanDiscoveryFinishedBuildItem beanDiscoveryFinishedBuildItem, | ||
BeanRegistrationPhaseBuildItem beanRegistrationPhase, | ||
RestContextBuildConfig buildConfig, | ||
BuildProducer<AnnotationDataBuildItem> producer) { | ||
|
||
if (!buildConfig.tenant.enabled) { | ||
return; | ||
} | ||
|
||
TenantAnnotationData tenant = new TenantAnnotationData(); | ||
|
||
for (BeanInfo bean : beanRegistrationPhase.getContext().beans().classBeans()) { | ||
ClassInfo ci = bean.getImplClazz(); | ||
|
||
// check @TenantExclude for class | ||
if (ci.hasDeclaredAnnotation(TENANT_EXCLUDE)) { | ||
tenant.addExcludeClass(ci.name().toString()); | ||
continue; | ||
} | ||
|
||
// check @TenantExclude for class methods | ||
for (MethodInfo methodInfo : ci.methods()) { | ||
if (methodInfo.hasAnnotation(TENANT_EXCLUDE)) { | ||
|
||
var params = ""; | ||
if (!methodInfo.parameterTypes().isEmpty()) { | ||
params = methodInfo.parameterTypes() | ||
.stream() | ||
.map(org.jboss.jandex.Type::toString) | ||
.collect(Collectors.joining()); | ||
} | ||
tenant.addExcludeMethod(ci.name().toString(), methodInfo.name(), params); | ||
} | ||
} | ||
} | ||
|
||
producer.produce(new AnnotationDataBuildItem(tenant)); | ||
} | ||
} |
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,73 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.tkit.quarkus.lib</groupId> | ||
<artifactId>tkit-quarkus-rest-context-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>tkit-quarkus-rest-context</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.tkit.quarkus.lib</groupId> | ||
<artifactId>tkit-quarkus-context</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.ws.rs</groupId> | ||
<artifactId>jakarta.ws.rs-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-smallrye-jwt</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>extension-descriptor</goal> | ||
</goals> | ||
<phase>compile</phase> | ||
<configuration> | ||
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version} | ||
</deployment> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>io.smallrye</groupId> | ||
<artifactId>jandex-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.