KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > jca15 > F_securityTest


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: F_securityTest.java,v 1.1 2004/04/15 17:09:34 bobkruse Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.clients.jca15;
27
28 import junit.framework.*;
29 import java.io.BufferedReader JavaDoc;
30 import java.io.FileInputStream JavaDoc;
31 import java.io.InputStreamReader JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.lang.String JavaDoc;
34 import java.rmi.RemoteException JavaDoc;
35 import javax.rmi.PortableRemoteObject JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.Enumeration JavaDoc;
38 import java.util.Hashtable JavaDoc;
39 import java.util.Properties JavaDoc;
40 import javax.ejb.FinderException JavaDoc;
41 import javax.ejb.RemoveException JavaDoc;
42 import javax.naming.Context JavaDoc;
43 import javax.naming.InitialContext JavaDoc;
44 import javax.naming.NamingException JavaDoc;
45
46 import org.objectweb.jonas.jtests.beans.jca15.SecuredCA;
47 import org.objectweb.jonas.jtests.beans.jca15.SecuredCAHome;
48 import org.objectweb.jonas.jtests.util.JTestCase;
49
50 /**
51  * Tests Jonas Connector Architecture container-managed sign-on.
52  */

53
54 public class F_securityTest extends JTestCase {
55
56     static Context JavaDoc ctx = null;
57
58     // Lookup bean home
59

60     protected static String JavaDoc BEAN_HOME = "SecuredCAHome";
61     protected static SecuredCAHome home = null;
62     private static final String JavaDoc RAR_JNDI_NAME = "eis/ErsatzSecurity";
63     static SecuredCA bean = null;
64     final public int CLOSE_HANDLE = 0;
65     final public int CLOSE_PHYSICAL = 1;
66     public int CloseType = 0;
67     public String JavaDoc UseBeans="jca15";
68
69     public F_securityTest(String JavaDoc name) {
70         super(name);
71     }
72
73     protected void setUp() {
74         super.setUp();
75         try {
76             // get JNDI initial context
77

78             if (ctx == null) {
79                 ctx = new InitialContext JavaDoc();
80             }
81
82             if (home == null) {
83                 useBeans(UseBeans, false);
84             }
85             getBean();
86             assertTrue (5 == 5);
87
88         } catch (Exception JavaDoc e) {
89             fail("Cannot do setUp: " +e);
90         }
91     }
92     private void getBean() throws Exception JavaDoc {
93         // Connecting to SecuredCAHome thru JNDI
94

95         if (home == null) {
96             home = (SecuredCAHome)PortableRemoteObject.narrow(
97                                 ctx.lookup(BEAN_HOME),
98                                 SecuredCAHome.class);
99             bean = home.create();
100         }
101     }
102     protected void tearDown() throws Exception JavaDoc {
103         bean.closeUp(CloseType);
104     }
105     protected void startUp(String JavaDoc testName) {
106         try {
107             bean.method1(RAR_JNDI_NAME, testName);
108         } catch (Exception JavaDoc ee) {
109             ee.printStackTrace();
110             System.exit(2);
111         }
112     }
113
114 // test list ****************************************************
115
/**
116      * Container managed sign-on.
117      *
118      * The application server provides the required security information for
119      * the resource principal through its configured security policies and mechanisms.
120      *
121      * When this class is deployed, the <code>secured.xml</code> file contains:
122      * <p>
123      * <code>&lt;res-auth&gt;Container&lt;/res-auth&gt;</code>
124      *
125      */

126     public void testSecurityContextContainer() throws Exception JavaDoc {
127         CloseType=CLOSE_PHYSICAL;
128         bean.setResAuth("Container");
129         startUp("testSecurityContextContainer");
130         //bean.setMatchNull(true);
131
String JavaDoc pw = bean.getSecurityPassword();
132         String JavaDoc u = bean.getSecurityUserName();
133         String JavaDoc realResAuth = bean.getResAuth();
134         if (realResAuth.equals("Container")) {
135             assertEquals("defaultPassword", pw);
136             assertEquals("defaultUserName", u);
137         } else {
138             assertFalse(pw.equals("defaultPassword"));
139         }
140     }
141 // end test list ****************************************************
142

143     public static Test suite() {
144         return new TestSuite(F_securityTest.class);
145     }
146
147     public static void main (String JavaDoc args[]) {
148
149         String JavaDoc testtorun = null;
150
151         // Get args
152

153         for (int argn = 0; argn < args.length; argn++) {
154
155             String JavaDoc s_arg = args[argn];
156             Integer JavaDoc i_arg;
157
158             if (s_arg.equals("-n")) {
159                 testtorun = args[++argn];
160             }
161         }
162
163         if (testtorun == null) {
164             junit.textui.TestRunner.run(suite());
165         } else {
166             junit.textui.TestRunner.run(new F_securityTest(testtorun));
167         }
168     }
169 }
170
Popular Tags