|
24 | 24 | import jakarta.servlet.http.HttpServletRequest;
|
25 | 25 | import org.apache.commons.logging.Log;
|
26 | 26 | import org.apache.commons.logging.LogFactory;
|
| 27 | +import reactor.util.annotation.NonNull; |
27 | 28 |
|
| 29 | +import org.springframework.beans.factory.BeanNameAware; |
28 | 30 | import org.springframework.core.log.LogMessage;
|
29 | 31 | import org.springframework.security.web.util.matcher.RequestMatcher;
|
30 | 32 | import org.springframework.util.StringUtils;
|
|
36 | 38 | * @author Jinwoo Bae
|
37 | 39 | * @since 3.1
|
38 | 40 | */
|
39 |
| -public final class DefaultSecurityFilterChain implements SecurityFilterChain { |
| 41 | +public final class DefaultSecurityFilterChain implements SecurityFilterChain, BeanNameAware { |
40 | 42 |
|
41 | 43 | private static final Log logger = LogFactory.getLog(DefaultSecurityFilterChain.class);
|
42 | 44 |
|
43 | 45 | private final RequestMatcher requestMatcher;
|
44 | 46 |
|
45 | 47 | private final List<Filter> filters;
|
46 | 48 |
|
| 49 | + private String beanName; |
| 50 | + |
47 | 51 | public DefaultSecurityFilterChain(RequestMatcher requestMatcher, Filter... filters) {
|
48 | 52 | this(requestMatcher, Arrays.asList(filters));
|
49 | 53 | }
|
@@ -80,8 +84,24 @@ public boolean matches(HttpServletRequest request) {
|
80 | 84 |
|
81 | 85 | @Override
|
82 | 86 | public String toString() {
|
83 |
| - return this.getClass().getSimpleName() + " [RequestMatcher=" + this.requestMatcher + ", Filters=" + this.filters |
84 |
| - + "]"; |
| 87 | + List<String> filterNames = new ArrayList<>(); |
| 88 | + for (Filter filter : this.filters) { |
| 89 | + String name = filter.getClass().getSimpleName(); |
| 90 | + if (name.endsWith("Filter")) { |
| 91 | + name = name.substring(0, name.length() - "Filter".length()); |
| 92 | + } |
| 93 | + filterNames.add(name); |
| 94 | + } |
| 95 | + String declaration = this.getClass().getSimpleName(); |
| 96 | + if (this.beanName != null) { |
| 97 | + declaration += " defined as '" + this.beanName + "'"; |
| 98 | + } |
| 99 | + return declaration + " matching [" + this.requestMatcher + "] and having filters " + filterNames; |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public void setBeanName(@NonNull String name) { |
| 104 | + this.beanName = name; |
85 | 105 | }
|
86 | 106 |
|
87 | 107 | }
|
0 commit comments