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

utilities.mddocs/

0

# Request Matching and Utilities

1

2

Spring Security Web provides flexible request matching capabilities and utility classes for URL manipulation, text escaping, and security operations.

3

4

## Request Matching

5

6

```java { .api }

7

public interface RequestMatcher {

8

boolean matches(HttpServletRequest request);

9

default MatchResult matcher(HttpServletRequest request);

10

}

11

12

public class AntPathRequestMatcher implements RequestMatcher {

13

public AntPathRequestMatcher(String pattern);

14

public AntPathRequestMatcher(String pattern, String httpMethod);

15

public boolean matches(HttpServletRequest request);

16

}

17

18

public class RegexRequestMatcher implements RequestMatcher {

19

public RegexRequestMatcher(String pattern, String httpMethod);

20

public boolean matches(HttpServletRequest request);

21

}

22

23

public class OrRequestMatcher implements RequestMatcher {

24

public OrRequestMatcher(RequestMatcher... requestMatchers);

25

public boolean matches(HttpServletRequest request);

26

}

27

28

public class AndRequestMatcher implements RequestMatcher {

29

public AndRequestMatcher(RequestMatcher... requestMatchers);

30

public boolean matches(HttpServletRequest request);

31

}

32

33

public class NegatedRequestMatcher implements RequestMatcher {

34

public NegatedRequestMatcher(RequestMatcher requestMatcher);

35

public boolean matches(HttpServletRequest request);

36

}

37

38

public class RequestHeaderRequestMatcher implements RequestMatcher {

39

public RequestHeaderRequestMatcher(String expectedHeaderName);

40

public RequestHeaderRequestMatcher(String expectedHeaderName, String expectedHeaderValue);

41

public boolean matches(HttpServletRequest request);

42

}

43

44

public class IpAddressMatcher implements RequestMatcher {

45

public IpAddressMatcher(String ipAddress);

46

public boolean matches(HttpServletRequest request);

47

public boolean matches(String address);

48

}

49

50

public class MediaTypeRequestMatcher implements RequestMatcher {

51

public MediaTypeRequestMatcher(MediaType mediaType);

52

public MediaTypeRequestMatcher(MediaType... mediaTypes);

53

public void setIgnoredMediaTypes(Set<MediaType> ignoredMediaTypes);

54

public boolean matches(HttpServletRequest request);

55

}

56

57

public class ELRequestMatcher implements RequestMatcher {

58

public ELRequestMatcher(String el);

59

public boolean matches(HttpServletRequest request);

60

}

61

```

62

63

## Utility Classes

64

65

```java { .api }

66

public final class UrlUtils {

67

public static String buildRequestUrl(HttpServletRequest request);

68

public static String buildFullRequestUrl(HttpServletRequest request);

69

public static boolean isAbsoluteUrl(String url);

70

}

71

72

public class RedirectUrlBuilder {

73

public String getUrl();

74

public RedirectUrlBuilder setScheme(String scheme);

75

public RedirectUrlBuilder setServerName(String serverName);

76

public RedirectUrlBuilder setPort(int port);

77

public RedirectUrlBuilder setContextPath(String contextPath);

78

public RedirectUrlBuilder setServletPath(String servletPath);

79

public RedirectUrlBuilder setPathInfo(String pathInfo);

80

public RedirectUrlBuilder setQuery(String query);

81

}

82

83

public final class TextEscapeUtils {

84

public static String escapeEntities(String s);

85

}

86

87

public class ThrowableAnalyzer {

88

public Throwable[] determineCauseChain(Throwable throwable);

89

public <T extends Throwable> T getFirstThrowableOfType(Class<T> type, Throwable[] chain);

90

public void registerExtractor(Class<? extends Throwable> throwableType, ThrowableCauseExtractor extractor);

91

}

92

93

public interface ThrowableCauseExtractor {

94

Throwable extractCause(Throwable throwable);

95

}

96

97

public class OnCommittedResponseWrapper extends HttpServletResponseWrapper {

98

protected OnCommittedResponseWrapper(HttpServletResponse response);

99

protected void onResponseCommitted();

100

public void setContentLength(int len);

101

public void setContentLengthLong(long len);

102

public void setContentType(String type);

103

public void setDateHeader(String name, long date);

104

public void addDateHeader(String name, long date);

105

public void setHeader(String name, String value);

106

public void addHeader(String name, String value);

107

public void setIntHeader(String name, int value);

108

public void addIntHeader(String name, int value);

109

}

110

```

111

112

## Usage Examples

113

114

```java

115

// Path matching

116

RequestMatcher apiMatcher = new AntPathRequestMatcher("/api/**");

117

RequestMatcher adminMatcher = new AntPathRequestMatcher("/admin/**", "GET");

118

119

// Combined matching

120

RequestMatcher publicMatcher = new OrRequestMatcher(

121

new AntPathRequestMatcher("/public/**"),

122

new AntPathRequestMatcher("/css/**"),

123

new AntPathRequestMatcher("/js/**")

124

);

125

126

// URL building

127

String requestUrl = UrlUtils.buildRequestUrl(request);

128

boolean isAbsolute = UrlUtils.isAbsoluteUrl("https://example.com/path");

129

```