Skip to content

Commit 7863c26

Browse files
authored
Merge pull request #3141 from wso2-extensions/sync-pr-3129-to-next
[Sync][master -> next][#3129]: Refactor cache operations to use read-safe methods for concurrent environments
2 parents b850c5a + 427a869 commit 7863c26

File tree

30 files changed

+627
-31
lines changed

30 files changed

+627
-31
lines changed

components/org.wso2.carbon.identity.oauth.dcr/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@
8383
<dependency>
8484
<groupId>org.wso2.carbon.identity.framework</groupId>
8585
<artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
86+
<exclusions>
87+
<exclusion>
88+
<groupId>org.eclipse.platform</groupId>
89+
<artifactId>org.eclipse.equinox.http.service.api</artifactId>
90+
</exclusion>
91+
</exclusions>
8692
</dependency>
8793
<dependency>
8894
<groupId>org.testng</groupId>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ private static OAuthAppDO getAppInformation(OAuth2AuthorizeReqDTO authzReqDTO) t
13681368
} else {
13691369
oAuthAppDO = new OAuthAppDAO().getAppInformation(authzReqDTO.getConsumerKey());
13701370
}
1371-
AppInfoCache.getInstance().addToCache(authzReqDTO.getConsumerKey(), oAuthAppDO);
1371+
AppInfoCache.getInstance().addToCacheOnRead(authzReqDTO.getConsumerKey(), oAuthAppDO);
13721372
return oAuthAppDO;
13731373
}
13741374
}

components/org.wso2.carbon.identity.oauth.extension/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
<groupId>org.wso2.carbon.identity.framework</groupId>
3434
<artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
3535
<scope>provided</scope>
36+
<exclusions>
37+
<exclusion>
38+
<groupId>org.eclipse.platform</groupId>
39+
<artifactId>org.eclipse.equinox.http.service.api</artifactId>
40+
</exclusion>
41+
</exclusions>
3642
</dependency>
3743
<dependency>
3844
<groupId>org.openjdk.nashorn</groupId>

components/org.wso2.carbon.identity.oauth.par/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,22 @@
7373
<dependency>
7474
<groupId>org.wso2.carbon.identity.framework</groupId>
7575
<artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
76+
<exclusions>
77+
<exclusion>
78+
<groupId>org.eclipse.platform</groupId>
79+
<artifactId>org.eclipse.equinox.http.service.api</artifactId>
80+
</exclusion>
81+
</exclusions>
7682
</dependency>
7783
<dependency>
7884
<groupId>org.wso2.carbon.identity.framework</groupId>
7985
<artifactId>org.wso2.carbon.identity.application.authentication.framework</artifactId>
86+
<exclusions>
87+
<exclusion>
88+
<groupId>org.eclipse.platform</groupId>
89+
<artifactId>org.eclipse.equinox.http.service.api</artifactId>
90+
</exclusion>
91+
</exclusions>
8092
</dependency>
8193
<dependency>
8294
<groupId>org.apache.ws.commons.axiom.wso2</groupId>

components/org.wso2.carbon.identity.oauth.ui/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
<dependency>
4545
<groupId>org.wso2.carbon</groupId>
4646
<artifactId>org.wso2.carbon.ui</artifactId>
47+
<exclusions>
48+
<exclusion>
49+
<groupId>org.eclipse.platform</groupId>
50+
<artifactId>org.eclipse.equinox.http.service.api</artifactId>
51+
</exclusion>
52+
</exclusions>
4753
</dependency>
4854
<dependency>
4955
<groupId>org.ops4j.pax.logging</groupId>
@@ -82,6 +88,12 @@
8288
<dependency>
8389
<groupId>org.eclipse.platform</groupId>
8490
<artifactId>org.eclipse.osgi.services</artifactId>
91+
<exclusions>
92+
<exclusion>
93+
<groupId>org.eclipse.platform</groupId>
94+
<artifactId>org.eclipse.equinox.http.service.api</artifactId>
95+
</exclusion>
96+
</exclusions>
8597
</dependency>
8698
<dependency>
8799
<groupId>org.wso2.carbon.identity.inbound.auth.oauth2</groupId>

