Skip to content

Commit

Permalink
Merge branch 'master' into role-v2-patch-token-revocation
Browse files Browse the repository at this point in the history
  • Loading branch information
SujanSanjula96 authored Jan 1, 2025
2 parents 0473876 + 9095d8d commit 678a6db
Show file tree
Hide file tree
Showing 48 changed files with 1,422 additions and 91 deletions.
4 changes: 2 additions & 2 deletions components/org.wso2.carbon.identity.api.server.dcr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<parent>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.server.dcr</artifactId>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
<name>WSO2 Carbon - User DCR Rest API</name>
<description>WSO2 Carbon - User DCR Rest API</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<parent>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.server.oauth.scope</artifactId>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>

<name>WSO2 Carbon - Identity OAuth 2.0 Scope Rest APIs</name>
<description>Rest APIs for OAuth 2.0 Scope Handling</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.discovery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.oauth.ciba/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>identity-inbound-auth-oauth</artifactId>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.oauth.common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ public static class OIDCClaims {
public static final String EMAIL_VERIFIED = "email_verified";
public static final String ADDRESS = "address";
public static final String ROLES = "roles";
public static final String APP_ROLES = "application_roles";
public static final String CUSTOM = "custom";
public static final String AZP = "azp";
public static final String AUTH_TIME = "auth_time";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.oauth.dcr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
10 changes: 9 additions & 1 deletion components/org.wso2.carbon.identity.oauth.endpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -146,6 +146,14 @@
<artifactId>org.wso2.carbon.identity.oidc.session</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.wso2</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,36 @@ private void addFederatedTokensToSessionCache(OAuthMessage oAuthMessage,
}
}

/**
* Add mapped remote claims to session cache.
*
* @param oAuthMessage The OAuthMessage with the session data cache entry.
* @param authenticationResult The authentication result of authorization call.
*/
private void addMappedRemoteClaimsToSessionCache(OAuthMessage oAuthMessage,
AuthenticationResult authenticationResult) {

Optional<Map<String, String>> mappedRemoteClaims = authenticationResult.getMappedRemoteClaims();
if (!mappedRemoteClaims.isPresent()) {
return;
}

SessionDataCacheEntry sessionDataCacheEntry = oAuthMessage.getSessionDataCacheEntry();
if (sessionDataCacheEntry == null || mappedRemoteClaims.get().isEmpty()) {
return;
}
Map<ClaimMapping, String> mappedRemoteClaimsMap = new HashMap<>();
mappedRemoteClaims.get().forEach(
(key, value) -> mappedRemoteClaimsMap.put(ClaimMapping.build(key, key, null,
false), value));
sessionDataCacheEntry.setMappedRemoteClaims(mappedRemoteClaimsMap);
if (log.isDebugEnabled() && authenticationResult.getSubject() != null) {
log.debug("Added the mapped remote claims to the session data cache. " +
"Session context identifier: " + sessionDataCacheEntry.getSessionContextIdentifier()
+ " for the user: " + authenticationResult.getSubject().getLoggableMaskedUserId());
}
}

