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.web.server; 018 019import java.net.InetAddress; 020 021import org.springframework.boot.autoconfigure.web.ServerProperties; 022import org.springframework.boot.context.properties.ConfigurationProperties; 023import org.springframework.boot.context.properties.NestedConfigurationProperty; 024import org.springframework.boot.web.server.Ssl; 025import org.springframework.util.Assert; 026import org.springframework.util.StringUtils; 027 028/** 029 * Properties for the management server (e.g. port and path settings). 030 * 031 * @author Dave Syer 032 * @author Stephane Nicoll 033 * @author Vedran Pavic 034 * @since 2.0.0 035 * @see ServerProperties 036 */ 037@ConfigurationProperties(prefix = "management.server", ignoreUnknownFields = true) 038public class ManagementServerProperties { 039 040 /** 041 * Management endpoint HTTP port (uses the same port as the application by default). 042 * Configure a different port to use management-specific SSL. 043 */ 044 private Integer port; 045 046 /** 047 * Network address to which the management endpoints should bind. Requires a custom 048 * management.server.port. 049 */ 050 private InetAddress address; 051 052 private final Servlet servlet = new Servlet(); 053 054 @NestedConfigurationProperty 055 private Ssl ssl; 056 057 /** 058 * Returns the management port or {@code null} if the 059 * {@link ServerProperties#getPort() server port} should be used. 060 * @return the port 061 * @see #setPort(Integer) 062 */ 063 public Integer getPort() { 064 return this.port; 065 } 066 067 /** 068 * Sets the port of the management server, use {@code null} if the 069 * {@link ServerProperties#getPort() server port} should be used. To disable use 0. 070 * @param port the port 071 */ 072 public void setPort(Integer port) { 073 this.port = port; 074 } 075 076 public InetAddress getAddress() { 077 return this.address; 078 } 079 080 public void setAddress(InetAddress address) { 081 this.address = address; 082 } 083 084 public Ssl getSsl() { 085 return this.ssl; 086 } 087 088 public void setSsl(Ssl ssl) { 089 this.ssl = ssl; 090 } 091 092 public Servlet getServlet() { 093 return this.servlet; 094 } 095 096 /** 097 * Servlet properties. 098 */ 099 public static class Servlet { 100 101 /** 102 * Management endpoint context-path (for instance, `/management`). Requires a 103 * custom management.server.port. 104 */ 105 private String contextPath = ""; 106 107 /** 108 * Return the context path with no trailing slash (i.e. the '/' root context is 109 * represented as the empty string). 110 * @return the context path (no trailing slash) 111 */ 112 public String getContextPath() { 113 return this.contextPath; 114 } 115 116 public void setContextPath(String contextPath) { 117 Assert.notNull(contextPath, "ContextPath must not be null"); 118 this.contextPath = cleanContextPath(contextPath); 119 } 120 121 private String cleanContextPath(String contextPath) { 122 if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) { 123 return contextPath.substring(0, contextPath.length() - 1); 124 } 125 return contextPath; 126 } 127 128 } 129 130}