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.jacc.test.external;
23:
24: import java.net.URL;
25:
26: import junit.framework.Test;
27: import junit.framework.TestSuite;
28:
29: import org.jboss.logging.Logger;
30: import org.jboss.test.JBossTestCase;
31: import org.jboss.test.JBossTestSetup;
32: import org.jboss.test.util.web.HttpUtils;
33:
34: //$Id: AuthzDelegationUnitTestCase.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
35:
36: /**
37: * Tests delegation of authorization decisions to an external policy provider
38: * @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
39: * @since Apr 27, 2006
40: * @version $Revision: 57211 $
41: */
42: public class AuthzDelegationUnitTestCase extends JBossTestCase {
43: private static Logger log = Logger
44: .getLogger(AuthzDelegationUnitTestCase.class);
45:
46: private String baseURLNoAuth = HttpUtils.getBaseURLNoAuth();
47:
48: public AuthzDelegationUnitTestCase(String name) {
49: super (name);
50: }
51:
52: public void testSuccessfulWebResourceDelegation() throws Exception {
53: //Try a successful access
54: HttpUtils.accessURL(new URL(baseURLNoAuth
55: + "/jacc-delegate/index.html"));
56: //Try an unsuccessful access
57: try {
58: HttpUtils.accessURL(new URL(baseURLNoAuth
59: + "/jacc-delegate/noResource.html"));
60: fail("Should have failed");
61: } catch (Exception ignore) {
62: log.error("Ignorable error that should be access denied:",
63: ignore);
64: }
65: }
66:
67: public static Test suite() throws Exception {
68: TestSuite suite = new TestSuite();
69: suite.addTest(new TestSuite(AuthzDelegationUnitTestCase.class));
70:
71: // Create an initializer for the test suite
72: Test wrapper = new JBossTestSetup(suite) {
73: protected void setUp() throws Exception {
74: super .setUp();
75: deploy("jacc-delegate.war");
76: // Make sure the security cache is clear
77: flushAuthCache();
78: }
79:
80: protected void tearDown() throws Exception {
81: undeploy("jacc-delegate.war");
82: super.tearDown();
83: }
84: };
85: return wrapper;
86: }
87: }
|