Java EE 7 Application Developer — Question 4
Given an HttpServletRequest request and an EJB SessionContext ctx.
Which is a valid way to retrieve the Principal invoking either behavior?
Answer options
- A. request.getCallerPrincipal() and ctx.getCallerPrincipal()
- B. request.getUserPrincipal() and ctx.getUserPrincipal()
- C. request.getCallerPrincipal() and ctx.getUserPrincipal()
- D. request.getUserPrincipal() and ctx.getCallerPrincipal()
Correct answer: A
Explanation
The correct answer is A because request.getCallerPrincipal() and ctx.getCallerPrincipal() are both valid methods to retrieve the invoking Principal in their respective contexts. Options B, C, and D are incorrect as they either use methods that aren't appropriate for retrieving the invoking Principal or mix the correct methods in a way that doesn't provide the intended result.