Skip to content

Commit

Permalink
Merge pull request #39650 from michalvavrik/feature/migrate-smallrye-…
Browse files Browse the repository at this point in the history
…jwt-config-classes-to-configmapping

Migrate the Quarkus SmallRye JWT config classes to `@ConfigMapping`
  • Loading branch information
sberyozkin authored Mar 22, 2024
2 parents 5ceb6a0 + 05220a0 commit d779c2c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package io.quarkus.smallrye.jwt.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

/**
* deployment configuration
*/
@ConfigRoot(name = "smallrye-jwt")
public class SmallRyeJwtBuildTimeConfig {
@ConfigMapping(prefix = "quarkus.smallrye-jwt")
@ConfigRoot
public interface SmallRyeJwtBuildTimeConfig {

/**
* The MP-JWT configuration object
*/
@ConfigItem(defaultValue = "true")
public boolean enabled = true;
@WithDefault("true")
boolean enabled();

/**
* The name of the {@linkplain java.security.Provider} that supports SHA256withRSA signatures
*/
@ConfigItem(defaultValue = "SunRsaSign")
public String rsaSigProvider;
@WithDefault("SunRsaSign")
String rsaSigProvider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void provideSecurityInformation(BuildProducer<SecurityInformationBuildIte
@BuildStep
void registerAdditionalBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
if (config.enabled) {
if (config.enabled()) {
AdditionalBeanBuildItem.Builder unremovable = AdditionalBeanBuildItem.builder().setUnremovable();
unremovable.addBeanClass(MpJwtValidator.class);
unremovable.addBeanClass(JsonWebTokenCredentialProducer.class);
Expand Down Expand Up @@ -156,7 +156,7 @@ private void registerKeyLocationResource(Config config, String propertyName,
*/
@BuildStep
JCAProviderBuildItem registerRSASigProvider() {
return new JCAProviderBuildItem(config.rsaSigProvider);
return new JCAProviderBuildItem(config.rsaSigProvider());
}

@BuildStep
Expand Down Expand Up @@ -213,7 +213,7 @@ public static class IsEnabled implements BooleanSupplier {
SmallRyeJwtBuildTimeConfig config;

public boolean getAsBoolean() {
return config.enabled;
return config.enabled();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public class JWTAuthMechanism implements HttpAuthenticationMechanism {
*/
private final boolean propagateTokenCredentialWithDuplicatedCtx;
@Inject
private JWTAuthContextInfo authContextInfo;
JWTAuthContextInfo authContextInfo;
private final boolean silent;

public JWTAuthMechanism(SmallRyeJwtConfig config) {
this.silent = config == null ? false : config.silent;
this.silent = config == null ? false : config.silent();
// we use system property in order to keep this option internal and avoid introducing SPI
this.propagateTokenCredentialWithDuplicatedCtx = Boolean
.getBoolean("io.quarkus.smallrye.jwt.runtime.auth.JWTAuthMechanism." +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public MpJwtValidator() {
@Inject
public MpJwtValidator(JWTParser parser, SmallRyeJwtConfig config) {
this.parser = parser;
this.blockingAuthentication = config == null ? false : config.blockingAuthentication;
this.blockingAuthentication = config == null ? false : config.blockingAuthentication();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package io.quarkus.smallrye.jwt.runtime.auth;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigRoot(name = "smallrye-jwt", phase = ConfigPhase.RUN_TIME)
public class SmallRyeJwtConfig {
@ConfigMapping(prefix = "quarkus.smallrye-jwt")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface SmallRyeJwtConfig {

/**
* Enable this property if fetching the remote keys can be a time-consuming operation.
* Do not enable it if you use the local keys.
*/
@ConfigItem(defaultValue = "false")
public boolean blockingAuthentication;
@WithDefault("false")
boolean blockingAuthentication();

/**
* Always create HTTP 401 challenge, even for requests containing no authentication credentials.
Expand All @@ -25,7 +27,7 @@ public class SmallRyeJwtConfig {
* by setting this property to 'true'.
*
*/
@ConfigItem
public boolean silent;
@WithDefault("false")
boolean silent();

}

0 comments on commit d779c2c

Please sign in to comment.