From 0b5bc7306087c889ccc18405d8964799d70fccd0 Mon Sep 17 00:00:00 2001 From: Ashan Thamara Date: Fri, 20 Mar 2026 00:08:38 +0530 Subject: [PATCH 1/2] Revert "Add expiry validation and null check util method for cache entries" This reverts commit 76f3baa1c9cee4c91a005bb00e716264c38534cb. --- .../identity/core/util/IdentityCacheUtil.java | 49 ----------- .../core/util/IdentityCacheUtilTest.java | 83 ------------------- .../src/test/resources/testng.xml | 1 - 3 files changed, 133 deletions(-) delete mode 100644 components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityCacheUtil.java delete mode 100644 components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/util/IdentityCacheUtilTest.java diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityCacheUtil.java b/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityCacheUtil.java deleted file mode 100644 index bbea550b0e5a..000000000000 --- a/components/identity-core/org.wso2.carbon.identity.core/src/main/java/org/wso2/carbon/identity/core/util/IdentityCacheUtil.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.identity.core.util; - -import org.wso2.carbon.identity.core.cache.CacheEntry; - -/** - * Utility class for cache operations. - */ -public class IdentityCacheUtil { - - private IdentityCacheUtil() {} - - /** - * Check if a cache entry has expired. - * - * @param cacheEntry Cache entry to check for expiration. - * @return true if the cache entry has expired or is null, false otherwise. - */ - public static boolean isCacheEntryExpired(CacheEntry cacheEntry) { - - if (cacheEntry == null) { - return true; - } - long validityPeriod = cacheEntry.getValidityPeriod(); - - // If validityPeriod is 0, it means the entry doesn't expire. - if (validityPeriod == 0L) { - return false; - } - return System.nanoTime() > validityPeriod; - } -} diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/util/IdentityCacheUtilTest.java b/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/util/IdentityCacheUtilTest.java deleted file mode 100644 index 3fd68f50ec69..000000000000 --- a/components/identity-core/org.wso2.carbon.identity.core/src/test/java/org/wso2/carbon/identity/core/util/IdentityCacheUtilTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.identity.core.util; - -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import org.wso2.carbon.identity.core.cache.CacheEntry; - -import static org.testng.Assert.assertEquals; - -/** - * Unit tests for IdentityCacheUtil. - */ -public class IdentityCacheUtilTest { - - /** - * Data provider for cache entry expiration test cases. - * - * @return Test data containing validity period and expected expiration result. - */ - @DataProvider(name = "cacheExpirationData") - public Object[][] cacheExpirationData() { - - long futureTime = System.nanoTime() + (60L * 60L * 1000000000L); - long pastTime = System.nanoTime() - (60L * 60L * 1000000000L); - - return new Object[][] { - // validity period, expected expiration result, description. - {null, true, "Null cache entry should be considered expired"}, - {0L, false, "Cache entry with validity period 0 should never expire"}, - {futureTime, false, "Cache entry with future validity period should not be expired"}, - {pastTime, true, "Cache entry with past validity period should be expired"} - }; - } - - /** - * Test cache entry expiration with various validity periods. - * - * @param validityPeriod The validity period in nanoseconds. - * @param expectedExpired The expected expiration result. - * @param description Description of the test case. - */ - @Test(dataProvider = "cacheExpirationData") - public void testIsCacheEntryExpired(Long validityPeriod, boolean expectedExpired, String description) { - - CacheEntry cacheEntry = validityPeriod == null ? null : new TestCacheEntry(validityPeriod); - assertEquals(IdentityCacheUtil.isCacheEntryExpired(cacheEntry), expectedExpired, description); - } - - /** - * Test implementation of CacheEntry for testing purposes. - */ - private static class TestCacheEntry extends CacheEntry { - - private static final long serialVersionUID = 1L; - private final long validityPeriod; - - public TestCacheEntry(long validityPeriod) { - this.validityPeriod = validityPeriod; - } - - @Override - public long getValidityPeriod() { - return validityPeriod; - } - } -} diff --git a/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml b/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml index d06c23395db7..420272e6fa11 100644 --- a/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml +++ b/components/identity-core/org.wso2.carbon.identity.core/src/test/resources/testng.xml @@ -23,7 +23,6 @@ - From 31ace83dec8ac7be1a011d3589f739c81babb67b Mon Sep 17 00:00:00 2001 From: Ashan Thamara Date: Fri, 20 Mar 2026 00:13:08 +0530 Subject: [PATCH 2/2] Add configuration to configure push device registration context validity period --- .../resources/identity.xml | 6 ++++++ .../resources/identity.xml.j2 | 6 ++++++ ...rg.wso2.carbon.identity.core.server.feature.default.json | 1 + 3 files changed, 13 insertions(+) diff --git a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml index 96ac1a6f5c20..6c48b15806b8 100644 --- a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml +++ b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml @@ -820,6 +820,12 @@ true + + + 180 + + + false diff --git a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml.j2 b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml.j2 index 5af98bbdad26..435196e413fd 100644 --- a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml.j2 +++ b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/identity.xml.j2 @@ -1500,6 +1500,12 @@ {{oauth.allow_issuer_selection_for_sub_org_applications}} + + + {{push_authenticator.device_registration_context.validity_period}} + + + {{rest_api_authentication.add_realm_user_to_error}} diff --git a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/org.wso2.carbon.identity.core.server.feature.default.json b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/org.wso2.carbon.identity.core.server.feature.default.json index 2b71165b32e6..4210f6ff9bed 100644 --- a/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/org.wso2.carbon.identity.core.server.feature.default.json +++ b/features/identity-core/org.wso2.carbon.identity.core.server.feature/resources/org.wso2.carbon.identity.core.server.feature.default.json @@ -850,6 +850,7 @@ "cache.push_device_registration_request_cache.enable": true, "cache.push_device_registration_request_cache.timeout": "300", "cache.push_device_registration_request_cache.capacity": "$ref{cache.default_capacity}", + "push_authenticator.device_registration_context.validity_period": "180", "cache.saml_cert_cache.enable": true, "cache.saml_cert_cache.timeout": "900", "cache.saml_cert_cache.capacity": "100",