?
Solved

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

Posted on 2004-03-28
14
Medium Priority
?
4,761 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 6

Expert Comment

by:jarasa
ID: 10702593
<%=System.getProperty("REMOTE_USER")%>
0
 

Author Comment

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

Expert Comment

by:jarasa
ID: 10702680
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

Expert Comment

by:jarasa
ID: 10702744
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
ID: 10702795
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
ID: 10702835
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
 

Author Comment

by:javantis
ID: 10702883
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
ID: 10702927
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 150 total points
ID: 10703219
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
ID: 10704061
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
ID: 10704572
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
ID: 10705631
>> 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
ID: 23775718
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

771 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