You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "bharos (via GitHub)" <gi...@apache.org> on 2025/08/12 20:36:25 UTC
[PR] [MINOR] feat(oauth): Support principal field to accept comma separated values to fallback [gravitino]
bharos opened a new pull request, #8049:
URL: https://github.com/apache/gravitino/pull/8049
<!--
1. Title: [#<issue>] <type>(<scope>): <subject>
Examples:
- "[#123] feat(operator): support xxx"
- "[#233] fix: check null before access result in xxx"
- "[MINOR] refactor: fix typo in variable name"
- "[MINOR] docs: fix typo in README"
- "[#255] test: fix flaky test NameOfTheTest"
Reference: https://www.conventionalcommits.org/en/v1.0.0/
2. If the PR is unfinished, please mark this PR as draft.
-->
### What changes were proposed in this pull request?
Support comma-separated values in principal field.
### Why are the changes needed?
Currently, the fallback values are hardcoded in the code. But better approach is to accept comma-separated values in config and use it in the order to fallback one by one.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
(Please test your changes, and provide instructions on how to test it:
Unit tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] feat(oauth): Support principal field to accept comma separated values to fallback [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #8049:
URL: https://github.com/apache/gravitino/pull/8049
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] feat(oauth): Support principal field to accept comma separated values to fallback [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #8049:
URL: https://github.com/apache/gravitino/pull/8049#discussion_r2275200668
##########
server-common/src/main/java/org/apache/gravitino/server/authentication/OAuthConfig.java:
##########
@@ -128,12 +129,14 @@ public interface OAuthConfig {
.stringConf()
.create();
- ConfigEntry<String> PRINCIPAL_FIELD =
+ ConfigEntry<List<String>> PRINCIPAL_FIELD =
new ConfigBuilder(OAUTH_CONFIG_PREFIX + "principalField")
Review Comment:
principalField -> principalFields
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] feat(oauth): Support principal field to accept comma separated values to fallback [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #8049:
URL: https://github.com/apache/gravitino/pull/8049#discussion_r2271896022
##########
server-common/src/main/java/org/apache/gravitino/server/authentication/JwksTokenValidator.java:
##########
@@ -147,23 +147,19 @@ private JWKSource<SecurityContext> createJwkSource() throws Exception {
}
}
- /** Extracts the principal from the validated JWT claims using configured field or fallbacks. */
+ /** Extracts the principal from the validated JWT claims using configured field(s). */
private String extractPrincipal(JWTClaimsSet validatedClaims) {
- // Try the configured principal field first
+ // Try the principal field(s) one by one in order
if (StringUtils.isNotBlank(principalField)) {
- String principal = (String) validatedClaims.getClaim(principalField);
- if (principal != null) {
- return principal;
- }
- }
-
- // Fallback to common user identity fields
- // TODO: Consider making this configurable
- String[] fallbackFields = {"unique_name", "upn", "email", "preferred_username", "sub"};
- for (String field : fallbackFields) {
- String principal = (String) validatedClaims.getClaim(field);
- if (principal != null) {
- return principal;
+ String[] configuredFields = principalField.split(",");
Review Comment:
ConfigEntry supports the `Sequence`, You can reuse it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] feat(oauth): Support principal field to accept comma separated values to fallback [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #8049:
URL: https://github.com/apache/gravitino/pull/8049#discussion_r2271896022
##########
server-common/src/main/java/org/apache/gravitino/server/authentication/JwksTokenValidator.java:
##########
@@ -147,23 +147,19 @@ private JWKSource<SecurityContext> createJwkSource() throws Exception {
}
}
- /** Extracts the principal from the validated JWT claims using configured field or fallbacks. */
+ /** Extracts the principal from the validated JWT claims using configured field(s). */
private String extractPrincipal(JWTClaimsSet validatedClaims) {
- // Try the configured principal field first
+ // Try the principal field(s) one by one in order
if (StringUtils.isNotBlank(principalField)) {
- String principal = (String) validatedClaims.getClaim(principalField);
- if (principal != null) {
- return principal;
- }
- }
-
- // Fallback to common user identity fields
- // TODO: Consider making this configurable
- String[] fallbackFields = {"unique_name", "upn", "email", "preferred_username", "sub"};
- for (String field : fallbackFields) {
- String principal = (String) validatedClaims.getClaim(field);
- if (principal != null) {
- return principal;
+ String[] configuredFields = principalField.split(",");
Review Comment:
Config supports the `Sequence`, You can reuse it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] feat(oauth): Support principal field to accept comma separated values to fallback [gravitino]
Posted by "jerqi (via GitHub)" <gi...@apache.org>.
jerqi commented on code in PR #8049:
URL: https://github.com/apache/gravitino/pull/8049#discussion_r2271955655
##########
server-common/src/main/java/org/apache/gravitino/server/authentication/JwksTokenValidator.java:
##########
@@ -147,23 +147,19 @@ private JWKSource<SecurityContext> createJwkSource() throws Exception {
}
}
- /** Extracts the principal from the validated JWT claims using configured field or fallbacks. */
+ /** Extracts the principal from the validated JWT claims using configured field(s). */
private String extractPrincipal(JWTClaimsSet validatedClaims) {
- // Try the configured principal field first
+ // Try the principal field(s) one by one in order
if (StringUtils.isNotBlank(principalField)) {
- String principal = (String) validatedClaims.getClaim(principalField);
- if (principal != null) {
- return principal;
- }
- }
-
- // Fallback to common user identity fields
- // TODO: Consider making this configurable
- String[] fallbackFields = {"unique_name", "upn", "email", "preferred_username", "sub"};
- for (String field : fallbackFields) {
- String principal = (String) validatedClaims.getClaim(field);
- if (principal != null) {
- return principal;
+ String[] configuredFields = principalField.split(",");
Review Comment:
public ConfigEntry<List<T>> toSequence() {}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] feat(oauth): Support principal field to accept comma separated values to fallback [gravitino]
Posted by "bharos (via GitHub)" <gi...@apache.org>.
bharos commented on code in PR #8049:
URL: https://github.com/apache/gravitino/pull/8049#discussion_r2273947558
##########
server-common/src/main/java/org/apache/gravitino/server/authentication/JwksTokenValidator.java:
##########
@@ -147,23 +147,19 @@ private JWKSource<SecurityContext> createJwkSource() throws Exception {
}
}
- /** Extracts the principal from the validated JWT claims using configured field or fallbacks. */
+ /** Extracts the principal from the validated JWT claims using configured field(s). */
private String extractPrincipal(JWTClaimsSet validatedClaims) {
- // Try the configured principal field first
+ // Try the principal field(s) one by one in order
if (StringUtils.isNotBlank(principalField)) {
- String principal = (String) validatedClaims.getClaim(principalField);
- if (principal != null) {
- return principal;
- }
- }
-
- // Fallback to common user identity fields
- // TODO: Consider making this configurable
- String[] fallbackFields = {"unique_name", "upn", "email", "preferred_username", "sub"};
- for (String field : fallbackFields) {
- String principal = (String) validatedClaims.getClaim(field);
- if (principal != null) {
- return principal;
+ String[] configuredFields = principalField.split(",");
Review Comment:
Good point. done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [MINOR] feat(oauth): Support principal field to accept comma separated values to fallback [gravitino]
Posted by "bharos (via GitHub)" <gi...@apache.org>.
bharos commented on code in PR #8049:
URL: https://github.com/apache/gravitino/pull/8049#discussion_r2277210375
##########
server-common/src/main/java/org/apache/gravitino/server/authentication/OAuthConfig.java:
##########
@@ -128,12 +129,14 @@ public interface OAuthConfig {
.stringConf()
.create();
- ConfigEntry<String> PRINCIPAL_FIELD =
+ ConfigEntry<List<String>> PRINCIPAL_FIELD =
new ConfigBuilder(OAUTH_CONFIG_PREFIX + "principalField")
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org