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

Enforce maximum operation count for scim2/Bulk API #400

Merged
merged 3 commits into from
Mar 4, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class ResponseCodeConstants {

public static final int CODE_PAYLOAD_TOO_LARGE = 413;
public static final String DESC_PAYLOAD_TOO_LARGE = "{\"maxOperations\": 1000,\"maxPayloadSize\": 1048576}";
public static final String ERROR_DESC_MAX_OPERATIONS_EXCEEDED = "The number of operations in the bulk " +
"request: %d exceeds the maximum total number of operations count: %d.";

public static final int CODE_INTERNAL_ERROR = 500;
public static final String DESC_INTERNAL_ERROR = "An internal error.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.charon3.core.config.CharonConfiguration;
import org.wso2.charon3.core.config.SCIMConfigConstants;
import org.wso2.charon3.core.encoder.JSONDecoder;
import org.wso2.charon3.core.encoder.JSONEncoder;
import org.wso2.charon3.core.exceptions.BadRequestException;
import org.wso2.charon3.core.exceptions.CharonException;
import org.wso2.charon3.core.exceptions.InternalErrorException;
import org.wso2.charon3.core.exceptions.PayloadTooLargeException;
import org.wso2.charon3.core.extensions.RoleManager;
import org.wso2.charon3.core.extensions.RoleV2Manager;
import org.wso2.charon3.core.extensions.UserManager;
Expand Down Expand Up @@ -80,6 +83,24 @@ public SCIMResponse processBulkData(String data, UserManager userManager) {
bulkRequestProcessor.setFailOnError(bulkRequestDataObject.getFailOnErrors());
bulkRequestProcessor.setUserManager(userManager);

int maxOperationCount =
PasinduYeshan marked this conversation as resolved.
Show resolved Hide resolved
(Integer) CharonConfiguration.getInstance().getConfig().get(SCIMConfigConstants.MAX_OPERATIONS);
int totalOperationCount = bulkRequestDataObject.getUserOperationRequests().size() +
bulkRequestDataObject.getGroupOperationRequests().size() +
bulkRequestDataObject.getRoleOperationRequests().size() +
bulkRequestDataObject.getRoleV2OperationRequests().size();
if (totalOperationCount > maxOperationCount) {
if (logger.isDebugEnabled()) {
logger.debug(String.format(ResponseCodeConstants.ERROR_DESC_MAX_OPERATIONS_EXCEEDED,
totalOperationCount,
maxOperationCount));
PasinduYeshan marked this conversation as resolved.
Show resolved Hide resolved
}
throw new PayloadTooLargeException(
String.format(ResponseCodeConstants.ERROR_DESC_MAX_OPERATIONS_EXCEEDED,
totalOperationCount,
maxOperationCount));
PasinduYeshan marked this conversation as resolved.
Show resolved Hide resolved
}

// Get bulk response data.
bulkResponseData = bulkRequestProcessor.processBulkRequests(bulkRequestDataObject);
//encode the BulkResponseData object
Expand All @@ -93,7 +114,7 @@ public SCIMResponse processBulkData(String data, UserManager userManager) {
// Create the final response.
return new SCIMResponse(ResponseCodeConstants.CODE_OK, finalEncodedResponse, responseHeaders);

} catch (CharonException | BadRequestException | InternalErrorException e) {
} catch (CharonException | BadRequestException | InternalErrorException | PayloadTooLargeException e) {
return AbstractResourceManager.encodeSCIMException(e);
}
}
Expand Down
Loading