/**
* This method creates a list of FederatedTokenDO objects from the list of FederatedToken objects.
*
Expand Down Expand Up @@ -1389,6 +1419,9 @@ private void addToAuthenticationResultDetailsToOAuthMessage(OAuthMessage oAuthMe
authnResult.getProperty(FrameworkConstants.AnalyticsAttributes.SESSION_ID));
// Adding federated tokens come with the authentication result of the authorization call.
addFederatedTokensToSessionCache(oAuthMessage, authnResult);
// Adding mapped remoted claims come with the authentication result to resolve access token claims in
// federated flow.
addMappedRemoteClaimsToSessionCache(oAuthMessage, authnResult);
}

private void updateAuthTimeInSessionDataCacheEntry(OAuthMessage oAuthMessage) {
Expand Down Expand Up @@ -2143,6 +2176,10 @@ private void addUserAttributesToOAuthMessage(OAuthMessage oAuthMessage, String c
authorizationGrantCacheEntry.setRequestObjectFlow(isRequestObjectFlow);
authorizationGrantCacheEntry.setFederatedTokens(sessionDataCacheEntry.getFederatedTokens());
sessionDataCacheEntry.setFederatedTokens(null);
Map<ClaimMapping, String> mappedRemoteClaims = sessionDataCacheEntry.getMappedRemoteClaims();
if (mappedRemoteClaims != null) {
authorizationGrantCacheEntry.setMappedRemoteClaims(mappedRemoteClaims);
}
oAuthMessage.setAuthorizationGrantCacheEntry(authorizationGrantCacheEntry);
}

Expand Down Expand Up @@ -3785,6 +3822,7 @@ private OAuth2AuthorizeReqDTO buildAuthRequest(OAuth2Parameters oauth2Params, Se
authzReqDTO.setState(oauth2Params.getState());
authzReqDTO.setHttpServletRequestWrapper(new HttpServletRequestWrapper(request));
authzReqDTO.setRequestedSubjectId(oauth2Params.getRequestedSubjectId());
authzReqDTO.setMappedRemoteClaims(sessionDataCacheEntry.getMappedRemoteClaims());

if (sessionDataCacheEntry.getParamMap() != null && sessionDataCacheEntry.getParamMap().get(OAuthConstants
.AMR) != null) {
Expand Down Expand Up @@ -4520,6 +4558,10 @@ private void addUserAttributesToCache(SessionDataCacheEntry sessionDataCacheEntr
DeviceAuthorizationGrantCacheKey cacheKey = new DeviceAuthorizationGrantCacheKey(deviceCode);
DeviceAuthorizationGrantCacheEntry cacheEntry =
new DeviceAuthorizationGrantCacheEntry(sessionDataCacheEntry.getLoggedInUser().getUserAttributes());
if (sessionDataCacheEntry.getMappedRemoteClaims() != null) {
cacheEntry.setMappedRemoteClaims(sessionDataCacheEntry
.getMappedRemoteClaims());
}
DeviceAuthorizationGrantCache.getInstance().addToCache(cacheKey, cacheEntry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.commons.collections.MapUtils;
import org.wso2.carbon.identity.application.common.model.ClaimMapping;
import org.wso2.carbon.identity.core.util.IdentityCoreConstants;
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
import org.wso2.carbon.identity.oauth.endpoint.util.ClaimUtil;
import org.wso2.carbon.identity.oauth.user.UserInfoClaimRetriever;

Expand All @@ -43,7 +44,10 @@ public Map<String, Object> getClaimsMap(Map<ClaimMapping, String> userAttributes
}
String claimValue = entry.getValue();
String claimUri = entry.getKey().getRemoteClaim().getClaimUri();
if (ClaimUtil.isMultiValuedAttribute(claimUri, claimValue)) {
boolean isMultiValueSupportEnabledForUserinfoResponse = OAuthServerConfiguration.getInstance()
.getUserInfoMultiValueSupportEnabled();
if (isMultiValueSupportEnabledForUserinfoResponse &&
ClaimUtil.isMultiValuedAttribute(claimUri, claimValue)) {
String[] attributeValues = ClaimUtil.processMultiValuedAttribute(claimValue);
claims.put(entry.getKey().getRemoteClaim().getClaimUri(), attributeValues);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ public static Map<String, Object> getClaimsFromUserStore(OAuth2TokenValidationRe
continue;
}
}
if (isMultiValuedAttribute(oidcClaimUri, claimValue)) {
boolean isMultiValueSupportEnabledForUserinfoResponse = OAuthServerConfiguration
.getInstance().getUserInfoMultiValueSupportEnabled();
if (isMultiValueSupportEnabledForUserinfoResponse &&
isMultiValuedAttribute(oidcClaimUri, claimValue)) {
String[] attributeValues = processMultiValuedAttribute(claimValue);
mappedAppClaims.put(oidcClaimUri, attributeValues);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>identity-inbound-auth-oauth</artifactId>
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.oauth.par/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.oauth.stub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.oauth.ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
9 changes: 3 additions & 6 deletions components/org.wso2.carbon.identity.oauth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>
<artifactId>identity-inbound-auth-oauth</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>7.0.193-SNAPSHOT</version>
<version>7.0.205-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -176,10 +176,6 @@
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.application.common</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.entitlement</artifactId>
</dependency>

<!--SAML Common Util dependency-->
<dependency>
Expand Down Expand Up @@ -421,7 +417,8 @@
org.osgi.framework; version="${osgi.framework.imp.pkg.version.range}",
org.osgi.service.component; version="${osgi.service.component.imp.pkg.version.range}",

org.wso2.carbon.identity.entitlement; version="${carbon.identity.framework.imp.pkg.version.range}"; resolution:=optional,
org.wso2.carbon.identity.entitlement;
version="${identity.oauth.xacml.version.range}"; resolution:=optional,
org.wso2.carbon.idp.mgt; version="${carbon.identity.framework.imp.pkg.version.range}",
org.wso2.carbon.identity.base; version="${carbon.identity.framework.imp.pkg.version.range}",
org.wso2.carbon.identity.core.*; version="${carbon.identity.framework.imp.pkg.version.range}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.wso2.carbon.identity.oauth.cache;

import com.nimbusds.jwt.JWT;
import com.nimbusds.jwt.JWTParser;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
Expand All @@ -29,10 +31,10 @@
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
import org.wso2.carbon.identity.oauth2.dao.OAuthTokenPersistenceFactory;
import org.wso2.carbon.identity.oauth2.model.AccessTokenDO;
import org.wso2.carbon.identity.oauth2.util.OAuth2Util;
import org.wso2.carbon.utils.CarbonUtils;

import java.text.ParseException;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -237,11 +239,22 @@ private String replaceFromCodeId(String authzCode) {
* @return TOKEN_ID from the database
*/
private String replaceFromTokenId(String keyValue) {
try {
AccessTokenDO accessTokenDO = OAuth2Util.findAccessToken(keyValue, true);
if (accessTokenDO != null) {
return accessTokenDO.getTokenId();
if (OAuth2Util.isJWT(keyValue)) {
try {
JWT parsedJwtToken = JWTParser.parse(keyValue);
keyValue = parsedJwtToken.getJWTClaimsSet().getJWTID();
} catch (ParseException e) {
if (log.isDebugEnabled()) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
log.debug("Error while getting JWTID from token: " + keyValue, e);
} else {
log.debug("Error while getting JWTID from token");
}
}
}
}
try {
return OAuthTokenPersistenceFactory.getInstance().getAccessTokenDAO().getTokenIdByAccessToken(keyValue);
} catch (IdentityOAuth2Exception e) {
log.error("Failed to retrieve token id by token from store for - ." + keyValue, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class AuthorizationGrantCacheEntry extends CacheEntry {

private boolean hasNonOIDCClaims;

private Map<ClaimMapping, String> mappedRemoteClaims;

/*
OIDC sub claim. This should be formatted based on the Service Provider configurations to append
userStoreDomain and tenantDomain.
Expand Down Expand Up @@ -390,4 +392,15 @@ public void setPreIssueAccessTokenActionsExecuted(boolean preIssueAccessTokenAct

isPreIssueAccessTokenActionsExecuted = preIssueAccessTokenActionsExecuted;
}

public Map<ClaimMapping, String> getMappedRemoteClaims() {

return mappedRemoteClaims;
}

public void setMappedRemoteClaims(
Map<ClaimMapping, String> mappedRemoteClaims) {

this.mappedRemoteClaims = mappedRemoteClaims;
}
}
Loading

0 comments on commit 678a6db

Please sign in to comment.