Skip to content

Commit

Permalink
Ignore the unhandled ODIC properties gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalya committed Oct 6, 2023
1 parent 358fc6c commit 02955c2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.trino.gateway.ha.config.OAuthConfiguration;

Expand Down Expand Up @@ -132,7 +133,8 @@ public Optional<Map<String, Claim>> getClaimsFromIdToken(String idToken) {
}

@Data
private static final class OidcTokens {
@JsonIgnoreProperties(ignoreUnknown = true)
static final class OidcTokens {

@JsonProperty
private final String accessToken;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.trino.gateway.ha.security;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.trino.gateway.ha.security.LbOAuthManager.OidcTokens;
import lombok.extern.slf4j.Slf4j;
import org.testng.Assert;
import org.testng.annotations.Test;

@Slf4j
public class TestOidcToken {
@Test
public void testOidcTokenParams() {
OidcTokens oidcTokens = null;
try {
ObjectMapper objectMapper = new ObjectMapper();

String jsonStr = "{\"id_token\" : \"ABC235234\", "
+ "\"access_token\" : \"AcessABCD123\", "
+ "\"refresh_token\" : \"RefreshTKN\", "
+ "\"token_type\" : \"TOKENType\", "
+ "\"expires_in\" : \"123456\", "
+ "\"to_be_ignored\" : \"XYX123456\", "
+ "\"scope\" : \"global\" "
+ "}";

oidcTokens = objectMapper.readValue(jsonStr, OidcTokens.class);
} catch (JsonProcessingException ex) {
log.error(ex.getMessage());
Assert.assertTrue(false);
}

Assert.assertTrue(oidcTokens.getIdToken().equals("ABC235234"));
Assert.assertTrue(oidcTokens.getAccessToken().equals("AcessABCD123"));
Assert.assertTrue(oidcTokens.getRefreshToken().equals("RefreshTKN"));
Assert.assertTrue(oidcTokens.getExpiresIn().equals("123456"));
Assert.assertTrue(oidcTokens.getScope().equals("global"));
}
}

0 comments on commit 02955c2

Please sign in to comment.