37
37
import org .apache .commons .logging .LogFactory ;
38
38
39
39
import org .springframework .core .log .LogMessage ;
40
- import org .springframework .security .web .util .UrlUtils ;
41
40
42
41
/**
43
- * A {@link org.springframework.security.web.server. FilterChainProxy.FilterChainDecorator}
44
- * that wraps the chain in before and after observations
42
+ * A {@link org.springframework.security.web.FilterChainProxy.FilterChainDecorator} that
43
+ * wraps the chain in before and after observations
45
44
*
46
45
* @author Josh Cummings
47
46
* @since 6.0
@@ -75,14 +74,16 @@ public FilterChain decorate(FilterChain original, List<Filter> filters) {
75
74
private FilterChain wrapSecured (FilterChain original ) {
76
75
return (req , res ) -> {
77
76
AroundFilterObservation parent = observation ((HttpServletRequest ) req );
78
- Observation observation = Observation .createNotStarted (SECURED_OBSERVATION_NAME , this .registry );
77
+ Observation observation = Observation .createNotStarted (SECURED_OBSERVATION_NAME , this .registry )
78
+ .contextualName ("secured request" );
79
79
parent .wrap (FilterObservation .create (observation ).wrap (original )).doFilter (req , res );
80
80
};
81
81
}
82
82
83
83
private FilterChain wrapUnsecured (FilterChain original ) {
84
84
return (req , res ) -> {
85
- Observation observation = Observation .createNotStarted (UNSECURED_OBSERVATION_NAME , this .registry );
85
+ Observation observation = Observation .createNotStarted (UNSECURED_OBSERVATION_NAME , this .registry )
86
+ .contextualName ("unsecured request" );
86
87
FilterObservation .create (observation ).wrap (original ).doFilter (req , res );
87
88
};
88
89
}
@@ -189,8 +190,8 @@ private void wrapFilter(ServletRequest request, ServletResponse response, Filter
189
190
}
190
191
191
192
private AroundFilterObservation parent (HttpServletRequest request ) {
192
- FilterChainObservationContext beforeContext = FilterChainObservationContext .before (request );
193
- FilterChainObservationContext afterContext = FilterChainObservationContext .after (request );
193
+ FilterChainObservationContext beforeContext = FilterChainObservationContext .before ();
194
+ FilterChainObservationContext afterContext = FilterChainObservationContext .after ();
194
195
Observation before = Observation .createNotStarted (this .convention , () -> beforeContext , this .registry );
195
196
Observation after = Observation .createNotStarted (this .convention , () -> afterContext , this .registry );
196
197
AroundFilterObservation parent = AroundFilterObservation .create (before , after );
@@ -409,8 +410,6 @@ public FilterChain wrap(FilterChain chain) {
409
410
410
411
static final class FilterChainObservationContext extends Observation .Context {
411
412
412
- private final ServletRequest request ;
413
-
414
413
private final String filterSection ;
415
414
416
415
private String filterName ;
@@ -419,29 +418,17 @@ static final class FilterChainObservationContext extends Observation.Context {
419
418
420
419
private int chainSize ;
421
420
422
- private FilterChainObservationContext (ServletRequest request , String filterSection ) {
421
+ private FilterChainObservationContext (String filterSection ) {
423
422
this .filterSection = filterSection ;
424
- this .request = request ;
425
- }
426
-
427
- static FilterChainObservationContext before (ServletRequest request ) {
428
- return new FilterChainObservationContext (request , "before" );
429
- }
430
-
431
- static FilterChainObservationContext after (ServletRequest request ) {
432
- return new FilterChainObservationContext (request , "after" );
423
+ setContextualName ("security filterchain " + filterSection );
433
424
}
434
425
435
- @ Override
436
- public void setName (String name ) {
437
- super .setName (name );
438
- if (name != null ) {
439
- setContextualName (name + "." + this .filterSection );
440
- }
426
+ static FilterChainObservationContext before () {
427
+ return new FilterChainObservationContext ("before" );
441
428
}
442
429
443
- String getRequestLine () {
444
- return requestLine (( HttpServletRequest ) this . request );
430
+ static FilterChainObservationContext after () {
431
+ return new FilterChainObservationContext ( "after" );
445
432
}
446
433
447
434
String getFilterSection () {
@@ -472,32 +459,31 @@ void setChainSize(int chainSize) {
472
459
this .chainSize = chainSize ;
473
460
}
474
461
475
- private static String requestLine (HttpServletRequest request ) {
476
- return request .getMethod () + " " + UrlUtils .buildRequestUrl (request );
477
- }
478
-
479
462
}
480
463
481
464
static final class FilterChainObservationConvention
482
465
implements ObservationConvention <FilterChainObservationContext > {
483
466
484
- static final String CHAIN_OBSERVATION_NAME = "spring.security.http.chains" ;
485
-
486
- private static final String REQUEST_LINE_NAME = "request.line" ;
467
+ static final String CHAIN_OBSERVATION_NAME = "spring.security.filterchains" ;
487
468
488
- private static final String CHAIN_POSITION_NAME = "chain .position" ;
469
+ private static final String CHAIN_POSITION_NAME = "spring.security.filterchain .position" ;
489
470
490
- private static final String CHAIN_SIZE_NAME = "chain .size" ;
471
+ private static final String CHAIN_SIZE_NAME = "spring.security.filterchain .size" ;
491
472
492
- private static final String FILTER_SECTION_NAME = "filter.section" ;
473
+ private static final String FILTER_SECTION_NAME = "security.security.reached. filter.section" ;
493
474
494
- private static final String FILTER_NAME = "current .filter.name" ;
475
+ private static final String FILTER_NAME = "spring.security.reached .filter.name" ;
495
476
496
477
@ Override
497
478
public String getName () {
498
479
return CHAIN_OBSERVATION_NAME ;
499
480
}
500
481
482
+ @ Override
483
+ public String getContextualName (FilterChainObservationContext context ) {
484
+ return "security filterchain " + context .getFilterSection ();
485
+ }
486
+
501
487
@ Override
502
488
public KeyValues getLowCardinalityKeyValues (FilterChainObservationContext context ) {
503
489
KeyValues kv = KeyValues .of (CHAIN_SIZE_NAME , String .valueOf (context .getChainSize ()))
@@ -509,12 +495,6 @@ public KeyValues getLowCardinalityKeyValues(FilterChainObservationContext contex
509
495
return kv ;
510
496
}
511
497
512
- @ Override
513
- public KeyValues getHighCardinalityKeyValues (FilterChainObservationContext context ) {
514
- String requestLine = context .getRequestLine ();
515
- return KeyValues .of (REQUEST_LINE_NAME , requestLine );
516
- }
517
-
518
498
@ Override
519
499
public boolean supportsContext (Observation .Context context ) {
520
500
return context instanceof FilterChainObservationContext ;
0 commit comments