Skip to content

Commit

Permalink
Move the configuration read method to the scim2
Browse files Browse the repository at this point in the history
  • Loading branch information
sandushi committed Oct 31, 2024
1 parent 1ceadcd commit 00317fb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public class SCIMCommonConstants {
"SCIM2.RemoveDuplicateUsersInUsersResponse";
public static final String SCIM2_COMPLEX_MULTI_ATTRIBUTE_FILTERING_ENABLED =
"SCIM2MultiAttributeFiltering.UsePagination";
public static final String CONSIDER_SERVER_WIDE_MAX_LIMIT_ENABLED=
"SCIM2.ConsiderServerWideUserEndpointMaxLimit";

public static final String URL_SEPERATOR = "/";
public static final String TENANT_URL_SEPERATOR = "/t/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,4 +986,20 @@ public static int validateCountParameter(Integer count) {

return count;
}

/**
* Read the SCIM User Endpoint Consider Server Wide config and returns it.
*
* @return If SCIM User Endpoint Consider Server Wise Config is enabled.
*/
public static boolean isConsiderServerWideUserEndpointMaxLimitEnabled() {

String considerServerWideUserEndpointMaxLimitProperty =
IdentityUtil.getProperty(SCIMCommonConstants.CONSIDER_SERVER_WIDE_MAX_LIMIT_ENABLED);

if (StringUtils.isBlank(considerServerWideUserEndpointMaxLimitProperty)) {
return true;
}
return Boolean.parseBoolean(considerServerWideUserEndpointMaxLimitProperty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.base.CarbonBaseConstants;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.identity.application.common.model.InboundProvisioningConfig;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
Expand All @@ -40,6 +39,7 @@
import org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping;
import org.wso2.carbon.identity.claim.metadata.mgt.model.ExternalClaim;
import org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim;
import org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.core.util.IdentityUtil;
import org.wso2.carbon.identity.scim2.common.DAO.GroupDAO;
Expand Down Expand Up @@ -91,6 +91,7 @@
import org.wso2.charon3.core.utils.codeutils.FilterTreeManager;
import org.wso2.charon3.core.utils.codeutils.Node;
import org.wso2.charon3.core.utils.codeutils.SearchRequest;
import org.wso2.carbon.identity.configuration.mgt.core.model.Resource;

import java.lang.reflect.Field;
import java.util.ArrayList;
Expand Down Expand Up @@ -142,6 +143,7 @@ public class SCIMUserManagerTest {
private static final String ADDRESS_LOCAL_CLAIM = "http://wso2.org/claims/addresses";
private static final String USER_SCHEMA_ADDRESS_HOME = "urn:ietf:params:scim:schemas:core:2.0:User:addresses.home";
private static final String USER_SCHEMA_ADDRESS_WORK= "urn:ietf:params:scim:schemas:core:2.0:User:addresses.work";
private static final String MAX_LIMIT_RESOURCE_NAME = "user-response-limit";

@Mock
private AbstractUserStoreManager mockedUserStoreManager;
Expand Down Expand Up @@ -191,6 +193,9 @@ public class SCIMUserManagerTest {
@Mock
private SCIMGroupHandler mockedSCIMGroupHandler;

@Mock
private ConfigurationManager mockedConfigurationManager;

@Mock
private RolePermissionManagementService mockedRolePermissionManagementService;
private MockedStatic<SCIMUserSchemaExtensionBuilder> scimUserSchemaExtensionBuilder;
Expand Down Expand Up @@ -1479,6 +1484,10 @@ public void testListUsersWithPost() throws Exception {
mockClaimMetadataManagementService, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
doReturn(usersGetResponse).when(scimUserManager)
.listUsersWithGET(any(), any(), any(), nullable(String.class), nullable(String.class), nullable(String.class), anyMap());
when(SCIMCommonComponentHolder.getConfigurationManager()).thenReturn(mockedConfigurationManager);
Resource resource = getResource();
when(mockedConfigurationManager.getResourceByTenantId( anyInt(), anyString(),
anyString() )).thenReturn(resource);
UsersGetResponse users = scimUserManager.listUsersWithPost(searchRequest, requiredAttributes);
assertEquals(users, usersGetResponse);
}
Expand Down Expand Up @@ -1685,4 +1694,23 @@ private org.wso2.carbon.user.core.common.Group buildUserCoreGroupResponse(String
group.setUserStoreDomain(domainName);
return group;
}

private List<org.wso2.carbon.identity.configuration.mgt.core.model.Attribute> getResourceAttribute() {

org.wso2.carbon.identity.configuration.mgt.core.model.Attribute attribute =
new org.wso2.carbon.identity.configuration.mgt.core.model.Attribute();
attribute.setKey("userResponseMaxLimit");
attribute.setValue("100");

List<org.wso2.carbon.identity.configuration.mgt.core.model.Attribute> attributes = new ArrayList<>();
attributes.add(attribute);
return attributes;
}

private Resource getResource() {
Resource resource = new Resource();
resource.setResourceName(MAX_LIMIT_RESOURCE_NAME);
resource.setAttributes(getResourceAttribute());
return resource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import static org.mockito.MockitoAnnotations.initMocks;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;

public class SCIMCommonUtilsTest {

Expand Down Expand Up @@ -267,4 +269,26 @@ public Object[][] tenantURLQualifyData() {
};
}

@DataProvider
public Object[][] getServerWideUserEndpointMaxLimitEnabledData() {
return new Object[][]{
{"", true},
{null, true},
{"true", true},
{"false", false},
};
}

@Test(dataProvider = "getServerWideUserEndpointMaxLimitEnabledData")
public void testIsConsiderServerWideUserEndpointMaxLimitEnabled(Object value, boolean isExpectedResultTrue) {

identityUtil.when(() -> IdentityUtil.getProperty(SCIMCommonConstants.CONSIDER_SERVER_WIDE_MAX_LIMIT_ENABLED))
.thenReturn(value);
if (isExpectedResultTrue) {
assertTrue(SCIMCommonUtils.isConsiderServerWideUserEndpointMaxLimitEnabled());
} else {
assertFalse(SCIMCommonUtils.isConsiderServerWideUserEndpointMaxLimitEnabled());
}

}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
<inbound.auth.oauth.version>6.5.3</inbound.auth.oauth.version>
<commons-collections.version>3.2.0.wso2v1</commons-collections.version>
<carbon.kernel.version>4.10.16</carbon.kernel.version>
<identity.framework.version>7.5.69</identity.framework.version>
<identity.framework.version>7.0.112</identity.framework.version>
<junit.version>4.13.1</junit.version>
<commons.lang.version>20030203.000129</commons.lang.version>
<identity.governance.version>1.8.12</identity.governance.version>
Expand Down

0 comments on commit 00317fb

Please sign in to comment.