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

support getting caller and group information from multiple tokens #26719

Conversation

arunavemulapalli
Copy link
Contributor

@arunavemulapalli arunavemulapalli commented Oct 25, 2023

update oidc client config, runtime

  • add support to get the caller / group claims from id token, access token and user info

For #25460
Fixes #26888

@arunavemulapalli
Copy link
Contributor Author

#build
#spawn.fullfat.buckets=com.ibm.ws.security.oidc.client_fat.1,com.ibm.ws.security.oidc.client_fat.2,com.ibm.ws.security.oidc.client_fat.3,com.ibm.ws.security.oidc.client_fat.backchannelLogout,com.ibm.ws.security.oidc.client_fat.claimPropagation,com.ibm.ws.security.oidc.client_fat.jaxrs,com.ibm.ws.security.oidc.server_fat.backchannelLogout,com.ibm.ws.security.oidc.server_fat.jaxrs.config.noOP,com.ibm.ws.security.oidc.server_fat.jaxrs.config.oauth,com.ibm.ws.security.oidc.server_fat.jaxrs.config.oidc,com.ibm.ws.security.oidc.server_fat.oauth,com.ibm.ws.security.oidc.server_fat.oidc,com.ibm.ws.security.social_fat.LibertyOP.1,com.ibm.ws.security.social_fat.LibertyOP.2,com.ibm.ws.security.social_fat.LibertyOP.3,com.ibm.ws.security.social_fat.LibertyOP.backchannelLogout,com.ibm.ws.security.social_fat.LibertyOP.claimPropagation,com.ibm.ws.security.social_fat.delegated,com.ibm.ws.security.social_fat.multiProvider,com.ibm.ws.security.oidc.client_fat.claimPropagation,com.ibm.ws.security.oidc.client_fat.config.1,com.ibm.ws.security.oidc.client_fat.config.2,com.ibm.ws.security.oidc.client_fat.e2e,com.ibm.ws.security.oidc.client_fat.saml

@LibbyBot
Copy link

Your personal build request is at https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_-fsC4HLdEe6LyICjST0JEw

Target locations of links might be accessible only to IBM employees.

@arunavemulapalli arunavemulapalli force-pushed the caller-from-multiple-tokens-updates branch from 88c6bc8 to f876e18 Compare October 25, 2023 19:57
@LibbyBot
Copy link

The build arunavemulapalli-26719-20231024-2038
https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_-fsC4HLdEe6LyICjST0JEw
completed and has errors or failures.

For help analyzing your personal build, go to https://libh-proxy1.fyre.ibm.com/cognitive/buildAnalysis.html?uuid=_-fsC4HLdEe6LyICjST0JEw

@LibbyBot
Copy link

The build arunavemulapalli-26719-2-20231025-1441
https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_tPX1kHN1Ee6LyICjST0JEw
completed and has errors or failures.

For help analyzing your personal build, go to https://libh-proxy1.fyre.ibm.com/cognitive/buildAnalysis.html?uuid=_tPX1kHN1Ee6LyICjST0JEw

@arunavemulapalli
Copy link
Contributor Author

#libby

@arunavemulapalli arunavemulapalli force-pushed the caller-from-multiple-tokens-updates branch from 1189bff to bf4e530 Compare October 28, 2023 22:45
@LibbyBot
Copy link

The build arunavemulapalli-26719-2-20231028-1555
https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_Vwua0HXbEe6p7N33NVgeoQ
completed and has errors or failures.

For help analyzing your personal build, go to https://libh-proxy1.fyre.ibm.com/cognitive/buildAnalysis.html?uuid=_Vwua0HXbEe6p7N33NVgeoQ

@LibbyBot
Copy link

LibbyBot commented Nov 1, 2023

The build arunavemulapalli-26719-2-20231031-2120
https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_RQ_MMHhkEe6p7N33NVgeoQ
completed and has errors or failures.

For help analyzing your personal build, go to https://libh-proxy1.fyre.ibm.com/cognitive/buildAnalysis.html?uuid=_RQ_MMHhkEe6p7N33NVgeoQ

@arunavemulapalli arunavemulapalli force-pushed the caller-from-multiple-tokens-updates branch from a48f897 to 6f189a7 Compare November 6, 2023 23:50
@arunavemulapalli
Copy link
Contributor Author

#libby

@LibbyBot
Copy link

LibbyBot commented Nov 7, 2023

The build arunavemulapalli-26719-2-20231106-1602
https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_XffuwHz3Ee6pmuZkFgD-jA
completed and has errors or failures.

For help analyzing your personal build, go to https://libh-proxy1.fyre.ibm.com/cognitive/buildAnalysis.html?uuid=_XffuwHz3Ee6pmuZkFgD-jA

