Here is my servlet code

  | public class SSOFederationServer extends HttpServlet
  | {
  |     private static final String partner = "partner";
  |     private static final String token = "token";
  |     private static final String target = "target";    
  |     
  |     
  |     
  |     public void doPost(HttpServletRequest request,HttpServletResponse 
response)
  |     throws ServletException,IOException
  |     {  
  |         System.out.println("doPost was called......"); 
  |         this.doGet(request,response);
  |     }
  |     
  |     public void doGet(HttpServletRequest request,HttpServletResponse 
response)
  |     throws ServletException,IOException
  |     { 
  |         System.out.println("doGet was called......");
  |         System.out.println("----------------------------------");
  |         
System.out.println("Partner="+request.getParameter(SSOFederationServer.partner));
  |         
System.out.println("Token="+request.getParameter(SSOFederationServer.token));
  |         System.out.println("Token(Cookie)="+this.getToken(request));
  |         
System.out.println("Target="+request.getParameter(SSOFederationServer.target)); 
       
  |         System.out.println("----------------------------------");
  |         
  |         String partner = request.getParameter(SSOFederationServer.partner); 
//federation server of the cross-domain site                
  |         if(partner==null || partner.trim().length()==0)
  |         {
  |             //this is an RP request to process (relying party needs to 
process the cookie)
  |             //from a party that has already asserted the identity of the 
user
  |             String target = 
request.getParameter(SSOFederationServer.target);
  |             String token = request.getParameter(SSOFederationServer.token);
  |             
  |             //create the same cookie from the domain that the user is 
coming from into my domain
  |             if(token!=null && token.trim().length()>0)
  |             {                   
  |                 Cookie rpCookie = new 
Cookie(SSOFederationServer.token,token);
  |                 String domain = this.getDomain(target);
  |                 if(domain!=null && domain.trim().length()>0)
  |                 {
  |                     rpCookie.setDomain(domain);
  |                 }
  |                 rpCookie.setPath("/"); //make this a top-level cookie
  |                 response.addCookie(rpCookie);
  |             }
  |             
  |             response.sendRedirect(target);
  |         }
  |         else
  |         {
  |             //this is the asserting party, need to extract the token from 
this domain and forward to
  |             //the relying party federatioon server, the token will be 
transported to that domain                        
  |             String target = 
request.getParameter(SSOFederationServer.target); //resource in that domain 
being accessed
  |             String token = this.getToken(request);
  |             
  |             //create the url to re-direct to
  |             String url = partner + "?target=" + URLEncoder.encode(target);
  |             
  |             if(token!=null && token.trim().length()>0)
  |             {
  |                 url += "&token=" + URLEncoder.encode(token);
  |             }
  |             
  |             response.sendRedirect(url);
  |         }
  |     }
  |     
  |     private String getDomain(String target)
  |     {
  |         String domain = null;
  |         
  |         if(target.indexOf(".com")!=-1)
  |         {
  |             domain = ".jboss.com";
  |         }
  |         else if(target.indexOf(".org")!=-1)
  |         {
  |             domain = ".jboss.org";
  |         }
  |                     
  |         return domain;
  |     }
  |     
  |     private String getToken(HttpServletRequest request)
  |     {
  |         String token = null;
  |         Cookie[] cookies = request.getCookies();
  |         if(cookies!=null)
  |         {
  |             for(int i=0;i<cookies.length;i++)
  |             {
  |                 if(cookies.getName().equals(SSOFederationServer.token))
  |                 {
  |                     token = cookies.getValue();
  |                     break;
  |                 }
  |             }
  |         }            
  |         return token;
  |     }
  | }
  | 
  | 

and here is my JSP that has the form which submits form data to this servlet


  | <[EMAIL PROTECTED] contentType="text/html" language="java"%>
  | 
  | <html>
  | 
  | <head><title>JBoss SSO Demo Application</title></head>
  | 
  | <body>
  |     
  |     
<%=(String)request.getAttribute("message")%>(<%=request.getServerName()%>)<br/>
  |     <form name="form1" ACTION="/sso-federation" METHOD="post">
  |             <input type="hidden" name="partner" 
value="<%=(String)request.getAttribute("partner")%>"/><br/>
  |             <input type="hidden" name="target" 
value="<%=(String)request.getAttribute("target")%>"/><br/>
  |             <input type="submit"/>
  |     </form>
  | 
  | </body>
  | 
  | </html>
  | 

Only the doGet method of my servlet gets called. doPost never gets called even 
though form method is set to Post. 

The parameters partner and target are always null, when form method=post. If I 
make method=get, it works fine.


This is happening on Tomcat5.x (Tomcat5.0.8 and Tomcat5.5.12- standalone as 
well as Tomcat5 bundled with JBoss-4.0.3-SP1)

Everything works fine under Tomcat4.1.31.

OS- Windows XP Professional
JDK - Tried both 1.5.0_3 and 1.4.2_8

Thanks
Sohil

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3906939#3906939

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3906939


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to