Skip to content

Commit

Permalink
Add support to Idle Account Suspension API to return disabled and non…
Browse files Browse the repository at this point in the history
…-disabled users
  • Loading branch information
KaveeshaPiumini committed Jan 8, 2025
1 parent 55bf5a4 commit b7bf193
Show file tree
Hide file tree
Showing 14 changed files with 615 additions and 22 deletions.
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

0 comments on commit b7bf193

Please sign in to comment.