KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > web > security > AuthenticatorsExternalizationTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 41836 2006-03-07 05:43:36Z asaldhana $
25
import java.net.HttpURLConnection JavaDoc;
26 import javax.management.MBeanServerConnection JavaDoc;
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 JBossTestCase
38 {
39    MBeanServerConnection JavaDoc server = null;
40    private String JavaDoc baseURLNoAuth = "http://" + getServerHost() + ":" + Integer.getInteger("web.port", 8080) + "/";
41    
42    
43    public AuthenticatorsExternalizationTestCase(String JavaDoc name)
44    {
45       super(name);
46    }
47    
48    public void setUp() throws Exception JavaDoc
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 JavaDoc
57    {
58       if(server != null)
59          server = null;
60       this.undeploy("auth-ext-header-web.war");
61    }
62    
63    /**
64     * Test custom header based authentication
65     *
66     * @throws Exception
67     */

68    public void testHeaderBasedAuthentication() throws Exception JavaDoc
69    {
70       String JavaDoc 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          //Add the request headers
90
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