*/
public void testPostDataFormAuth() throws Exception
{
log.info("+++ testPostDataFormAuth");
// Start by accessing the secured index.html of war1
HttpClient httpConn = new HttpClient();
GetMethod indexGet = new GetMethod(baseURLNoAuth+"form-auth/unsecure_form.html");
int responseCode = httpConn.executeMethod(indexGet);
assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
// Submit the form to /restricted/SecuredPostServlet
PostMethod servletPost = new PostMethod(baseURLNoAuth+"form-auth/restricted/SecuredPostServlet");
servletPost.addParameter("checkParam", "123456");
responseCode = httpConn.executeMethod(servletPost);
String body = servletPost.getResponseBodyAsString();
assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
assertTrue("Redirected to login page", body.indexOf("j_security_check") > 0 );
HttpState state = httpConn.getState();
Cookie[] cookies = state.getCookies();
String sessionID = null;
for(int c = 0; c < cookies.length; c ++)
{
Cookie k = cookies[c];
if( k.getName().equalsIgnoreCase("JSESSIONID") )
sessionID = k.getValue();
}
getLog().debug("Saw JSESSIONID="+sessionID);
// Submit the login form
PostMethod formPost = new PostMethod(baseURLNoAuth+"form-auth/j_security_check");
formPost.addRequestHeader("Referer", baseURLNoAuth+"form-auth/unsecure_form.html");
formPost.addParameter("j_username", "jduke");
formPost.addParameter("j_password", "theduke");
responseCode = httpConn.executeMethod(formPost.getHostConfiguration(),
formPost, state);
String response = formPost.getStatusText();
getLog().debug("responseCode="+responseCode+", response="+response);
assertTrue("Saw HTTP_MOVED_TEMP", responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
// Follow the redirect to the SecureServlet
Header location = formPost.getResponseHeader("Location");
String indexURI = location.getValue();
GetMethod war1Index = new GetMethod(indexURI);
responseCode = httpConn.executeMethod(war1Index.getHostConfiguration(),
war1Index, state);
assertTrue("Get OK", responseCode == HttpURLConnection.HTTP_OK);
body = war1Index.getResponseBodyAsString();
if( body.indexOf("j_security_check") > 0 )
fail("get of "+indexURI+" redirected to login page");