Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Idle Account Suspension API to return disabled and non-disabled users #901

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/org.wso2.carbon.identity.governance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<groupId>org.apache.axis2.wso2</groupId>
<artifactId>axis2</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-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
Expand All @@ -24,6 +24,7 @@
import org.wso2.carbon.user.core.UserStoreManager;
import org.wso2.carbon.user.core.model.ExpressionCondition;

import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -128,6 +129,58 @@ List<String> getUserNamesMoreThanProvidedClaimValue(String claimURI, String clai
List<String> getUserNamesBetweenProvidedClaimValues(String claimURI, String startValue, String endValue,
int tenantId) throws IdentityException;

/**
* Get the list of usernames who have the claim value less than the provided claim value for a given claim URI
* and include or exclude the users with the boolean isIncluded
* based on the nested claim value for a given nested claim URI.
*
* @param claimURI Claim URI.
* @param claimValue Claim value.
* @param nestedClaimURI Nested claim URI.
* @param nestedClaimValue Nested claim value.
* @param tenantId Tenant ID.
* @param isIncluded Include or exclude the users based on the nested claim.
* @return List of usernames.
* @throws IdentityException Identity exception.
*/
default List<String> getUserNamesLessThanClaimWithNestedClaim(String claimURI,
String claimValue,
String nestedClaimURI,
String nestedClaimValue,
int tenantId,
boolean isIncluded)
throws IdentityException {

return Collections.emptyList();
}

/**
* Get the list of usernames who have the claim value between the provided claim values for a given claim URI
* and include or exclude the users with the boolean isIncluded
* based on the nested claim value for a given nested claim URI.
*
* @param claimURI Claim URI.
* @param startValue Start value.
* @param endValue End value.
* @param nestedClaimURI Nested claim URI.
* @param nestedClaimValue Nested claim value.
* @param tenantId Tenant ID.
* @param isIncluded Include or exclude the users based on the nested claim.
* @return List of usernames.
* @throws IdentityException Identity exception.
*/
default List<String> getUserNamesBetweenGivenClaimsWithNestedClaim(String claimURI,
String startValue,
String endValue,
String nestedClaimURI,
String nestedClaimValue,
int tenantId,
boolean isIncluded)
throws IdentityException {

return Collections.emptyList();
}

/**
* Check whether the identity data store is user store based.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
* Copyright (c) 2023-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
Expand Down Expand Up @@ -179,6 +179,31 @@ public List<String> getUserNamesBetweenProvidedClaimValues(String claimURI, Stri
return identityDataStore.getUserNamesBetweenProvidedClaimValues(claimURI, startValue, endValue, tenantId);
}

@Override
public List<String> getUserNamesLessThanClaimWithNestedClaim(String claimURI,
String claimValue,
String nestedClaimURI,
String nestedClaimValue,
int tenantId,
boolean isIncluded)
throws IdentityException {

return identityDataStore.getUserNamesLessThanClaimWithNestedClaim(claimURI, claimValue,
nestedClaimURI, nestedClaimValue, tenantId, isIncluded);
}

@Override
public List<String> getUserNamesBetweenGivenClaimsWithNestedClaim(String claimURI, String startValue,
String endValue,
String nestedClaimURI,
String nestedClaimValue, int tenantId,
boolean isIncluded)
throws IdentityException {

return identityDataStore.getUserNamesBetweenGivenClaimsWithNestedClaim(claimURI, startValue,
endValue, nestedClaimURI, nestedClaimValue, tenantId, isIncluded);
}

@Override
public boolean isUserStoreBasedIdentityDataStore() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2016-2025, WSO2 LLC. (http://www.wso2.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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
* 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.
* 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.governance.store;
Expand Down Expand Up @@ -463,6 +465,82 @@ public List<String> getUserNamesBetweenProvidedClaimValues(String claimURI, Str
}
}

@Override
public List<String> getUserNamesLessThanClaimWithNestedClaim(String claimURI, String claimValue,
String nestedClaimURI,
String nestedClaimValue, int tenantId,
boolean isIncluded)
throws IdentityException {

String sqlStmt = SQLQuery.FILTER_USERS_BY_DATA_KEY_LESS_THAN_DATA_VALUE;
String subSqlStmt = SQLQuery.LIST_USERS_FROM_CLAIM;
if (isIncluded) {
sqlStmt = sqlStmt + " AND USER_NAME IN (" + subSqlStmt + ")";
} else {
sqlStmt = sqlStmt + " AND USER_NAME NOT IN (" + subSqlStmt + ")";
}

List<String> userNames = new ArrayList<>();
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (PreparedStatement prepStmt = connection.prepareStatement(sqlStmt)) {
prepStmt.setString(1, claimURI);
prepStmt.setInt(2, tenantId);
prepStmt.setString(3, claimValue);
prepStmt.setString(4, nestedClaimURI);
prepStmt.setString(5, nestedClaimValue);
prepStmt.setInt(6, tenantId);
prepStmt.setString(7, "%");
try (ResultSet resultSet = prepStmt.executeQuery()) {
while (resultSet.next()) {
String username = resultSet.getString(1);
userNames.add(username);
}
}
return userNames;
}
} catch (SQLException e) {
throw new IdentityException("Error occurred while retrieving users from Identity Store.", e);
}
}

@Override
public List<String> getUserNamesBetweenGivenClaimsWithNestedClaim(String claimURI, String startValue,
String endValue,
String nestedClaimURI,
String nestedClaimValue, int tenantId,
boolean isIncluded)
throws IdentityException {

String sqlStmt = SQLQuery.FILTER_USERS_BY_DATA_KEY_LESS_THAN_AND_GREATER_THAN_DATA_VALUES;
String subSqlStmt = SQLQuery.LIST_USERS_FROM_CLAIM;
if (isIncluded) {
sqlStmt = sqlStmt + " AND USER_NAME IN (" + subSqlStmt + ")";
} else {
sqlStmt = sqlStmt + " AND USER_NAME NOT IN (" + subSqlStmt + ")";
}
List<String> userNames = new ArrayList<>();
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (PreparedStatement prepStmt = connection.prepareStatement(sqlStmt)) {
prepStmt.setString(1, claimURI);
prepStmt.setInt(2, tenantId);
prepStmt.setString(3, endValue);
prepStmt.setString(4, startValue);
prepStmt.setString(5, nestedClaimURI);
prepStmt.setString(6, nestedClaimValue);
prepStmt.setInt(7, tenantId);
prepStmt.setString(8, "%");
try (ResultSet resultSet = prepStmt.executeQuery()) {
while (resultSet.next()) {
String username = resultSet.getString(1);
userNames.add(username);
}
}
return userNames;
}
} catch (SQLException e) {
throw new IdentityException("Error occurred while retrieving users from Identity Store.", e);
}
}

private void populatePrepareStatement(SqlBuilder sqlBuilder, PreparedStatement prepStmt, int startIndex,
int endIndex) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2016-2025, WSO2 LLC. (http://www.wso2.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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
* 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.
* 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.governance.store;
Expand Down Expand Up @@ -161,4 +163,56 @@ public List<String> getUserNamesBetweenProvidedClaimValues(String claimURI, Stri
// Return an immutable empty list if subclasses do not have any overrides.
return Collections.emptyList();
}

/**
* Get the list of usernames who have the claim value less than the provided claim value for a given claim URI
* and include or exclude the users with the boolean isIncluded
* based on the nested claim value for a given nested claim URI.
*
* @param claimURI Claim URI.
* @param claimValue Claim value.
* @param nestedClaimURI Nested claim URI.
* @param nestedClaimValue Nested claim value.
* @param tenantId Tenant ID.
* @param isIncluded Include or exclude the users based on the nested claim.
* @return List of usernames.
* @throws IdentityException Identity exception.
*/
public List<String> getUserNamesLessThanClaimWithNestedClaim(String claimURI,
String claimValue,
String nestedClaimURI,
String nestedClaimValue,
int tenantId,
boolean isIncluded) throws IdentityException {

// Return an immutable empty list if subclasses do not have any overrides.
return Collections.emptyList();
}

/**
* Get the list of usernames who have the claim value between the provided claim values for a given claim URI
* and include or exclude the users with the boolean isIncluded
* based on the nested claim value for a given nested claim URI.
*
* @param claimURI Claim URI.
* @param startValue Start value.
* @param endValue End value.
* @param nestedClaimURI Nested claim URI.
* @param nestedClaimValue Nested claim value.
* @param tenantId Tenant ID.
* @param isIncluded Include or exclude the users based on the nested claim.
* @return List of usernames.
* @throws IdentityException Identity exception.
*/
public List<String> getUserNamesBetweenGivenClaimsWithNestedClaim(String claimURI,
String startValue,
String endValue,
String nestedClaimURI,
String nestedClaimValue,
int tenantId,
boolean isIncluded) throws IdentityException {

// Return an immutable empty list if subclasses do not have any overrides.
return Collections.emptyList();
}
}
Loading
Loading