So programming servlet i made:
public class CustReq extends HttpServletRequestWrapper{
public CustReq(HttpServletRequest request) {
super(request);
}
@Override
public String getHeader(String name) {
if ("UserID".equalsIgnoreCase(name)) {
return "myuser";
}
return super.getHeader(name);
}
}
And then used in a Filter method:
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
CustReq wrapp = new CustReq((HttpServletRequest)arg0);
arg2.doFilter(wrapp, arg1);
}
And finally bound filter to RedirectorServlet which has following code in doGet():
ServletContext context =
getServletContext().getContext("/Workspace_cust/Main.html");
RequestDispatcher rd = context.getRequestDispatcher("/Main.html");
rd.include(req, res);
Then I integrated this classes to Workspace_cust.ear, modifying web.xml and adding .class files.
Now when I navigate with my browser to ../Workspace_cust/RedirectorServlet I get redirected to Main.html as I should be, but there is still login screen! I tested SSO using FF modify headers plugin and also by making servlet like this in doGet:
PrintWriter out = res.getWriter();
out.println("Userid header is " +req.getHeader("UserID"));
And I get the Correct values!
So please help me how do I set/add http headers in Java Servlet.
Thank you in advance