components/org.wso2.carbon.identity.oauth/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@
222222
<groupId>org.slf4j</groupId>
223223
<artifactId>log4j-over-slf4j</artifactId>
224224
</exclusion>
225+
<exclusion>
226+
<groupId>org.eclipse.platform</groupId>
227+
<artifactId>org.eclipse.equinox.http.service.api</artifactId>
228+
</exclusion>
225229
</exclusions>
226230
</dependency>
227231
<dependency>

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/OAuthAdminServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2721,7 +2721,7 @@ OAuthAppDO getOAuthApp(String consumerKey, String tenantDomain) throws InvalidOA
27212721
if (LOG.isDebugEnabled()) {
27222722
LOG.debug("OAuth app with consumerKey: " + consumerKey + " retrieved from database.");
27232723
}
2724-
AppInfoCache.getInstance().addToCache(consumerKey, oauthApp, tenantDomain);
2724+
AppInfoCache.getInstance().addToCacheOnRead(consumerKey, oauthApp, tenantDomain);
27252725
}
27262726
return oauthApp;
27272727
}

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/cache/AuthorizationGrantCache.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public AuthorizationGrantCacheEntry getValueFromCacheByTokenId(AuthorizationGran
106106
}
107107
cacheEntry = getFromSessionStore(tokenId);
108108
if (cacheEntry != null && key != null) {
109-
super.addToCache(key, cacheEntry);
109+
super.addToCacheOnRead(key, cacheEntry);
110110
}
111111
}
112112
return cacheEntry;
@@ -130,7 +130,7 @@ public AuthorizationGrantCacheEntry getValueFromCacheByTokenId(AuthorizationGran
130130
}
131131
cacheEntry = getFromSessionStore(tokenId, operation);
132132
if (cacheEntry != null) {
133-
super.addToCache(key, cacheEntry);
133+
super.addToCacheOnRead(key, cacheEntry);
134134
}
135135
}
136136
return cacheEntry;
@@ -155,7 +155,7 @@ public AuthorizationGrantCacheEntry getValueFromCacheByToken(AuthorizationGrantC
155155
}
156156
cacheEntry = getFromSessionStore(replaceFromTokenId(key.getUserAttributesId()));
157157
if (cacheEntry != null) {
158-
super.addToCache(key, cacheEntry);
158+
super.addToCacheOnRead(key, cacheEntry);
159159
}
160160
}
161161
return cacheEntry;
@@ -238,7 +238,7 @@ public AuthorizationGrantCacheEntry getValueFromCacheByCode(AuthorizationGrantCa
238238
}
239239
cacheEntry = getFromSessionStore(replaceFromCodeId(key.getUserAttributesId()));
240240
if (cacheEntry != null) {
241-
super.addToCache(key, cacheEntry);
241+
super.addToCacheOnRead(key, cacheEntry);
242242
}
243243
}
244244
return cacheEntry;

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/cache/OAuthCache.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ public void addToCache(OAuthCacheKey key, CacheEntry entry) {
7676
}
7777
}
7878

79+
@Override
80+
public void addToCacheOnRead(OAuthCacheKey key, CacheEntry entry) {
81+
82+
if (entry instanceof AccessTokenDO) {
83+
AccessTokenDO tokenDO = (AccessTokenDO) entry;
84+
String tenantDomain = tokenDO.getAuthzUser().getTenantDomain();
85+
if (LOG.isDebugEnabled()) {
86+
LOG.debug(String.format("[AddToCacheOnRead] AccessTokenDO was added for the given token identifier: " +
87+
"%s in the tenant: %s.", ((AccessTokenDO) entry).getTokenId(), tenantDomain));
88+
}
89+
super.addToCacheOnRead(key, entry, tenantDomain);
90+
} else {
91+
super.addToCacheOnRead(key, entry);
92+
}
93+
}
94+
7995
@Override
8096
public void clearCacheEntry(OAuthCacheKey key, String tenantDomain) {
8197

components/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/cache/OAuthScopeBindingCache.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ public void addToCache(OAuthScopeBindingCacheKey key, Scope[] entry, int tenantI
6363
}
6464
}
6565

66+
/**
67+
* Add a cache entry during a READ operation.
68+
*
69+
* @param key Key which cache entry is indexed.
70+
* @param entry Actual object where cache entry is placed.
71+
*/
72+
public void addToCacheOnRead(OAuthScopeBindingCacheKey key, Scope[] entry, int tenantId) {
73+
74+
super.addToCacheOnRead(key, entry, tenantId);
75+
if (log.isDebugEnabled()) {
76+
log.debug("[AddToCacheOnRead] Scope bindings are added to the cache. \n" + ArrayUtils.toString(entry));
77+
}
78+
}
79+
6680
/**
6781
* Retrieves a cache entry.
6882
*

0 commit comments

Comments
 (0)