19
19
import java .util .ArrayList ;
20
20
import java .util .List ;
21
21
22
+ import io .micrometer .observation .ObservationRegistry ;
22
23
import jakarta .servlet .ServletRequest ;
23
24
import org .w3c .dom .Element ;
24
25
@@ -106,6 +107,8 @@ class HttpConfigurationBuilder {
106
107
107
108
private static final String ATT_INVALID_SESSION_URL = "invalid-session-url" ;
108
109
110
+ private static final String ATT_OBSERVATION_REGISTRY_REF = "observation-registry-ref" ;
111
+
109
112
private static final String ATT_SESSION_AUTH_STRATEGY_REF = "session-authentication-strategy-ref" ;
110
113
111
114
private static final String ATT_SESSION_AUTH_ERROR_URL = "session-authentication-error-url" ;
@@ -211,7 +214,7 @@ class HttpConfigurationBuilder {
211
214
private boolean addAllAuth ;
212
215
213
216
HttpConfigurationBuilder (Element element , boolean addAllAuth , ParserContext pc , BeanReference portMapper ,
214
- BeanReference portResolver , BeanReference authenticationManager ) {
217
+ BeanReference portResolver , BeanReference authenticationManager , BeanMetadataElement observationRegistry ) {
215
218
this .httpElt = element ;
216
219
this .addAllAuth = addAllAuth ;
217
220
this .pc = pc ;
@@ -226,7 +229,7 @@ class HttpConfigurationBuilder {
226
229
createSecurityContextHolderStrategy ();
227
230
createForceEagerSessionCreationFilter ();
228
231
createDisableEncodeUrlFilter ();
229
- createCsrfFilter ();
232
+ createCsrfFilter (observationRegistry );
230
233
createSecurityPersistence ();
231
234
createSessionManagementFilters ();
232
235
createWebAsyncManagerFilter ();
@@ -812,9 +815,10 @@ private void createDisableEncodeUrlFilter() {
812
815
}
813
816
}
814
817
815
- private void createCsrfFilter () {
818
+ private void createCsrfFilter (BeanMetadataElement observationRegistry ) {
816
819
Element elmt = DomUtils .getChildElementByTagName (this .httpElt , Elements .CSRF );
817
820
this .csrfParser = new CsrfBeanDefinitionParser ();
821
+ this .csrfParser .setObservationRegistry (observationRegistry );
818
822
this .csrfFilter = this .csrfParser .parse (elmt , this .pc );
819
823
if (this .csrfFilter == null ) {
820
824
this .csrfParser = null ;
@@ -897,6 +901,14 @@ List<OrderDecorator> getFilters() {
897
901
return filters ;
898
902
}
899
903
904
+ private static BeanMetadataElement getObservationRegistry (Element httpElmt ) {
905
+ String holderStrategyRef = httpElmt .getAttribute (ATT_OBSERVATION_REGISTRY_REF );
906
+ if (StringUtils .hasText (holderStrategyRef )) {
907
+ return new RuntimeBeanReference (holderStrategyRef );
908
+ }
909
+ return BeanDefinitionBuilder .rootBeanDefinition (ObservationRegistryFactory .class ).getBeanDefinition ();
910
+ }
911
+
900
912
static class RoleVoterBeanFactory extends AbstractGrantedAuthorityDefaultsBeanFactory {
901
913
902
914
private RoleVoter voter = new RoleVoter ();
@@ -944,4 +956,18 @@ public Class<?> getObjectType() {
944
956
945
957
}
946
958
959
+ static class ObservationRegistryFactory implements FactoryBean <ObservationRegistry > {
960
+
961
+ @ Override
962
+ public ObservationRegistry getObject () throws Exception {
963
+ return ObservationRegistry .NOOP ;
964
+ }
965
+
966
+ @ Override
967
+ public Class <?> getObjectType () {
968
+ return ObservationRegistry .class ;
969
+ }
970
+
971
+ }
972
+
947
973
}
0 commit comments