0

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 ?

user1924104
  • 891
  • 2
  • 16
  • 38
  • Your question is incomplete, if the answers from the other question didn't sort you out. Do you intend for `getName()` to retrieve the supplied username from the login form OR do you want to simply retrieve the name of a user who has already been authenticated by another piece of code within your application? – kolossus Jan 21 '13 at 23:48
  • `getName()`was used to get a username from a input text box, and then return the getId(); what i am trying to do now is get the username from a login page i have created, that authenticates the user via our LDAP server, and then returns this string as getId(); – user1924104 Jan 22 '13 at 14:30

1 Answers1

1

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.

Community
  • 1
  • 1
kolossus
  • 20,559
  • 3
  • 52
  • 104