This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Problems with getRemoteUser()  RSS feed

 
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);
%>
 
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!
 
Author and ninkuma
Marshal
Posts: 66783
168
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
Posts: 66783
168
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
Boost this thread!