Solved

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

Posted on 2004-03-28
14
4,442 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
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 95
jersey maven project error 7 142
reflection example 3 112
Multiple Images Upload [JSP Web-application] 3 42
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Riverbed Technology's webinar discusses networking for the cloud era with simplified SD-WAN cloud connectivity.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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