01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.web.security;
23:
24: //$Id: AuthenticatorsExternalizationTestCase.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
25: 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: /**
33: * JBAS-2481: Externalization of Tomcat Authenticators
34: * @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
35: * @since Dec 1, 2005
36: */
37: public class AuthenticatorsExternalizationTestCase extends
38: JBossTestCase {
39: MBeanServerConnection server = null;
40: private String baseURLNoAuth = "http://" + getServerHost() + ":"
41: + Integer.getInteger("web.port", 8080) + "/";
42:
43: public AuthenticatorsExternalizationTestCase(String name) {
44: super (name);
45: }
46:
47: public void setUp() throws Exception {
48: this .serverFound();
49: this .deploy("auth-ext-header-web.war");
50: server = getServer();
51: assertNotNull("Obtained MBeanServerConnection?", server);
52: }
53:
54: public void tearDown() throws Exception {
55: if (server != null)
56: server = null;
57: this .undeploy("auth-ext-header-web.war");
58: }
59:
60: /**
61: * Test custom header based authentication
62: *
63: * @throws Exception
64: */
65: public void testHeaderBasedAuthentication() throws Exception {
66: String location = baseURLNoAuth + "header-auth/index.jsp";
67: int responseCode = 0;
68: HttpClient httpConn = new HttpClient();
69: GetMethod indexGet = null;
70: try {
71: indexGet = new GetMethod(location);
72: indexGet.setFollowRedirects(false);
73: responseCode = httpConn.executeMethod(indexGet);
74: assertEquals(HttpURLConnection.HTTP_FORBIDDEN, responseCode);
75: } finally {
76: indexGet.releaseConnection();
77: }
78: indexGet = null;
79: try {
80: indexGet = new GetMethod(location);
81: indexGet.setFollowRedirects(false);
82: //Add the request headers
83: indexGet.addRequestHeader("JBOSS_TEST_USER_NAME", "jduke");
84: indexGet.addRequestHeader("JBOSS_TEST_CREDENTIAL",
85: "theduke");
86: responseCode = httpConn.executeMethod(indexGet);
87: assertEquals(HttpURLConnection.HTTP_OK, responseCode);
88: } finally {
89: indexGet.releaseConnection();
90: }
91: }
92: }
|