Skip to content
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
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ The subject of the client assertion JWT. Optional. The default is the client ID.

### `rest.auth.oauth2.client-assertion.jwt.audience`

The audience of the client assertion JWT. Optional. The default is the token endpoint.
The audience of the client assertion JWT. Optional. The default is the token endpoint. Can be a single audience or a comma-separated list of audiences.

### `rest.auth.oauth2.client-assertion.jwt.token-lifespan`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ public interface ClientAssertionConfig {
@WithName(SUBJECT)
Optional<Subject> getSubject();

/** The audience of the client assertion JWT. Optional. The default is the token endpoint. */
/**
* The audience of the client assertion JWT. Optional. The default is the token endpoint. Can be a
* single audience or a comma-separated list of audiences.
*/
@WithName(AUDIENCE)
Optional<Audience> getAudience();
Optional<List<Audience>> getAudience();

/** The expiration time of the client assertion JWT. Optional. The default is 5 minutes. */
@WithName(TOKEN_LIFESPAN)
Expand Down Expand Up @@ -166,10 +169,15 @@ default void validate() {
}

default Map<String, String> asMap() {
Map<String, String> properties = new HashMap<>();
Map<String, String> properties = new HashMap<String, String>();
getIssuer().ifPresent(i -> properties.put(PREFIX + '.' + ISSUER, i.getValue()));
getSubject().ifPresent(s -> properties.put(PREFIX + '.' + SUBJECT, s.getValue()));
getAudience().ifPresent(a -> properties.put(PREFIX + '.' + AUDIENCE, a.getValue()));
getAudience()
.ifPresent(
a ->
properties.put(
PREFIX + '.' + AUDIENCE,
a.stream().map(Audience::getValue).collect(Collectors.joining(","))));
properties.put(PREFIX + '.' + TOKEN_LIFESPAN, getTokenLifespan().toString());
getAlgorithm().ifPresent(a -> properties.put(PREFIX + '.' + ALGORITHM, a.getName()));
getKeyId().ifPresent(k -> properties.put(PREFIX + '.' + KEY_ID, k));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,19 @@ private JWTAssertionDetails createJwtAssertionDetails(URI tokenEndpoint) {
getConfig().getClientAssertionConfig().getSubject().isPresent()
? getConfig().getClientAssertionConfig().getSubject().get()
: new Subject(getConfig().getBasicConfig().getClientId().orElseThrow().getValue());
Audience audience =
getConfig().getClientAssertionConfig().getAudience().isPresent()
? getConfig().getClientAssertionConfig().getAudience().get()
: new Audience(tokenEndpoint);
List<Audience> audiences =
getConfig()
.getClientAssertionConfig()
.getAudience()
.orElseGet(() -> List.of(new Audience(tokenEndpoint)));
Instant issuedAt = getRuntime().getClock().instant();
Instant expiration = issuedAt.plus(getConfig().getClientAssertionConfig().getTokenLifespan());
@SuppressWarnings({"rawtypes", "unchecked"})
Map<String, Object> extraClaims = (Map) getConfig().getClientAssertionConfig().getExtraClaims();
return new JWTAssertionDetails(
issuer,
subject,
List.of(audience),
audiences,
Date.from(expiration),
Date.from(issuedAt),
Date.from(issuedAt),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

import com.dremio.iceberg.authmgr.oauth2.config.validator.ConfigValidator;
import com.nimbusds.oauth2.sdk.id.Audience;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.common.MapBackedConfigSource;
Expand Down Expand Up @@ -149,4 +150,38 @@ void testKeyIdPresent() {
smallRyeConfig.getConfigMapping(ClientAssertionConfig.class, PREFIX);
assertThat(config.getKeyId()).hasValue("my-key-123");
}

@Test
void testAudienceSingleValue() {
Map<String, String> properties =
Map.of(PREFIX + '.' + ClientAssertionConfig.AUDIENCE, "https://example.com");
SmallRyeConfig smallRyeConfig =
new SmallRyeConfigBuilder()
.withMapping(ClientAssertionConfig.class, PREFIX)
.withSources(new MapBackedConfigSource("catalog-properties", properties, 1000) {})
.build();
ClientAssertionConfig config =
smallRyeConfig.getConfigMapping(ClientAssertionConfig.class, PREFIX);
assertThat(config.getAudience()).contains(List.of(new Audience("https://example.com")));
}

@Test
void testAudienceMultipleValues() {
Map<String, String> properties =
Map.of(
PREFIX + '.' + ClientAssertionConfig.AUDIENCE,
"https://auth1.example.com,https://auth2.example.com");
SmallRyeConfig smallRyeConfig =
new SmallRyeConfigBuilder()
.withMapping(ClientAssertionConfig.class, PREFIX)
.withSources(new MapBackedConfigSource("catalog-properties", properties, 1000) {})
.build();
ClientAssertionConfig config =
smallRyeConfig.getConfigMapping(ClientAssertionConfig.class, PREFIX);
assertThat(config.getAudience())
.contains(
List.of(
new Audience("https://auth1.example.com"),
new Audience("https://auth2.example.com")));
}
}