001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.security.test;
023:
024: import java.net.HttpURLConnection;
025: import java.net.URL;
026:
027: import javax.security.auth.login.Configuration;
028:
029: import junit.extensions.TestSetup;
030: import junit.framework.Test;
031: import junit.framework.TestSuite;
032:
033: import org.jboss.security.auth.login.XMLLoginConfigImpl;
034: import org.jboss.test.JBossTestSetup;
035: import org.jboss.test.util.web.HttpUtils;
036:
037: //$Id: CustomSecurityManagerTestCase.java 60917 2007-02-26 18:10:13Z anil.saldhana@jboss.com $
038:
039: /**
040: * JBAS-2703 : Create a AuthenticationManager/AuthorizationManager
041: * plugin testcase
042: *
043: * This testcase overrides test methods from EJBSpecUnitTestCase (that
044: * should not be tested) with noop implementation.
045: *
046: * Also tests the interaction of the web layer with the EJB layer, with
047: * a custom security manager plugin installed.
048: *
049: * @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
050: * @since Apr 3, 2006
051: * @version $Revision: 60917 $
052: */
053: public class CustomSecurityManagerTestCase extends EJBSpecUnitTestCase {
054: public static String REALM = "JBossTest Servlets";
055:
056: public CustomSecurityManagerTestCase(String name) {
057: super (name);
058: }
059:
060: /**
061: * Tests the access of a BASIC secured servlet that internally
062: * accesses a secured EJB
063: *
064: * @throws Exception
065: */
066: public void testWebLayer() throws Exception {
067: //Access the SecureServletSecureEJB servlet
068: String baseURL = HttpUtils.getBaseURL("scott", "echoman");
069: //Test the Restricted servlet
070: URL url = new URL(baseURL + "custom-secmgr/SecureServlet");
071: HttpUtils.accessURL(url, REALM, HttpURLConnection.HTTP_OK,
072: HttpUtils.POST);
073: }
074:
075: /**
076: * Overriden test method that has noop impl
077: */
078: public void testDomainInteraction() throws Exception {
079: log.debug("testDomainInteraction::We Do Not Test This!");
080: }
081:
082: /**
083: * JBAS-4801: JRockit wierdness:: Just calls the super class method
084: */
085: public void testGetCallerPrincipal() throws Exception {
086: super .testGetCallerPrincipal();
087: }
088:
089: /**
090: * Setup the test suite.
091: */
092: public static Test suite() throws Exception {
093: TestSuite suite = new TestSuite();
094: suite.addTestSuite(CustomSecurityManagerTestCase.class);
095:
096: // Create an initializer for the test suite
097: TestSetup wrapper = new JBossTestSetup(suite) {
098: protected void setUp() throws Exception {
099: super .setUp();
100: Configuration
101: .setConfiguration(new XMLLoginConfigImpl());
102: deploy(getResourceURL("security/custom-secmgr/queues-service.xml"));
103: redeploy("custom-secmgrtests.ear");
104: flushAuthCache();
105: }
106:
107: protected void tearDown() throws Exception {
108: undeploy("custom-secmgrtests.ear");
109: undeploy(getResourceURL("security/custom-secmgr/queues-service.xml"));
110: super.tearDown();
111:
112: }
113: };
114: return wrapper;
115: }
116: }
|