@Override public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall( ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) { ServerCall.Listener<ReqT> delegate = next.startCall(call, headers); return new SimpleForwardingServerCallListener<ReqT>(delegate) { @Override public void onComplete() { try { super.onComplete(); } finally { SecurityContextHolder.clearContext(); log.debug("SecurityContextHolder now cleared, as request processing completed"); } } @Override public void onCancel() { try { super.onCancel(); } finally { SecurityContextHolder.clearContext(); log.debug("SecurityContextHolder now cleared, as request processing was canceled"); } } }; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); forwarder = new SimpleForwardingServerCallListener<Void>(serverCallListener) {}; }