How to get user's login info?
I know this is probably a Java question rather than JSF, but I suspect someone here has probably ran into this before.
I have an application that requires me to grab the user's login information -
in particular their login name, and check that against a database.
I then need to do some verificaion or require the user to create a new account.
How do I access the user's login information?
[423 byte] By [
burferda] at [2007-11-27 2:21:19]

# 1
Just let the user login by a form.
# 2
This is how I'm doing it using Websphere Portal 6, not sure if it's the same for you:HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();String userId = request.getUserPrincipal().toString()
# 3
Hi,This will give you the User log into the systemFacesContext fc = FacesContext.getCurrentInstance();HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();String userId = request.getRemoteUser();
# 4
This is true if he is using HTTP based authentication.
# 5
Is getRemoteUser() preferred over what I am using getUserPrincipal()? What's the difference?
# 6
Is there any way to test either of these methods within a development environment?I get 'null' when I use either method inside Java Studio Creator IDE.It's kind of hard to develop a login procedure without being able to test in a development environment.
# 7
With Studio Creator:
- Create a page "Login" (Creator creates a JSP ("Login.jsp") and a page bean which is a java source file "Login.java").
- In design view drop a Text Field, a Password Field and a Button from the palette on the page.
- Doubleclick the button. (Creator creates an action method in the page bean.)
- Write
String username = (String) this.textField1.getText();
String password = (String) this.passwordField1.getText();
(You can use a binding too instead of manipulating the component instances directly.)
- Set a breakpoint to the first line.
- Press F5 or choose Run - Debug Main Project.
# 8
The object is not to create a login page.The object is to get the user's login id from the system so I can use it in the application.
# 9
In doing a bit of searching, I ran into System.getProperties() that seems to be able to get things like user.name.
Not sure if this will get the user name of the person accessing from a client side or if it is the username of the owner of the application on the server.
Can anyone shed light on this?
Also, what needs to be set in the 'server.policy' file?
I granted 'AllPermission' in order to do some testing, but I know there has to be a more limited permission that will do the job. I just don't kow what it is.
# 10
I found the permission that is needed.java.util.PropertyPermmission
# 11
Which login info exactly do you need then? The local (operating system) login name? Or do you want a HTTP based authentication? Or just a form based authentication?
# 12
Basically, this is how it needs to work.
The application will be on a server on our corporate network.
Users login to the network with their usernames and passwords.
When the user brings this web application up in their browsers, I need
to be able to identify the username of the user.
I then need to check the database to see if that user has registered for the application.
If not, then I present the user with a screen to create an account associated with the application.
If the user is registed, then he can login into the application.
# 13
In Windows and Linux you can use System.getProperty("user.name") to retrieve the logged in username for the operating system. I am not sure about other operating systems tho.
# 14
That's what I was going to try. It seems to work in my test environment.
# 15
The getProperty("user.name") returns the user Id of the application running on the server (in this case, Administrator) . I need a mechanism to return the remote user who is running the application from a client.
# 16
In this case, you cannot. Consider form or http based authentication.
# 17
Not sure what you mean by 'form' authentication.I need to be able to associate the login user with the application.How do you do http authentication?
# 18
Form based: let the user register and choose an username/password to login with. Just create some simple forms and eventually add a Filter.
HTTP based: generally you define usernames/passwords yourself. The user will retrieve a browser default login popup when he access the restricted pages.
Another solution to crawl in the clients system is to use a signed applet instead of a webapp.
I recommend just form based authentication though. Less effort after all.