-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat(frontend): Parse JWT access token claims #5138
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
580cc2d
OIDC discovery URL will not have none as auth method
chen4119 855be7a
Fix code style
chen4119 09b87d8
fix compilation error
chen4119 82d176f
merge from datahub
chen4119 232f58d
Merge branch 'datahub-project-master'
chen4119 d4465b6
add keystore/truststore type env variables
chen4119 085728b
check keystore/truststore location is set
chen4119 54abf53
Merge branch 'master' into master
dd5aa59
Merge branch 'datahub-project:master' into master
chen4119 b7ce108
Merge branch 'datahub-project:master' into master
chen4119 5ce26c9
parse JWT access token
chen4119 8a4c2aa
Merge branch 'datahub-project:master' into master
chen4119 90063e4
fix build error
chen4119 f4f6781
Merge branch 'master' of https://github.com/chen4119/datahub
chen4119 bc0ae29
address PR comments
chen4119 a4aff93
fix build error
chen4119 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
datahub-frontend/app/auth/sso/oidc/OidcAuthorizationGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package auth.sso.oidc; | ||
|
||
import java.util.Map.Entry; | ||
|
||
import org.pac4j.core.authorization.generator.AuthorizationGenerator; | ||
import org.pac4j.core.context.WebContext; | ||
import org.pac4j.core.profile.AttributeLocation; | ||
import org.pac4j.core.profile.CommonProfile; | ||
import org.pac4j.core.profile.definition.ProfileDefinition; | ||
import org.pac4j.oidc.profile.OidcProfile; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.nimbusds.jwt.JWT; | ||
import com.nimbusds.jwt.JWTParser; | ||
|
||
public class OidcAuthorizationGenerator implements AuthorizationGenerator { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(OidcAuthorizationGenerator.class); | ||
|
||
private final ProfileDefinition profileDef; | ||
|
||
private final OidcConfigs oidcConfigs; | ||
|
||
public OidcAuthorizationGenerator(final ProfileDefinition profileDef, final OidcConfigs oidcConfigs) { | ||
this.profileDef = profileDef; | ||
this.oidcConfigs = oidcConfigs; | ||
} | ||
|
||
@Override | ||
public CommonProfile generate(WebContext context, CommonProfile profile) { | ||
if (oidcConfigs.getExtractJwtAccessTokenClaims().orElse(false)) { | ||
try { | ||
final JWT jwt = JWTParser.parse(((OidcProfile) profile).getAccessToken().getValue()); | ||
|
||
for (final Entry<String, Object> entry : jwt.getJWTClaimsSet().getClaims().entrySet()) { | ||
final String claimName = entry.getKey(); | ||
if (profile.getAttribute(claimName) == null) { | ||
profileDef.convertAndAdd(profile, AttributeLocation.PROFILE_ATTRIBUTE, claimName, entry.getValue()); | ||
} | ||
} | ||
} catch (Exception e) { | ||
logger.warn("Cannot parse access token claims", e); | ||
} | ||
} | ||
|
||
return profile; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we name this class to reflect that its related to Parsing access tokens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also keep this name, but just pass in the "OidcConfigs" object in the constructor, and then decide whether to parse JWT access tokens inside of here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passed in OidcConfigs in constructor