Skip to main content

ISecurityLoadingHandler Interface

Handles security violations that occur when the API loads a document or presentation.

Declaration

public interface ISecurityLoadingHandler

Remarks

The handleLimitExceeded() method handles violations of security loading limits. The handleOptionsViolation() method handles violations detected by security loading options.

The following code snippet configures loading options, handles security violations, and loads a presentation with the specified security settings. The example throws an exception if the presentation exceeds a configured limit or contains restricted content, and logs the violation to the console:

package presentation;

import com.devexpress.docs.office.*;
import com.devexpress.docs.presentation.*;

import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        // Create load options.
        LoadOptions loadOptions = new LoadOptions();

        // Configure security loading limits.
        PresentationSecurityLoadingLimits limits = new PresentationSecurityLoadingLimits();
        limits.setMaxFileSize(50L * 1024 * 1024);
        limits.setMaxSlideCount(100);
        limits.setMaxShapeCountPerSlide(500);

        loadOptions.setSecurityLoadingLimits(limits);

        // Configure security loading options.
        PresentationSecurityLoadingOptions securityLoadingOptionsOptions = new PresentationSecurityLoadingOptions();
        securityLoadingOptionsOptions.setRemoveMacros(true);
        securityLoadingOptionsOptions.setRemoveOleObjects(true);
        securityLoadingOptionsOptions.setRemoveActiveXContent(true);
        securityLoadingOptionsOptions.setRemoveCustomXMLParts(true);

        loadOptions.setSecurityLoadingOptions(securityLoadingOptionsOptions);

        // Handle security loading violations.
        loadOptions.setSecurityLoadingHandler(new ISecurityLoadingHandler() {
            @Override
            public SecurityLimitAction handleLimitExceeded(
                    SecurityLimitExceededParams parameters) {

                System.out.println("Security limit exceeded: " + parameters.getPropertyName());
                return SecurityLimitAction.THROW;
            }

            @Override
            public SecurityViolationAction handleOptionsViolation(
                    SecurityOptionsViolationParams parameters) {

                System.out.println("Security option violated: " + parameters.getPropertyName());
                return SecurityViolationAction.REMOVE;
            }
        });

        try(FileInputStream inputStream = new FileInputStream("Presentation.pptx");
            Presentation presentation = new Presentation(inputStream, loadOptions)) {

            //...
        }
    }
}

Refer to the following help topic for additional information: Secure Presentation Processing.

Methods

handleLimitExceeded(SecurityLimitExceededParams parameters) Method

Handles a security loading limit violation.

Declaration

public abstract SecurityLimitAction handleLimitExceeded(SecurityLimitExceededParams parameters)

Parameters

Name Type Description
parameters SecurityLimitExceededParams

Contains information about the security loading limit violation.

Returns

Type Description
SecurityLimitAction

An action that specifies whether to continue or stop loading the document.

handleOptionsViolation(SecurityOptionsViolationParams parameters) Method

Handles a security loading options violation.

Declaration

public abstract SecurityViolationAction handleOptionsViolation(SecurityOptionsViolationParams parameters)

Parameters

Name Type Description
parameters SecurityOptionsViolationParams

Contains information about the security loading options violation.

Returns

Type Description
SecurityViolationAction

An action that specifies whether to continue or stop loading the document.