1 22 package org.jboss.test.web.security; 23 24 import java.net.HttpURLConnection ; 26 import javax.management.MBeanServerConnection ; 27 28 import org.apache.commons.httpclient.HttpClient; 29 import org.apache.commons.httpclient.methods.GetMethod; 30 import org.jboss.test.JBossTestCase; 31 32 37 public class AuthenticatorsExternalizationTestCase extends JBossTestCase 38 { 39 MBeanServerConnection server = null; 40 private String baseURLNoAuth = "http://" + getServerHost() + ":" + Integer.getInteger("web.port", 8080) + "/"; 41 42 43 public AuthenticatorsExternalizationTestCase(String name) 44 { 45 super(name); 46 } 47 48 public void setUp() throws Exception 49 { 50 this.serverFound(); 51 this.deploy("auth-ext-header-web.war"); 52 server = getServer(); 53 assertNotNull("Obtained MBeanServerConnection?", server); 54 } 55 56 public void tearDown() throws Exception 57 { 58 if(server != null) 59 server = null; 60 this.undeploy("auth-ext-header-web.war"); 61 } 62 63 68 public void testHeaderBasedAuthentication() throws Exception 69 { 70 String location = baseURLNoAuth+"header-auth/index.jsp"; 71 int responseCode = 0; 72 HttpClient httpConn = new HttpClient(); 73 GetMethod indexGet = null; 74 try 75 { 76 indexGet = new GetMethod(location); 77 indexGet.setFollowRedirects(false); 78 responseCode = httpConn.executeMethod(indexGet); 79 assertEquals(HttpURLConnection.HTTP_FORBIDDEN, responseCode ); 80 }finally 81 { 82 indexGet.releaseConnection(); 83 } 84 indexGet = null; 85 try 86 { 87 indexGet = new GetMethod(location); 88 indexGet.setFollowRedirects(false); 89 indexGet.addRequestHeader("JBOSS_TEST_USER_NAME", "jduke"); 91 indexGet.addRequestHeader("JBOSS_TEST_CREDENTIAL", "theduke"); 92 responseCode = httpConn.executeMethod(indexGet); 93 assertEquals(HttpURLConnection.HTTP_OK,responseCode); 94 }finally 95 { 96 indexGet.releaseConnection(); 97 } 98 } 99 } 100 | Popular Tags |