001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.actuate.autoconfigure.endpoint.web;
018
019import java.util.LinkedHashMap;
020import java.util.LinkedHashSet;
021import java.util.Map;
022import java.util.Set;
023
024import org.springframework.boot.context.properties.ConfigurationProperties;
025import org.springframework.util.Assert;
026import org.springframework.util.StringUtils;
027
028/**
029 * Configuration properties for web management endpoints.
030 *
031 * @author Madhura Bhave
032 * @author Phillip Webb
033 * @since 2.0.0
034 */
035@ConfigurationProperties(prefix = "management.endpoints.web")
036public class WebEndpointProperties {
037
038        private final Exposure exposure = new Exposure();
039
040        /**
041         * Base path for Web endpoints. Relative to server.servlet.context-path or
042         * management.server.servlet.context-path if management.server.port is configured.
043         */
044        private String basePath = "/actuator";
045
046        /**
047         * Mapping between endpoint IDs and the path that should expose them.
048         */
049        private final Map<String, String> pathMapping = new LinkedHashMap<>();
050
051        public Exposure getExposure() {
052                return this.exposure;
053        }
054
055        public String getBasePath() {
056                return this.basePath;
057        }
058
059        public void setBasePath(String basePath) {
060                Assert.isTrue(basePath.isEmpty() || basePath.startsWith("/"),
061                                "Base path must start with '/' or be empty");
062                this.basePath = cleanBasePath(basePath);
063        }
064
065        private String cleanBasePath(String basePath) {
066                if (StringUtils.hasText(basePath) && basePath.endsWith("/")) {
067                        return basePath.substring(0, basePath.length() - 1);
068                }
069                return basePath;
070        }
071
072        public Map<String, String> getPathMapping() {
073                return this.pathMapping;
074        }
075
076        public static class Exposure {
077
078                /**
079                 * Endpoint IDs that should be included or '*' for all.
080                 */
081                private Set<String> include = new LinkedHashSet<>();
082
083                /**
084                 * Endpoint IDs that should be excluded or '*' for all.
085                 */
086                private Set<String> exclude = new LinkedHashSet<>();
087
088                public Set<String> getInclude() {
089                        return this.include;
090                }
091
092                public void setInclude(Set<String> include) {
093                        this.include = include;
094                }
095
096                public Set<String> getExclude() {
097                        return this.exclude;
098                }
099
100                public void setExclude(Set<String> exclude) {
101                        this.exclude = exclude;
102                }
103
104        }
105
106}