Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with getRemoteUser()

 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you authenticating users?
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you aren't going to answer Ben's question, how can anyone help you?
 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I will give it a whirl!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic