user1924104
user1924104

Reputation: 901

Using a username through out the app

I have started a new thread, as the old one went off course from the original question,

i have a login page, validating against our LDAP server, and where as before i would have the user enter a username to determine where there data is stored by the code :

@Override
    public String getName() {
        return getId();
    }

but i would like to replace the getName() bit with the username the user has already entered from the login page, and so far i have gotten confused with the options, is there a simple way of achieving this ?

Upvotes: 0

Views: 53

Answers (1)

kolossus
kolossus

Reputation: 20691

Those answers seem pretty clear, to me anyway .There are two main options to retrieve the authenticated username (the user must have been previously authenticated by your app server against some database or LDAP or the methods returns null)

  1. getRemoteUser()

  2. getUserPrincipal()

both methods are available by default on the HttpServletRequest object associated with your context. How you want to obtain the object is now a different matter.

Within a JSF Web application

  1. the first line of this question provides a way to retrieve the request object within your backing bean.

2.The answer to your previous question provides the #{request.userName} EL to retrieve the username directly from the HttpServletRequest into your JSF view.

Upvotes: 1

Related Questions