Example usage for org.springframework.web.reactive.resource PathResourceResolver setAllowedLocations

List of usage examples for org.springframework.web.reactive.resource PathResourceResolver setAllowedLocations

Introduction

In this page you can find the example usage for org.springframework.web.reactive.resource PathResourceResolver setAllowedLocations.

Prototype

public void setAllowedLocations(@Nullable Resource... locations) 

Source Link

Document

By default when a Resource is found, the path of the resolved resource is compared to ensure it's under the input location where it was found.

Usage

From source file:org.springframework.web.reactive.resource.ResourceWebHandler.java

/**
 * Look for a {@code PathResourceResolver} among the configured resource
 * resolvers and set its {@code allowedLocations} property (if empty) to
 * match the {@link #setLocations locations} configured on this class.
 *//* w ww .  j a  v a 2 s. c  om*/
protected void initAllowedLocations() {
    if (CollectionUtils.isEmpty(this.locations)) {
        if (logger.isWarnEnabled()) {
            logger.warn("Locations list is empty. No resources will be served unless a "
                    + "custom ResourceResolver is configured as an alternative to PathResourceResolver.");
        }
        return;
    }
    for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
        if (getResourceResolvers().get(i) instanceof PathResourceResolver) {
            PathResourceResolver resolver = (PathResourceResolver) getResourceResolvers().get(i);
            if (ObjectUtils.isEmpty(resolver.getAllowedLocations())) {
                resolver.setAllowedLocations(getLocations().toArray(new Resource[getLocations().size()]));
            }
            break;
        }
    }
}