or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

access-control.mdauthentication.mdcsrf.mdfilter-chain.mdfirewall.mdindex.mdreactive.mdsecurity-context.mdsession-management.mdutilities.md

reactive.mddocs/

0

# Reactive Web Security

1

2

Spring Security Web provides reactive programming support for WebFlux applications with non-blocking security filters and handlers that integrate with Project Reactor.

3

4

## Core Reactive Components

5

6

```java { .api }

7

public interface SecurityWebFilterChain {

8

boolean matches(ServerWebExchange exchange);

9

Flux<WebFilter> getWebFilters();

10

}

11

12

public class WebFilterChainProxy implements WebFilter {

13

public WebFilterChainProxy(List<SecurityWebFilterChain> filters);

14

public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain);

15

public void setFirewall(ServerHttpFirewall firewall);

16

}

17

18

public interface ServerAuthenticationEntryPoint {

19

Mono<Void> commence(ServerWebExchange exchange, AuthenticationException ex);

20

}

21

22

public interface ServerRedirectStrategy {

23

Mono<Void> sendRedirect(ServerWebExchange exchange, URI location);

24

}

25

26

public class DefaultServerRedirectStrategy implements ServerRedirectStrategy {

27

public void setStatusCode(HttpStatus statusCode);

28

public Mono<Void> sendRedirect(ServerWebExchange exchange, URI location);

29

}

30

```

31

32

## Reactive Authentication Converters

33

34

```java { .api }

35

public class ServerFormLoginAuthenticationConverter implements Function<ServerWebExchange, Mono<Authentication>> {

36

public void setUsernameParameter(String usernameParameter);

37

public void setPasswordParameter(String passwordParameter);

38

public Mono<Authentication> apply(ServerWebExchange exchange);

39

}

40

41

public class ServerHttpBasicAuthenticationConverter implements Function<ServerWebExchange, Mono<Authentication>> {

42

public Mono<Authentication> apply(ServerWebExchange exchange);

43

}

44

```

45

46

## Usage Examples

47

48

```java

49

// Reactive filter chain

50

List<WebFilter> filters = Arrays.asList(

51

new ServerFormLoginAuthenticationWebFilter(authenticationManager),

52

new AuthorizationWebFilter(authorizationManager)

53

);

54

55

SecurityWebFilterChain chain = new MatcherSecurityWebFilterChain(

56

ServerWebExchangeMatchers.anyExchange(),

57

filters

58

);

59

60

WebFilterChainProxy proxy = new WebFilterChainProxy(Arrays.asList(chain));

61

62

// Reactive authentication

63

ServerFormLoginAuthenticationConverter converter = new ServerFormLoginAuthenticationConverter();

64

converter.setUsernameParameter("email");

65

converter.setPasswordParameter("password");

66

```