Uploaded image for project: 'EJB 3.0'
  1. EJB 3.0
  2. EJBTHREE-1667

Same stateless EJB's context used from one call to another

    XMLWordPrintable

Details

    • Workaround Exists
    • Hide

      The following works for me, but I can not guarantee it is the best way:

      private String getCallerName() {
      String caller = null;
      SecurityContext context = SecurityContextAssociation.getSecurityContext();
      if (context != null) {
      SubjectInfo subjectInfo = context.getSubjectInfo();
      if (subjectInfo != null) {
      CredentialIdentity<?> cIdentity = subjectInfo.getIdentity(CredentialIdentity.class);
      if (cIdentity != null) {
      Principal principal = cIdentity.asPrincipal();
      if (principal != null)

      { caller = principal.getName(); }

      }
      }
      }
      return caller;
      }

      Show
      The following works for me, but I can not guarantee it is the best way: private String getCallerName() { String caller = null; SecurityContext context = SecurityContextAssociation.getSecurityContext(); if (context != null) { SubjectInfo subjectInfo = context.getSubjectInfo(); if (subjectInfo != null) { CredentialIdentity<?> cIdentity = subjectInfo.getIdentity(CredentialIdentity.class); if (cIdentity != null) { Principal principal = cIdentity.asPrincipal(); if (principal != null) { caller = principal.getName(); } } } } return caller; }

    Description

      1) I have Stateless EJBs with the EJBContext defined as a @Resource and a method getting the caller's name:
      public class MyBean {
      @Resource
      private SessionContext ejbSession = null;

      private String getCallerName()

      { return this.ejbSession.getCallerPrincipal().getName(); }

      }

      2) My client always always calls in authenticated mode

      3) I execute my client once and everything goes fine

      4) I execute it other times, but there, one in a while, I don't get my authenticated user but the one from a preious call.

      I tracked that it was sometimes the same "EJBContextImpl" object from one call to the other. The first call to "getCallerPrincipal()" is cached, so when I use the same object the second time, it does not look for it but returns the value from a previous call.

      Attachments

        Activity

          People

            Unassigned Unassigned
            pantolomin_jira John Gonon (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 1 day
                1d
                Remaining:
                Remaining Estimate - 1 day
                1d
                Logged:
                Time Spent - Not Specified
                Not Specified