001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.server.management; 018 019/** 020 * Deny-by-default exposure settings for the diagnostic dump endpoints ({@code /threaddump}, {@code /heapdump}). 021 * 022 * <p> 023 * Both dumps are <b>off by default</b> on security grounds — a thread dump can leak sensitive state and a 024 * heap dump can be large and contain secrets. A consumer opts in <i>explicitly</i> by registering a 025 * {@code DumpsSettings} bean (built with {@link Builder#enableThreadDump()} / {@link Builder#enableHeapDump()}) 026 * in the resource's bean store. When no such bean is present, {@link DumpsManager} resolves the default 027 * (both disabled) and the endpoints respond {@code 403 Forbidden}. 028 * 029 * <h5 class='section'>See Also:</h5><ul> 030 * <li class='jc'>{@link DumpsManager} 031 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/ManagementSurface">Management Surface (Actuator-style endpoints)</a> 032 * </ul> 033 * 034 * @since 10.0.0 035 */ 036public class DumpsSettings { 037 038 /** The default (deny-all) settings used when no bean is registered. */ 039 public static final DumpsSettings DEFAULT = create().build(); 040 041 private final boolean threadDumpEnabled; 042 private final boolean heapDumpEnabled; 043 044 private DumpsSettings(Builder b) { 045 this.threadDumpEnabled = b.threadDumpEnabled; 046 this.heapDumpEnabled = b.heapDumpEnabled; 047 } 048 049 /** 050 * Builder creator. 051 * 052 * @return A new builder (both dumps disabled). 053 */ 054 public static Builder create() { 055 return new Builder(); 056 } 057 058 /** 059 * @return <jk>true</jk> if the {@code /threaddump} endpoint is enabled. 060 */ 061 public boolean isThreadDumpEnabled() { 062 return threadDumpEnabled; 063 } 064 065 /** 066 * @return <jk>true</jk> if the {@code /heapdump} endpoint is enabled. 067 */ 068 public boolean isHeapDumpEnabled() { 069 return heapDumpEnabled; 070 } 071 072 /** 073 * Builder for {@link DumpsSettings}. 074 */ 075 public static class Builder { 076 private boolean threadDumpEnabled; 077 private boolean heapDumpEnabled; 078 079 /** 080 * Enables the {@code /threaddump} endpoint. 081 * 082 * @return This object. 083 */ 084 public Builder enableThreadDump() { 085 threadDumpEnabled = true; 086 return this; 087 } 088 089 /** 090 * Enables the {@code /heapdump} endpoint. 091 * 092 * @return This object. 093 */ 094 public Builder enableHeapDump() { 095 heapDumpEnabled = true; 096 return this; 097 } 098 099 /** 100 * Builds the settings. 101 * 102 * @return A new {@link DumpsSettings}. 103 */ 104 public DumpsSettings build() { 105 return new DumpsSettings(this); 106 } 107 } 108}