code: @Override
      public void postInvoke(EJBRequestData request, SecurityCookieImpl preInvokeResult) throws EJBAccessDeniedException {
          if (preInvokeResult != null) {
              JaccService js = jaccService.getService();
              if (js != null) {
                  js.resetPolicyContextHandlerInfo();
              }
              SecurityCookieImpl securityCookie = preInvokeResult;
              Subject invocationSubject = subjectManager.getInvocationSubject();
              Subject callerSubject = subjectManager.getCallerSubject();
              // A unit test might set either invocationSubject or callerSubject as null.
              if ((invocationSubject == null || invocationSubject.equals(securityCookie.getAdjustedInvokedSubject())) &&
                  (callerSubject == null || callerSubject.equals(securityCookie.getAdjustedReceivedSubject()))) {
                  // if invocation and caller subject are unchanged, this means that a programmatic authentication
                  // was not carried out, thus put the original subject back.
                  // otherwise, keep the current subjects in order to preserve the subjects from the programmatic login.
                  Subject invokedSubject = securityCookie.getInvokedSubject();
                  Subject receivedSubject = securityCookie.getReceivedSubject();
  
                  subjectManager.setCallerSubject(receivedSubject);
                  subjectManager.setInvocationSubject(invokedSubject);
              } else {
                  if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                      Tr.debug(tc, "Subjects have been changed, preserving the current Subjects.");
                  }
              }
          }
      }
docs: {@inheritDoc}