@arunavemulapalli arunavemulapalli force-pushed the caller-from-multiple-tokens-updates branch from 6f189a7 to e1607c0 Compare November 7, 2023 22:35
@arunavemulapalli
Copy link
Contributor Author

#libby

@arunavemulapalli arunavemulapalli force-pushed the caller-from-multiple-tokens-updates branch from e1607c0 to a9709b9 Compare November 8, 2023 04:05
onlinefw and others added 5 commits November 8, 2023 13:48
… token, access token, user info

address review comments

social - OidcLoginConfigImpl update

Fix the groupId / aud retrieval issue

configuration update

configuration update and add implementation to OidcLoginConfigImpl

Update to ignore the exception from finding userinfo and continue with the other 2 tokens

Update to use space instead of "," to fix the configuration issue

update to take default value when the new config attribute is not used
@LibbyBot
Copy link

LibbyBot commented Nov 8, 2023

The build arunavemulapalli-26719-2-20231107-2016
https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_1_5OwH3jEe6pmuZkFgD-jA
completed successfully!

@posmith
Copy link

posmith commented Nov 10, 2023

L2 message review not required.

@arunavemulapalli
Copy link
Contributor Author

#libby

@@ -562,7 +567,14 @@ private void processConfigProps(Map<String, Object> props) {
// checkValidationEndpointUrl();

// validateAuthzTokenEndpoints(); //TODO: update tests to expect the error if the validation here fails

String tokens = configUtils.getConfigAttributeWithDefaultValue(props, CFG_KEY_TOKEN_ORDER_TOFETCH_CALLER_CLAIMS, "IDToken");//getStringArrayConfigAttribute(props, CFG_KEY_TOKEN_ORDER_TOFETCH_CALLER_CLAIMS);
/* if (tokens == null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up code

@@ -298,3 +298,8 @@ pkceCodeChallengeMethod.S256=S256

tokenRequestOriginHeader=Token request origin header
tokenRequestOriginHeader.desc=Specifies the value to use in the Origin HTTP header that is included in the HTTP POST request to the token endpoint of the OpenID Connect provider. If not specified, an Origin HTTP header is not included in the request.

tokenOrderToFetchCallerClaims=Specify one or more tokens to fetch caller claims
tokenOrderToFetchCallerClaims.desc=Specifies the order of the token/s to fetch the caller name and group claim values. If the claim does not exist in the first token, then the OpenID Connect client will continue the search with other tokens in the list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove /
change "will continue" to "continues"

tokenOrderToFetchCallerClaims=Specify one or more tokens to fetch caller claims
tokenOrderToFetchCallerClaims.desc=Specifies the order of the token/s to fetch the caller name and group claim values. If the claim does not exist in the first token, then the OpenID Connect client will continue the search with other tokens in the list
tokenOrderToFetchCallerClaims.IDToken=Use IDToken only to determine the caller claims
tokenOrderToFetchCallerClaims.ACCESSAndIDAndUITokens=Use AccessToken, IDToken and Userinfo tokens in this order, to determine the caller claims.
Copy link

@arkarkala arkarkala Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses the AccessToken, IDToken, and UserInfo tokens, in that order, to determine the caller claims.


tokenOrderToFetchCallerClaims=Specify one or more tokens to fetch caller claims
tokenOrderToFetchCallerClaims.desc=Specifies the order of the token/s to fetch the caller name and group claim values. If the claim does not exist in the first token, then the OpenID Connect client will continue the search with other tokens in the list
tokenOrderToFetchCallerClaims.IDToken=Use IDToken only to determine the caller claims

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses only the IDToken to determine the caller claims

arkarkala
arkarkala previously approved these changes Nov 10, 2023

public static final String USER_PRINCIPAL_NAME = "upn";

public static final String GROUP = "groupIds";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to call this GROUP_IDS instead of GROUP?

@@ -40,6 +40,7 @@ public class TokenEndpointServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private final String servletName = "TokenEndpointServlet";
private String token = null;
private String idt = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would really prefer this to be called something like overrideIdToken or idTokenOverride or idTokenRequestParameter so it's more descriptive than the cryptic idt.

trustAliasName="rs256"
signatureAlgorithm="RS256"
tokenOrderToFetchCallerClaims="AccessToken IDToken Userinfo"
mapIdentityToRegistryUser="yes"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapIdentityToRegistryUser takes a boolean as a value, so the value needs to either be "true" or "false".

com.ibm.ws.webcontainer.security.*=all=enabled:\
com.ibm.oauth.*=all=enabled:\
com.ibm.wsspi.security.oauth20.*=all=enabled:\
org.apache.http.client.*=all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add io.openliberty.security*=all.

com.ibm.ws.webcontainer.security.*=all=enabled:\
com.ibm.oauth.*=all=enabled:\
com.ibm.wsspi.security.oauth20.*=all=enabled:\
org.apache.http.client.*=all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add io.openliberty.security*=all.

userInfoClaims = getClaimsFromUserInfo(userInfoStr);

} catch (Exception e) {
Tr.error(tc, "Invalid user info: " + userInfoStr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Tr.error(tc, "Invalid user info: " + userInfoStr);
Tr.debug(tc, "Invalid user info: " + userInfoStr);

The Tr.error() method emits messages to the console.log and messages.log that require translation. The Tr.debug() method should be used here instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a higher priority issue to fix.

oidcResult = new ProviderAuthenticationResult(AuthResult.SUCCESS, HttpServletResponse.SC_OK, null, null, props, null);
if (isRunningBetaMode()) {
createWASOidcSession(oidcClientRequest, jwtClaims, clientConfig);
//createWASOidcSession(oidcClientRequest, jwtClaims, clientConfig);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code.

uid = clientConfig.getUserIdentityToCreateSubject();
}

String[] userClaimIdentifiers = {attrUsedToCreateSubject, uid};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an ideal way to return data back from the method. It's not clear to callers that [0] happens to be the name of the attribute name and [1] happens to be the value.

Comment on lines +732 to +733
@SuppressWarnings("unchecked")
List<String> getGroupIds(ConvergedClientConfig clientConfig, List<String> tokensOrderToFetchCallerClaims, Map<String, JwtClaims> tokenClaimsMap) throws MalformedClaimException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@SuppressWarnings("unchecked")
List<String> getGroupIds(ConvergedClientConfig clientConfig, List<String> tokensOrderToFetchCallerClaims, Map<String, JwtClaims> tokenClaimsMap) throws MalformedClaimException {
@SuppressWarnings("unchecked")
@FFDCIgnore(MalformedClaimException.class)
List<String> getGroupIds(ConvergedClientConfig clientConfig, List<String> tokensOrderToFetchCallerClaims, Map<String, JwtClaims> tokenClaimsMap) throws MalformedClaimException {

List<String> groupIds = null;
try {
groupIds = getClaimValueFromTokens(groupIdsClaim, List.class, tokensOrderToFetchCallerClaims, tokenClaimsMap);
} catch (Exception e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (Exception e) {
} catch (MalformedClaimException e) {

@arunavemulapalli
Copy link
Contributor Author

thanks @ayoho , @arkarkala for the review. I will get the review issues done

@arunavemulapalli
Copy link
Contributor Author

#build

@LibbyBot
Copy link

Your personal build request is at https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_yOrhMH_3Ee6pmuZkFgD-jA

Target locations of links might be accessible only to IBM employees.

@arunavemulapalli
Copy link
Contributor Author

#libby

@LibbyBot
Copy link

Code analysis and actions

DO NOT DELETE THIS COMMENT.
  • 13 product code files were changed.

  • Please describe in a separate comment how you tested your changes.

  • 24 FAT files were changed, added, or removed.

  • Check that the build did not break the affected FAT suite(s).

  • 1 NLS files were changed and need an ID review.

  • @OpenLiberty/message-reviewer Please review.

  • dev/com.ibm.ws.security.openidconnect.client/resources/OSGI-INF/l10n/metatype.properties

@arunavemulapalli arunavemulapalli merged commit d51d7b1 into OpenLiberty:integration Nov 11, 2023
@LibbyBot
Copy link

The build arunavemulapalli-26719-20231110-1143
https://wasrtc.hursley.ibm.com:9443/jazz/resource/itemOid/com.ibm.team.build.BuildResult/_yOrhMH_3Ee6pmuZkFgD-jA
completed and has errors or failures.

For help analyzing your personal build, go to https://libh-proxy1.fyre.ibm.com/cognitive/buildAnalysis.html?uuid=_yOrhMH_3Ee6pmuZkFgD-jA

Copy link

@helyarp helyarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -298,3 +298,8 @@ pkceCodeChallengeMethod.S256=S256

tokenRequestOriginHeader=Token request origin header
tokenRequestOriginHeader.desc=Specifies the value to use in the Origin HTTP header that is included in the HTTP POST request to the token endpoint of the OpenID Connect provider. If not specified, an Origin HTTP header is not included in the request.

tokenOrderToFetchCallerClaims=Specify one or more tokens to fetch caller claims
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change is fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fetch caller claims from multiple tokens
7 participants