These two seem to be doing the same things. Can anyone explain the main difference between the two? When would you use one vs the other?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
Principalrepresents someone who could potentially authenticate with your application. The Principal’s name depends on the authentication method used:getRemoteUser()returns “the login of the user” which, in the case of HTTP Basic authentication, will also be the username; it doesn’t map cleanly in the X.509 client certificate case though, since the user doesn’t enter a “login” as such – in the example above, we could use the Distinguished Name or simply the CN, “bob”.The Javadocs state that “whether the user name is sent with each subsequent request depends on the browser and type of authentication”, suggesting that
getRemoteUser()was originally meant to provide data only for requests in which a username was entered. This, however, would result in it returningnullfor the majority of requests when cookie-based auth is in use – not too helpful!In reality,
getRemoteUser()often just callsgetUserPrincipal().getName(); verified in Tomcat 6 and Jetty 6/7.