nerdexam
Oracle

1Z0-900 · Question #43

Given an HttpServletRequest request and an EJB SessionContext ctx. Which is a valid way to retrieve the Principal invoking either behavior?

The correct answer is A. request.getCallerPrincipal() and ctx.getCallerPrincipal(). There is an error in the provided answer key - D is actually correct, not A. HttpServletRequest exposes getUserPrincipal() (Servlet API), while SessionContext exposes getCallerPrincipal() (EJB API). These are two different APIs designed by different specs, which is exactly what…

Secure Java EE 7 Applications

Question

Given an HttpServletRequest request and an EJB SessionContext ctx. Which is a valid way to retrieve the Principal invoking either behavior?

Options

  • Arequest.getCallerPrincipal() and ctx.getCallerPrincipal()
  • Brequest.getUserPrincipal() and ctx.getUserPrincipal()
  • Crequest.getCallerPrincipal() and ctx.getUserPrincipal()
  • Drequest.getUserPrincipal() and ctx.getCallerPrincipal()

How the community answered

(33 responses)
  • A
    94% (31)
  • C
    3% (1)
  • D
    3% (1)

Explanation

There is an error in the provided answer key - D is actually correct, not A.

HttpServletRequest exposes getUserPrincipal() (Servlet API), while SessionContext exposes getCallerPrincipal() (EJB API). These are two different APIs designed by different specs, which is exactly what option D reflects: request.getUserPrincipal() and ctx.getCallerPrincipal().

Why the other options are wrong:

  • A is wrong because HttpServletRequest has no getCallerPrincipal() method - that method belongs to EJBContext only.
  • B is wrong because SessionContext has no getUserPrincipal() method - that belongs to the Servlet API only.
  • C mixes them the wrong way around: the getCallerPrincipal() call is incorrectly assigned to the request, and getUserPrincipal() to the context.

Memory tip: Think of EJBs as callers in a business-tier invocation chain (getCallerPrincipal), while HTTP requests come from users in a browser (getUserPrincipal). The naming reflects the layer: User → HTTP, Caller → EJB.

Note to you: The answer key provided marks A as correct, but this contradicts the Java EE specification. You may want to verify the source of this question, as it appears to contain a typo or error.

Topics

#Principal retrieval#EJB SessionContext#Servlet security#Caller identity

Community Discussion

No community discussion yet for this question.

Full 1Z0-900 Practice