Solved

Tomcat + how to get the user name of a client machine?

Posted on 2004-03-28
14
4,213 Views
Last Modified: 2012-05-04
Hi,

my webapp is running on a Tomcat 4.1.29 Server. On the login page I want to display the windows user name of the client. <%=System.getProperty("user.name")%> only displays the name of the machine where tomcat has been installed. how do I get the windows user name of the clients machine? thx,

Dirk
0
Comment
Question by:javantis
14 Comments
 
LVL 6

Expert Comment

by:jarasa
Comment Utility
<%=System.getProperty("REMOTE_USER")%>
0
 

Author Comment

by:javantis
Comment Utility
<%=System.getProperty("REMOTE_USER")%> is not working.
0
 
LVL 6

Expert Comment

by:jarasa
Comment Utility
Sorry, is not a System Var.

Try request.getRemoteUser();

http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-CGI-Variables.html

Javier
0
 

Author Comment

by:javantis
Comment Utility
I already tried request.getRemoteUser();. It does not work either..
0
 
LVL 6

Expert Comment

by:jarasa
Comment Utility
Create a JSP with this and try it:

Maybe you get it as Not Specified

<%

    String[][] variables =
      { { "AUTH_TYPE", request.getAuthType() },
        { "CONTENT_LENGTH", String.valueOf(request.getContentLength()) },
        { "CONTENT_TYPE", request.getContentType() },
        { "DOCUMENT_ROOT", getServletContext().getRealPath("/") },
        { "PATH_INFO", request.getPathInfo() },
        { "PATH_TRANSLATED", request.getPathTranslated() },
        { "QUERY_STRING", request.getQueryString() },
        { "REMOTE_ADDR", request.getRemoteAddr() },
        { "REMOTE_HOST", request.getRemoteHost() },
        { "REMOTE_USER", request.getRemoteUser() },
        { "REQUEST_METHOD", request.getMethod() },
        { "SCRIPT_NAME", request.getServletPath() },
        { "SERVER_NAME", request.getServerName() },
        { "SERVER_PORT", String.valueOf(request.getServerPort()) },
        { "SERVER_PROTOCOL", request.getProtocol() },
        { "SERVER_SOFTWARE", getServletContext().getServerInfo() }
      };
    String title = "Servlet Example: Showing CGI Variables";
    out.println("<BODY BGCOLOR=\"#FDF5E6\">\n" +
                "<H1 ALIGN=CENTER>" + title + "</H1>\n" +
                "<TABLE BORDER=1 ALIGN=CENTER>\n" +
                "<TR BGCOLOR=\"#FFAD00\">\n" +
                "<TH>CGI Variable Name<TH>Value");
    for(int i=0; i<variables.length; i++) {
      String varName = variables[i][0];
      String varValue = variables[i][1];
      if (varValue == null)
        varValue = "<I>Not specified</I>";
      out.println("<TR><TD>" + varName + "<TD>" + varValue);
    }
    out.println("</TABLE></BODY></HTML>");


%>
0
 

Author Comment

by:javantis
Comment Utility
ok I just ran it. I get a 'Not specified' value for getRemoteUser(). So what do I have to do?
0
 
LVL 6

Expert Comment

by:jarasa
Comment Utility
Well that means the the user has not been authenticated, you must protect the page so tomcat shows the authentication login, if you are using your own authentication method won't work.

From JavaDoc:
getRemoteUser() -> Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.

Javier
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:javantis
Comment Utility
hm. how to authenticate a user before she submits her username? There must be some other way. When the login.jsp is called I just want to filled the textfield 'username' with the windows user name of the client machine. There should not be any authentication process at this time.
0
 
LVL 6

Expert Comment

by:jarasa
Comment Utility
Well I'm not sure if that can be done with Java maybe with JavaScript but let me check it and I'll let you know.

Javier
0
 
LVL 6

Accepted Solution

by:
jarasa earned 50 total points
Comment Utility
Hi again.

This will do it for you but is VBScript, won't work out of windows. besides if you're not using Win2000 or XP you must install this:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&familyid=0a8a18f6-249c-4a72-bfcf-fc6af26dc390

Javier

<html>
<head>
<title>Login</title>
</head>
<body>
<form name=Form1 action="login.jsp">
USER: <input type=text value="" name="USER">
PASSWORD: <input type=password value="" name="PASSWORD">
<input type=submit name="LOG ON">
<script language="VbScript">
Dim X
set X = createobject("WSCRIPT.Network")
dim U
U=x.UserName
Form1.USER.value=U
</script>
</form>
</body>
</html>
0
 

Author Comment

by:javantis
Comment Utility
thanks for your afford. but i am not allowed to use vbscript for security reasons. though, javascript would have been an issue, but java is the preferred way. I have no clue what to do next. Have not thought this would be that difficult, so the problem is still unsolved. Maybe I coould set an authentication header and send it with the request for the login.jsp?!
0
 
LVL 6

Expert Comment

by:jarasa
Comment Utility
Well if you can use ASP the you may do this:

Function GetUserName()
    Dim domainAndUser
    Dim loginUser
    Dim user

    loginUser = Request.ServerVariables("LOGON_USER")
    domainAndUser = Split(loginUser, "\")
    If IsArray(domainAndUser) Then
        GetUserName = domainAndUser(UBound(domainAndUser))
    Else
        GetUserName = loginUser
    End If
End Function

Thats why we hate Bill Gates :c)

Javier
0
 
LVL 14

Expert Comment

by:kennethxu
Comment Utility
>> On the login page I want to display the windows user name of the client.
as Javier has already mentioned, you can use VBScript.

Just to confirm that you CANNOT do it with java and/or javascript. because of security issue.

don't accept mine as answer, Javier's should if you would.
0
 

Expert Comment

by:nyu2n
Comment Utility
hi
I know this is an old thread
but I really need help on this thing too
I cannot user vbscript
I only can use jsp and java
is there any possible way to do that ?
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now