Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-03-28
14
Medium Priority
?
4,959 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

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!

Question has a verified solution.

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

Sometimes Administrators rights are not enough. These cases call for the SYSTEM account. The process in this article outlines the steps required to execute commands using the SYSTEM account.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

636 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