CSSLP · Question #32
Which of the following methods determines the principle name of the current user and returns the jav
The correct answer is A. security.Principal object in the HttpServletRequest interface?. The getUserPrincipal() method in the HttpServletRequest interface determines the principal name of the current user and returns a java.security.Principal object.
Question
Which of the following methods determines the principle name of the current user and returns the jav
Options
- Asecurity.Principal object in the HttpServletRequest interface?
- BgetUserPrincipal()
- CisUserInRole()
- DgetRemoteUser()
- EgetCallerPrincipal()
How the community answered
(41 responses)- A88% (36)
- B2% (1)
- D7% (3)
- E2% (1)
Why each option
The getUserPrincipal() method in the HttpServletRequest interface determines the principal name of the current user and returns a java.security.Principal object.
The `getUserPrincipal()` method of the `HttpServletRequest` interface is specifically designed to retrieve the `java.security.Principal` object representing the current authenticated user, allowing access to the user's name and other principal information.
`isUserInRole()` checks if the authenticated user belongs to a specific security role, returning a boolean, not the principal object itself.
`getRemoteUser()` returns the login name of the authenticated user as a `String`, not a `java.security.Principal` object.
`getCallerPrincipal()` is typically used in EJB containers to get the identity of the caller performing the method invocation, not directly from the `HttpServletRequest`.
Concept tested: Java Servlet security - User authentication
Source: https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletRequest.html
Topics
Community Discussion
No community discussion yet for this question.