aspose file tools*
The moose likes JSP and the fly likes Problems with getRemoteUser() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problems with getRemoteUser()" Watch "Problems with getRemoteUser()" New topic
Author

Problems with getRemoteUser()

m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
Hi,
I am trying to get the windows userid from the user when the go to my jsp. I have tried getRemoteUser but I keep getting null. Any sugestions/ideas? Here is my jsp code:

<%@ page import="java.util.*,java.sql.*, java.io.*, java.text.*, javax.servlet.http.*, javax.servlet" %>

<%
String userid=request.getRemoteUser();
out.println(userid);
%>
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

How are you authenticating users?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
I have written a servlet:


import java.io.*;
import java.security.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Snoop extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();

out.println("<HTML><HEAD><TITLE>AuthenticationSnoop</TITLE></HEAD><BODY>");
out.println("<H1>UserID</H1>");
out.println("<PRE>");
out.println("User Name: " + req.getRemoteUser());
String name = (req.getUserPrincipal() == null) ?
null : req.getUserPrincipal().getName();
out.println("Principal Name: " + name);
out.println("Authentication Type: " + req.getAuthType());
out.println("</PRE>");
out.println("</BODY></HTML>");
}
}

Am I missing something here?
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
Can anyone look at my servlet and tell me what I a might be missing? I continue to get "null" for my output.
Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

If you aren't going to answer Ben's question, how can anyone help you?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
I am not sure what you mean...I am trying to get the windows userid, since it is an intranet the windows userid would already be authenticated, do I have to do this a second time in my servlet?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

The point is that getRemoteUser will return the userid of the browser-authenticated user. It has nothing to do with the Windows (or any other OS) login.
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
Okay, so if someone is logged into the company intranet and they click on my jsp they have to be authenticated again?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes, if you want to use getRemoteUser()

Take a look at the documentation for JNDI resources:
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html

I know it's also possible (but I've never done it) via JNDI to use windows authentication with Tomcat.
Google would be more help than I would for that.
m brymer
Ranch Hand

Joined: Jan 04, 2005
Posts: 64
Thanks, I will give it a whirl!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problems with getRemoteUser()