Skip to content

Commit

Permalink
Use application tenant domain to retrieve client app.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpmadhavig committed Aug 23, 2024
1 parent feee694 commit 4e56039
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
import org.wso2.carbon.identity.central.log.mgt.utils.LoggerUtils;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl;
import org.wso2.carbon.identity.oauth.common.OAuthConstants;
import org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException;
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
import org.wso2.carbon.identity.oauth.dao.OAuthAppDO;
import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO;
import org.wso2.carbon.identity.oauth.internal.OAuthComponentServiceHolder;
import org.wso2.carbon.identity.oauth.tokenprocessor.TokenProvider;
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
import org.wso2.carbon.identity.oauth2.IdentityOAuth2ServerException;
import org.wso2.carbon.identity.oauth2.OAuth2Constants;
import org.wso2.carbon.identity.oauth2.authcontext.AuthorizationContextTokenGenerator;
import org.wso2.carbon.identity.oauth2.dto.OAuth2ClientApplicationDTO;
Expand Down Expand Up @@ -575,7 +573,7 @@ private OAuth2IntrospectionResponseDTO validateAccessToken(OAuth2TokenValidation
.isRemoveUsernameFromIntrospectionResponseForAppTokensEnabled();
boolean isAppTokenType = StringUtils.equals(OAuthConstants.UserType.APPLICATION, tokenType);
boolean removeUsernameFromAppTokenEnabledAppConfig =
isOmitUsernameInIntrospectionRespForAppTokens(accessTokenDO, tenantDomain);
isOmitUsernameInIntrospectionRespForAppTokens(accessTokenDO);

// should be in seconds
introResp.setIat(accessTokenDO.getIssuedTime().getTime() / 1000);
Expand Down Expand Up @@ -678,16 +676,23 @@ private OAuth2IntrospectionResponseDTO validateAccessToken(OAuth2TokenValidation
return introResp;
}

private static boolean isOmitUsernameInIntrospectionRespForAppTokens(AccessTokenDO accessTokenDO,
String tenantDomain)
private static boolean isOmitUsernameInIntrospectionRespForAppTokens(AccessTokenDO accessTokenDO)
throws IdentityOAuth2Exception {

OAuthAdminServiceImpl oAuthAdminService = OAuthComponentServiceHolder.getInstance().getoAuthAdminService();
boolean omitUsernameInIntrospectionRespForAppTokens;
try {
OAuthConsumerAppDTO oAuthApp = oAuthAdminService.getOAuthApplicationData(accessTokenDO.getConsumerKey(),
tenantDomain);
omitUsernameInIntrospectionRespForAppTokens = oAuthApp.isOmitUsernameInIntrospectionRespForAppTokens();
String appResidentTenantDomain = null;
int appResidentTenantId = accessTokenDO.getAppResidentTenantId();
if (appResidentTenantId != MultitenantConstants.INVALID_TENANT_ID) {
appResidentTenantDomain = IdentityTenantUtil.getTenantDomain(appResidentTenantId);
OAuthAppDO oAuthAppDO = OAuth2Util.getAppInformationByClientId(accessTokenDO.getConsumerKey(),
appResidentTenantDomain);
omitUsernameInIntrospectionRespForAppTokens = oAuthAppDO
.isOmitUsernameInIntrospectionRespForAppTokens();
} else {
throw new IdentityOAuth2ServerException("Invalid tenant domain found in access token issue for"
+ " client id: " + accessTokenDO.getConsumerKey());
}
} catch (Exception e) {
throw new IdentityOAuth2Exception("Error occurred while retrieving OAuth2 application data for client id:" +
accessTokenDO.getConsumerKey(), e);
Expand Down

0 comments on commit 4e56039

Please sign in to comment.