Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ requirements or investigating individual historic traffic issues.
Logbook is ready to use out of the box for most common setups. Even for uncommon applications and technologies, it should be simple to implement the necessary interfaces to connect a
library/framework/etc. to it.

**Contents:**
<!-- toc -->
- [Features](#features)
- [Dependencies](#dependencies)
* [Jackson Version Support](#jackson-version-support)
- [Installation](#installation)
- [Usage](#usage)
* [Strategy](#strategy)
* [Attribute Extractor](#attribute-extractor)
* [Phases](#phases)
* [Servlet](#servlet)
* [HTTP Client](#http-client)
* [HTTP Client 5](#http-client-5)
* [JAX-RS 3.x (aka Jakarta RESTful Web Services)](#jax-rs-3x-aka-jakarta-restful-web-services)
* [JDK HTTP Server](#jdk-http-server)
* [Netty](#netty)
* [OkHttp v2.x](#okhttp-v2x)
* [OkHttp v3.x](#okhttp-v3x)
* [Ktor](#ktor)
* [Spring](#spring)
* [Spring Boot Starter](#spring-boot-starter)
* [logstash-logback-encoder](#logstash-logback-encoder)
- [Known Issues](#known-issues)
- [Getting Help with Logbook](#getting-help-with-logbook)
- [Getting Involved/Contributing](#getting-involvedcontributing)
- [Alternatives](#alternatives)
- [Credits and References](#credits-and-references)
<!-- tocstop -->
**Contents:**

<!-- toc -->

- [Features](#features)
- [Dependencies](#dependencies)
* [Jackson Version Support](#jackson-version-support)
- [Installation](#installation)
- [Usage](#usage)
* [Strategy](#strategy)
* [Attribute Extractor](#attribute-extractor)
* [Phases](#phases)
* [Servlet](#servlet)
* [HTTP Client](#http-client)
* [HTTP Client 5](#http-client-5)
* [JAX-RS 3.x (aka Jakarta RESTful Web Services)](#jax-rs-3x-aka-jakarta-restful-web-services)
* [JDK HTTP Server](#jdk-http-server)
* [Netty](#netty)
* [OkHttp v2.x](#okhttp-v2x)
* [OkHttp v3.x](#okhttp-v3x)
* [Ktor](#ktor)
* [Spring](#spring)
* [Spring Boot Starter](#spring-boot-starter)
* [logstash-logback-encoder](#logstash-logback-encoder)
- [Known Issues](#known-issues)
- [Getting Help with Logbook](#getting-help-with-logbook)
- [Getting Involved/Contributing](#getting-involvedcontributing)
- [Alternatives](#alternatives)
- [Credits and References](#credits-and-references)

<!-- tocstop -->

## Features

- **Logging**: of HTTP requests and responses, including the body; partial logging (no body) for unauthorized requests
Expand Down Expand Up @@ -1089,7 +1089,7 @@ The `logbook-spring` module contains a `ClientHttpRequestInterceptor` to use wit
Logbook comes with a convenient auto configuration for Spring Boot users. It sets up all of the following parts automatically with sensible defaults:

- Servlet filter
- Second Servlet filter for unauthorized requests (if Spring Security is detected)
- Second Servlet filter for unauthorized requests (if a `SecurityFilterChain` bean is present)
- Header-/Parameter-/Body-Filters
- HTTP-/JSON-style formatter
- Logging writer
Expand Down Expand Up @@ -1178,7 +1178,7 @@ The following tables show the available configuration (sorted alphabetically):
| `logbook.reactive.server-mode` | Selects the reactive server integration: `netty` or `web-filter` (see [Spring WebFlux](#spring-webflux)) | `netty` |
| `logbook.server.predicate.include` | Include only certain paths and methods for incoming requests (if defined) | `[]` |
| `logbook.server.predicate.exclude` | Exclude certain paths and methods for incoming requests (overrides `logbook.server.predicate.include`) | `[]` |
| `logbook.secure-filter.enabled` | Enable the [`SecureLogbookFilter`](#servlet) | `true` |
| `logbook.secure-filter.enabled` | Enable the [`SecureLogbookFilter`](#security). Only registered when a `SecurityFilterChain` bean exists. Requires all 401/403 responses to be produced by a filter between the two Logbook filters; set to `false` if authorization failures are handled in the dispatcher (e.g. permit-all chains with method security) | `true` |
| `logbook.strategy` | [Strategy](#strategy) (`default`, `status-at-least`, `body-only-if-status-at-least`, `without-body`) | `default` |
| `logbook.write.chunk-size` | Splits log lines into smaller chunks of size up-to `chunk-size`. | `0` (disabled) |
| `logbook.write.status-code-based` | Enables status-code-aware log levels. Responses with 2xx/3xx are logged at `TRACE`, 4xx at `WARN`, 5xx at `ERROR`. Requests are always logged at `TRACE`. | `false` |
Expand Down Expand Up @@ -1319,4 +1319,4 @@ more details, check the [contribution guidelines](.github/CONTRIBUTING.md).
![Creative Commons (Attribution-Share Alike 3.0 Unported](https://licensebuttons.net/l/by-sa/3.0/80x15.png)
[*Grand Turk, a replica of a three-masted 6th rate frigate from Nelson's days - logbook and charts*](https://commons.wikimedia.org/wiki/File:Grand_Turk(34).jpg)
by [JoJan](https://commons.wikimedia.org/wiki/User:JoJan) is licensed under a
[Creative Commons (Attribution-Share Alike 3.0 Unported)](http://creativecommons.org/licenses/by-sa/3.0/).
[Creative Commons (Attribution-Share Alike 3.0 Unported)](http://creativecommons.org/licenses/by-sa/3.0/).
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ static class JakartaSecurityServletFilterConfiguration {
private static final String FILTER_NAME = "secureLogbookFilter";

@Bean
@ConditionalOnBean(SecurityFilterChain.class)
@ConditionalOnProperty(name = "logbook.secure-filter.enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean(name = FILTER_NAME)
public FilterRegistrationBean<?> secureLogbookFilter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"name": "logbook.secure-filter.enabled",
"type": "java.lang.Boolean",
"defaultValue": true,
"description": "Enables/disables security servlet filter support."
"description": "Enables/disables the SecureLogbookFilter. Only takes effect when a SecurityFilterChain bean is present. The two-filter setup requires all 401/403 responses to be produced by a filter between secureLogbookFilter and logbookFilter; apps that return 401/403 from the dispatcher (e.g. permit-all chains with method security or @ControllerAdvice) must set this to false."
},
{
"name": "logbook.reactive.server-mode",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
package org.zalando.logbook.autoconfigure;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.security.web.SecurityFilterChain;
import org.zalando.logbook.Logbook;
import org.zalando.logbook.servlet.AsyncOnCompleteListenerWrapper;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

@LogbookTest
class SecurityFilterTest {

@Autowired
@Qualifier("secureLogbookFilter")
private FilterRegistrationBean secureLogbookFilter;
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withUserConfiguration(LogbookAutoConfiguration.JakartaSecurityServletFilterConfiguration.class)
.withBean(AsyncOnCompleteListenerWrapper.class, AsyncOnCompleteListenerWrapper::identity);

@Autowired
@Qualifier("logbookFilter")
private FilterRegistrationBean logbookFilter;
@Test
void shouldRegisterSecureLogbookFilterWhenSecurityFilterChainIsPresent() {
contextRunner
.withBean("logbook", Logbook.class, Logbook::create)
.withBean("securityFilterChain", SecurityFilterChain.class, () -> mock(SecurityFilterChain.class))
.run(context -> assertThat(context).hasBean("secureLogbookFilter"));
}

@Test
void shouldInitializeFilters() {
assertThat(secureLogbookFilter).isNotNull();
assertThat(logbookFilter).isNotNull();
void shouldNotRegisterSecureLogbookFilterWithoutSecurityFilterChain() {
contextRunner
.withBean("logbook", Logbook.class, Logbook::create)
.run(context -> assertThat(context).doesNotHaveBean("secureLogbookFilter"));
}

}