diff --git a/NOTICE b/NOTICE index f23dc44095f371086d63c8ee6bbab83a9f699041..a07bd0175c61261da9a2b307eef2875327a4cd3c 100644 --- a/NOTICE +++ b/NOTICE @@ -83,7 +83,7 @@ The following software have components provided under the terms of this license: - Byte Buddy Java agent (from https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent) - ClassMate (from http://github.com/cowtowncoder/java-classmate) - Cloud Key Management Service (KMS) API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms) -- Cloud Storage JSON API (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) +- Cloud Storage JSON API v1-rev20240202-2.0.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage) - Collections (from https://repo1.maven.org/maven2/commons-collections/commons-collections) - Commons Digester (from http://commons.apache.org/digester/) - Converter: Jackson (from https://github.com/square/retrofit, https://repo1.maven.org/maven2/com/squareup/retrofit2/converter-jackson) diff --git a/storage-core/src/main/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImpl.java b/storage-core/src/main/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImpl.java index 222912d8a1b92eb156d0681cbc932e2a746db9ad..3582f8de8e104004a8533fe3856240896af5ecd6 100644 --- a/storage-core/src/main/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImpl.java +++ b/storage-core/src/main/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImpl.java @@ -190,8 +190,8 @@ public class EntitlementsAndCacheServiceImpl implements IEntitlementsExtensionSe } protected static String getGroupCacheKey(DpsHeaders headers) { - String key = String.format("entitlement-groups:%s:%s", headers.getPartitionIdWithFallbackToAccountId(), - headers.getAuthorization()); + String key = String.format("entitlement-groups:%s:%s:%s", headers.getPartitionIdWithFallbackToAccountId(), + headers.getAuthorization(), headers.getUserId()); return Crc32c.hashToBase64EncodedString(key); } } diff --git a/storage-core/src/test/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImplTest.java b/storage-core/src/test/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImplTest.java index 845e4dffed7daa45628aa775223720df72f10695..98cb0e7ab66f4e23710b85732070e8c71b9fd8d6 100644 --- a/storage-core/src/test/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImplTest.java +++ b/storage-core/src/test/java/org/opengroup/osdu/storage/service/EntitlementsAndCacheServiceImplTest.java @@ -43,8 +43,12 @@ import static org.mockito.Mockito.*; public class EntitlementsAndCacheServiceImplTest { private static final String MEMBER_EMAIL = "tester@gmail.com"; + private static final String MEMBER_EMAIL_2 = "tester2@gmail.com"; private static final String HEADER_ACCOUNT_ID = "anyTenant"; private static final String HEADER_AUTHORIZATION = "anyCrazyToken"; + private static final String USER_ID = "userID"; + + private static final String USER_ID_2 = "userID2"; @Mock private IEntitlementsFactory entitlementFactory; @@ -84,6 +88,7 @@ public class EntitlementsAndCacheServiceImplTest { private void setDefaultHeaders() { headerMap.put(DpsHeaders.ACCOUNT_ID, HEADER_ACCOUNT_ID); headerMap.put(DpsHeaders.AUTHORIZATION, HEADER_AUTHORIZATION); + headerMap.put(DpsHeaders.USER_ID, USER_ID); } @Test @@ -221,13 +226,65 @@ public class EntitlementsAndCacheServiceImplTest { // First call, getting groups from entitlements assertEquals(MEMBER_EMAIL, this.sut.authorize(this.headers, "role2")); - when(this.cache.get("NLdxKQ==")).thenReturn(groups); + when(this.cache.get("5QjU5g==")).thenReturn(groups); // Second call, getting groups from cache assertEquals(MEMBER_EMAIL, this.sut.authorize(this.headers, "role2")); verify(this.entitlementService, times(1)).getGroups(); - verify(this.cache, times(2)).get("NLdxKQ=="); - verify(this.cache, times(1)).put("NLdxKQ==", groups); + verify(this.cache, times(2)).get("5QjU5g=="); + verify(this.cache, times(1)).put("5QjU5g==", groups); + } + + @Test + public void should_getGroupsFromCache_when_requestHashIsFoundInCacheTwoDifferentUSerIDs() throws EntitlementsException { + + GroupInfo g1 = new GroupInfo(); + g1.setEmail("role1@gmail.com"); + g1.setName("role1"); + + GroupInfo g2 = new GroupInfo(); + g2.setEmail("role2@gmail.com"); + g2.setName("role2"); + + GroupInfo g3 = new GroupInfo(); + g3.setEmail("role3@gmail.com"); + g3.setName("role3"); + + GroupInfo g4 = new GroupInfo(); + g4.setEmail("role4@gmail.com"); + g4.setName("role4"); + + List<GroupInfo> groupsInfo1 = new ArrayList<>(); + groupsInfo1.add(g1); + groupsInfo1.add(g2); + + List<GroupInfo> groupsInfo2 = new ArrayList<>(); + groupsInfo2.add(g3); + groupsInfo2.add(g4); + + Groups groups = new Groups(); + groups.setGroups(groupsInfo1); + groups.setDesId(MEMBER_EMAIL); + + Groups groups2 = new Groups(); + groups2.setGroups(groupsInfo2); + groups2.setDesId(MEMBER_EMAIL_2); + + when(this.cache.get("5QjU5g==")).thenReturn(groups); + when(this.cache.get("RtEtMQ==")).thenReturn(groups2); + + assertEquals(MEMBER_EMAIL, this.sut.authorize(this.headers, "role2")); + + verify(this.cache, times(1)).get("5QjU5g=="); + + headerMap.put(DpsHeaders.USER_ID, USER_ID_2); + this.headers = DpsHeaders.createFromMap(headerMap); + + assertEquals(MEMBER_EMAIL_2, this.sut.authorize(this.headers, "role3")); + + // Verifies that cache key is different in case of different user + verify(this.cache, times(1)).get("RtEtMQ=="); + } @Test