Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate the Quarkus SmallRye JWT config classes to @ConfigMapping #39650

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();

}
Loading