Solved

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

Posted on 2004-03-28
14
4,643 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
Industry Leaders: 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 50 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today’s effective marketing is about coming down to the customers’ level and engaging in a whole new way. A text message is one of the most effective and influential ways that you can engage your customers. Here are eight ways that you can utilize t…
Make the most of your online learning experience.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

687 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