Skip to content

Commit c7579cf

Browse files
committed
front port fixes from wso2-extensions#2208
1 parent 0260929 commit c7579cf

File tree

23 files changed

+305
-187
lines changed

23 files changed

+305
-187
lines changed

components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/user/impl/UserInfoISAccessTokenValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public OAuth2TokenValidationResponseDTO validateToken(String accessTokenIdentifi
7878
}
7979

8080
try {
81-
accessTokenDO = OAuth2ServiceComponentHolder.getInstance().getAccessTokenProvider()
81+
accessTokenDO = OAuth2ServiceComponentHolder.getInstance().getTokenProvider()
8282
.getVerifiedAccessToken(accessTokenIdentifier, false);
8383
} catch (IdentityOAuth2Exception e) {
8484
throw new UserInfoEndpointException("Error in getting AccessTokenDO", e);

components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/user/impl/UserInfoJWTResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private String getAuthzUserTenantDomain(OAuth2TokenValidationResponseDTO tokenRe
120120

121121
AccessTokenDO accessTokenDO;
122122
try {
123-
accessTokenDO = OAuth2ServiceComponentHolder.getInstance().getAccessTokenProvider()
123+
accessTokenDO = OAuth2ServiceComponentHolder.getInstance().getTokenProvider()
124124
.getVerifiedAccessToken(tokenResponse.getAuthorizationContextToken().getTokenString(), false);
125125
} catch (IdentityOAuth2Exception e) {
126126
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {

components/org.wso2.carbon.identity.oauth.endpoint/src/main/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static Map<String, Object> getClaimsFromUserStore(OAuth2TokenValidationRe
116116
String subjectClaimValue = null;
117117

118118
try {
119-
AccessTokenDO accessTokenDO = OAuth2ServiceComponentHolder.getInstance().getAccessTokenProvider()
119+
AccessTokenDO accessTokenDO = OAuth2ServiceComponentHolder.getInstance().getTokenProvider()
120120
.getVerifiedAccessToken(tokenResponse.getAuthorizationContextToken().getTokenString(),
121121
false);
122122
userId = accessTokenDO.getAuthzUser().getUserId();

components/org.wso2.carbon.identity.oauth.endpoint/src/test/java/org/wso2/carbon/identity/oauth/endpoint/user/impl/UserInfoJSONResponseBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCache;
3838
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
3939
import org.wso2.carbon.identity.oauth.endpoint.util.ClaimUtil;
40-
import org.wso2.carbon.identity.oauth.tokenprocessor.DefaultAccessTokenProvider;
40+
import org.wso2.carbon.identity.oauth.tokenprocessor.DefaultTokenProvider;
4141
import org.wso2.carbon.identity.oauth2.RequestObjectException;
4242
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO;
4343
import org.wso2.carbon.identity.oauth2.internal.OAuth2ServiceComponentHolder;
@@ -91,7 +91,7 @@ public void setUpTest() throws Exception {
9191

9292
OAuth2ServiceComponentHolder.getInstance().setScopeClaimMappingDAO(new ScopeClaimMappingDAOImpl());
9393
userInfoJSONResponseBuilder = new UserInfoJSONResponseBuilder();
94-
OAuth2ServiceComponentHolder.getInstance().setAccessTokenProvider(new DefaultAccessTokenProvider());
94+
OAuth2ServiceComponentHolder.getInstance().setTokenProvider(new DefaultTokenProvider());
9595
TestUtils.initiateH2Base();
9696
con = TestUtils.getConnection();
9797
}

components/org.wso2.carbon.identity.oauth.endpoint/src/test/java/org/wso2/carbon/identity/oauth/endpoint/util/ClaimUtilTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException;
4444
import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
4545
import org.wso2.carbon.identity.oauth.dao.OAuthAppDO;
46-
import org.wso2.carbon.identity.oauth.tokenprocessor.DefaultAccessTokenProvider;
46+
import org.wso2.carbon.identity.oauth.tokenprocessor.DefaultTokenProvider;
4747
import org.wso2.carbon.identity.oauth.user.UserInfoEndpointException;
4848
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
4949
import org.wso2.carbon.identity.oauth2.dto.OAuth2TokenValidationResponseDTO;
@@ -319,8 +319,8 @@ public void testGetClaimsFromUserStore(boolean mockRealm, boolean mockAccessToke
319319
OAuth2ServiceComponentHolder oAuth2ServiceComponentHolderInstance =
320320
Mockito.mock(OAuth2ServiceComponentHolder.class);
321321
when(OAuth2ServiceComponentHolder.getInstance()).thenReturn(oAuth2ServiceComponentHolderInstance);
322-
when(oAuth2ServiceComponentHolderInstance.getAccessTokenProvider())
323-
.thenReturn(new DefaultAccessTokenProvider());
322+
when(oAuth2ServiceComponentHolderInstance.getTokenProvider())
323+
.thenReturn(new DefaultTokenProvider());
324324
Map<String, Object> claimsMap;
325325
try {
326326
claimsMap = ClaimUtil.getClaimsFromUserStore(mockedValidationTokenResponseDTO);

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/tokenprocessor/DefaultOAuth2RevocationProcessor.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
import org.wso2.carbon.user.core.UserStoreManager;
3232

3333
/**
34-
* Handles oauth2 token revocation when persistence layer exists.
34+
* DefaultOAuth2RevocationProcessor is responsible for handling OAuth2 token revocation
35+
* when a persistence layer is in use. It provides methods to revoke access tokens and
36+
* refresh tokens, as well as a mechanism to revoke tokens associated with a specific user.
3537
*/
3638
public class DefaultOAuth2RevocationProcessor implements OAuth2RevocationProcessor {
3739

@@ -51,27 +53,6 @@ public void revokeRefreshToken(OAuthRevocationRequestDTO revokeRequestDTO,
5153
.revokeAccessTokens(new String[]{refreshTokenDO.getAccessToken()});
5254
}
5355

54-
@Override
55-
public RefreshTokenValidationDataDO getRevocableRefreshToken(OAuthRevocationRequestDTO revokeRequestDTO)
56-
throws IdentityOAuth2Exception {
57-
58-
return OAuthTokenPersistenceFactory.getInstance().getTokenManagementDAO()
59-
.validateRefreshToken(revokeRequestDTO.getConsumerKey(), revokeRequestDTO.getToken());
60-
}
61-
62-
@Override
63-
public AccessTokenDO getRevocableAccessToken(OAuthRevocationRequestDTO revokeRequestDTO)
64-
throws IdentityOAuth2Exception {
65-
66-
return OAuth2Util.findAccessToken(revokeRequestDTO.getToken(), true);
67-
}
68-
69-
@Override
70-
public boolean isRefreshTokenType(OAuthRevocationRequestDTO revokeRequestDTO) {
71-
72-
return StringUtils.equals(GrantType.REFRESH_TOKEN.toString(), revokeRequestDTO.getTokenType());
73-
}
74-
7556
@Override
7657
public boolean revokeTokens(String username, UserStoreManager userStoreManager)
7758
throws UserStoreException {
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,29 @@
1919
package org.wso2.carbon.identity.oauth.tokenprocessor;
2020

2121
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
22+
import org.wso2.carbon.identity.oauth2.dao.OAuthTokenPersistenceFactory;
2223
import org.wso2.carbon.identity.oauth2.model.AccessTokenDO;
24+
import org.wso2.carbon.identity.oauth2.model.RefreshTokenValidationDataDO;
2325
import org.wso2.carbon.identity.oauth2.util.OAuth2Util;
2426

2527
/**
26-
* Default implementation of AccessTokenProvider for scenarios with token persistence enabled.
28+
* Default implementation of TokenProvider for scenarios with token persistence enabled.
2729
* Verifies access tokens by querying the database, including optional inclusion of expired tokens.
2830
*/
29-
public class DefaultAccessTokenProvider implements AccessTokenProvider {
31+
public class DefaultTokenProvider implements TokenProvider {
3032

3133
@Override
3234
public AccessTokenDO getVerifiedAccessToken(String accessToken, boolean includeExpired)
3335
throws IdentityOAuth2Exception {
3436

3537
return OAuth2Util.findAccessToken(accessToken, includeExpired);
3638
}
39+
40+
@Override
41+
public RefreshTokenValidationDataDO getVerifiedRefreshToken(String refreshToken, String consumerKey)
42+
throws IdentityOAuth2Exception {
43+
44+
return OAuthTokenPersistenceFactory.getInstance().getTokenManagementDAO().validateRefreshToken(consumerKey,
45+
refreshToken);
46+
}
3747
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/tokenprocessor/OAuth2RevocationProcessor.java

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.wso2.carbon.user.core.UserStoreManager;
2828

2929
/**
30-
* Abstraction layer between OAuth2Service and persistence layer to handle
31-
* revocation logic during token persistence and non-persistence scenarios.
30+
* Abstraction layer between OAuth2Service and persistence layer to handle revocation logic during token persistence
31+
* and non-persistence scenarios.
3232
*/
3333
public interface OAuth2RevocationProcessor {
3434

@@ -53,42 +53,13 @@ void revokeAccessToken(OAuthRevocationRequestDTO revokeRequestDTO, AccessTokenDO
5353
void revokeRefreshToken(OAuthRevocationRequestDTO revokeRequestDTO,
5454
RefreshTokenValidationDataDO refreshTokenDO) throws IdentityOAuth2Exception;
5555

56-
/**
57-
* Validate and return the refresh token metadata.
58-
*
59-
* @param revokeRequestDTO Metadata containing revoke token request.
60-
* @return RefreshTokenValidationDataDO {@link RefreshTokenValidationDataDO} instance.
61-
* @throws IdentityOAuth2Exception If an error occurs while validating the refresh token.
62-
*/
63-
RefreshTokenValidationDataDO getRevocableRefreshToken(OAuthRevocationRequestDTO revokeRequestDTO)
64-
throws IdentityOAuth2Exception;
65-
66-
/**
67-
* Validate and return the access token metadata.
68-
*
69-
* @param revokeRequestDTO Metadata containing revoke token request.
70-
* @return AccessTokenDO {@link AccessTokenDO} instance.
71-
* @throws IdentityOAuth2Exception If an error occurs while validating the access token.
72-
*/
73-
AccessTokenDO getRevocableAccessToken(OAuthRevocationRequestDTO revokeRequestDTO)
74-
throws IdentityOAuth2Exception;
75-
76-
/**
77-
* Check whether revoke request is related to access token or revoke token.
78-
*
79-
* @param revokeRequestDTO Metadata containing revoke token request.
80-
* @return boolean whether it is a refresh token request or not
81-
* @throws IdentityOAuth2Exception If an error occurs while checking the token type.
82-
*/
83-
boolean isRefreshTokenType(OAuthRevocationRequestDTO revokeRequestDTO) throws IdentityOAuth2Exception;
84-
8556
/**
8657
* Handle indirect token revocation for internal user events.
8758
*
8859
* @param username User on which the event occurred.
8960
* @param userStoreManager User store manager.
9061
* @return true if revocation is successful. Else return false.
91-
* @throws UserStoreException
62+
* @throws UserStoreException If an error occurs while revoking tokens for users.
9263
*/
9364
boolean revokeTokens(String username, UserStoreManager userStoreManager)
9465
throws UserStoreException;
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
2222
import org.wso2.carbon.identity.oauth2.model.AccessTokenDO;
23+
import org.wso2.carbon.identity.oauth2.model.RefreshTokenValidationDataDO;
2324

2425
/**
25-
* The AccessTokenProvider interface defines the contract for classes that are responsible
26-
* for verifying and providing access tokens. Implementing classes should offer methods
27-
* to retrieve access tokens based on token data objects, with the option to include expired
28-
* tokens in the verification process and handle potential exceptions.
26+
* The TokenProvider interface defines the contract for classes that are responsible
27+
* for verifying and providing access tokens and refresh tokens. Implementing classes should offer methods
28+
* to retrieve access tokens and refresh token based on token data objects.
2929
*/
30-
public interface AccessTokenProvider {
30+
public interface TokenProvider {
3131

3232
/**
3333
* Retrieves and verifies an access token based on the provided access token data object,
@@ -43,4 +43,17 @@ public interface AccessTokenProvider {
4343
* @throws IdentityOAuth2Exception If there is an error during the access token retrieval or verification process.
4444
*/
4545
AccessTokenDO getVerifiedAccessToken(String accessToken, boolean includeExpired) throws IdentityOAuth2Exception;
46+
47+
48+
/**
49+
* Retrieves and verifies a refresh token.
50+
*
51+
* @param refreshToken The access token data object to retrieve and verify.
52+
* @param consumerKey Consumer key
53+
* @return The RefreshTokenValidationDataDO if the token is valid (ACTIVE or EXPIRED), or null if the token
54+
* is not found either in ACTIVE or EXPIRED states.
55+
* @throws IdentityOAuth2Exception If there is an error during the access token retrieval or verification process.
56+
*/
57+
RefreshTokenValidationDataDO getVerifiedRefreshToken(String refreshToken, String consumerKey)
58+
throws IdentityOAuth2Exception;
4659
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/OAuth2Constants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public static class TokenBinderType {
3333

3434
}
3535
public static final String GROUPS = "groups";
36+
public static final String ENTITY_ID = "entity_id";
37+
public static final String IS_CONSENTED = "is_consented";
38+
public static final boolean DEFAULT_PERSIST_ENABLED = true;
39+
public static final String OAUTH_TOKEN_PERSISTENCE_ENABLE = "OAuth.TokenPersistence.Enable";
3640
}

0 commit comments

Comments
 (0)