File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed
appsec/src/test/groovy/com/datadog/appsec/user
instrumentation/spring-security-5/src/main/java/datadog/trace/instrumentation/springsecurity5
internal-api/src/main/java/datadog/trace/api/appsec Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -268,6 +268,15 @@ class AppSecEventTrackerSpecification extends DDSpecification {
268268 thrown(BlockingException)
269269 }
270270
271+ void ' should not fail on null callback' () {
272+ when:
273+ tracker.onUserEvent(UserIdCollectionMode.IDENTIFICATION, ' test- user' )
274+
275+ then:
276+ noExceptionThrown()
277+ provider.getCallback(EVENTS.user()) >> null
278+ }
279+
271280 private static class ActionFlow<T> implements Flow<T> {
272281
273282 private Action action
Original file line number Diff line number Diff line change 11package datadog .trace .instrumentation .springsecurity5 ;
22
33import java .util .function .Supplier ;
4+ import org .slf4j .Logger ;
5+ import org .slf4j .LoggerFactory ;
46import org .springframework .security .core .context .SecurityContext ;
57
68public class AppSecDeferredContext implements Supplier <SecurityContext > {
79
10+ private static final Logger LOGGER = LoggerFactory .getLogger (AppSecDeferredContext .class );
11+
812 private final Supplier <SecurityContext > delegate ;
913
1014 public AppSecDeferredContext (final Supplier <SecurityContext > delegate ) {
@@ -15,7 +19,11 @@ public AppSecDeferredContext(final Supplier<SecurityContext> delegate) {
1519 public SecurityContext get () {
1620 SecurityContext context = delegate .get ();
1721 if (context != null ) {
18- SpringSecurityUserEventDecorator .DECORATE .onUser (context .getAuthentication ());
22+ try {
23+ SpringSecurityUserEventDecorator .DECORATE .onUser (context .getAuthentication ());
24+ } catch (Throwable e ) {
25+ LOGGER .debug ("Error handling user event" , e );
26+ }
1927 }
2028 return context ;
2129 }
Original file line number Diff line number Diff line change @@ -142,6 +142,9 @@ private <T> void dispatch(
142142 return ;
143143 }
144144 final T callback = cbp .getCallback (event );
145+ if (callback == null ) {
146+ return ;
147+ }
145148 final Flow <Void > flow = consumer .apply (ctx , callback );
146149 if (flow == null ) {
147150 return ;
You can’t perform that action at this time.
0 commit comments