001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_securityTest.java 4604 2004-04-15 17:15:45Z bobkruse $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.jca15;
027:
028: import junit.framework.*;
029: import java.io.BufferedReader;
030: import java.io.FileInputStream;
031: import java.io.InputStreamReader;
032: import java.io.IOException;
033: import java.lang.String;
034: import java.rmi.RemoteException;
035: import javax.rmi.PortableRemoteObject;
036: import java.util.Collection;
037: import java.util.Enumeration;
038: import java.util.Hashtable;
039: import java.util.Properties;
040: import javax.ejb.FinderException;
041: import javax.ejb.RemoveException;
042: import javax.naming.Context;
043: import javax.naming.InitialContext;
044: import javax.naming.NamingException;
045:
046: import org.objectweb.jonas.jtests.beans.jca15.SecuredCA;
047: import org.objectweb.jonas.jtests.beans.jca15.SecuredCAHome;
048: import org.objectweb.jonas.jtests.util.JTestCase;
049:
050: /**
051: * Tests Jonas Connector Architecture container-managed sign-on.
052: */
053:
054: public class F_securityTest extends JTestCase {
055:
056: static Context ctx = null;
057:
058: // Lookup bean home
059:
060: protected static String BEAN_HOME = "SecuredCAHome";
061: protected static SecuredCAHome home = null;
062: private static final String RAR_JNDI_NAME = "eis/ErsatzSecurity";
063: static SecuredCA bean = null;
064: final public int CLOSE_HANDLE = 0;
065: final public int CLOSE_PHYSICAL = 1;
066: public int CloseType = 0;
067: public String UseBeans = "jca15";
068:
069: public F_securityTest(String name) {
070: super (name);
071: }
072:
073: protected void setUp() {
074: super .setUp();
075: try {
076: // get JNDI initial context
077:
078: if (ctx == null) {
079: ctx = new InitialContext();
080: }
081:
082: if (home == null) {
083: useBeans(UseBeans, false);
084: }
085: getBean();
086: assertTrue(5 == 5);
087:
088: } catch (Exception e) {
089: fail("Cannot do setUp: " + e);
090: }
091: }
092:
093: private void getBean() throws Exception {
094: // Connecting to SecuredCAHome thru JNDI
095:
096: if (home == null) {
097: home = (SecuredCAHome) PortableRemoteObject.narrow(ctx
098: .lookup(BEAN_HOME), SecuredCAHome.class);
099: bean = home.create();
100: }
101: }
102:
103: protected void tearDown() throws Exception {
104: bean.closeUp(CloseType);
105: }
106:
107: protected void startUp(String testName) {
108: try {
109: bean.method1(RAR_JNDI_NAME, testName);
110: } catch (Exception ee) {
111: ee.printStackTrace();
112: System.exit(2);
113: }
114: }
115:
116: // test list ****************************************************
117: /**
118: * Container managed sign-on.
119: *
120: * The application server provides the required security information for
121: * the resource principal through its configured security policies and mechanisms.
122: *
123: * When this class is deployed, the <code>secured.xml</code> file contains:
124: * <p>
125: * <code><res-auth>Container</res-auth></code>
126: *
127: */
128: public void testSecurityContextContainer() throws Exception {
129: CloseType = CLOSE_PHYSICAL;
130: bean.setResAuth("Container");
131: startUp("testSecurityContextContainer");
132: //bean.setMatchNull(true);
133: String pw = bean.getSecurityPassword();
134: String u = bean.getSecurityUserName();
135: String realResAuth = bean.getResAuth();
136: if (realResAuth.equals("Container")) {
137: assertEquals("defaultPassword", pw);
138: assertEquals("defaultUserName", u);
139: } else {
140: assertFalse(pw.equals("defaultPassword"));
141: }
142: }
143:
144: // end test list ****************************************************
145:
146: public static Test suite() {
147: return new TestSuite(F_securityTest.class);
148: }
149:
150: public static void main(String args[]) {
151:
152: String testtorun = null;
153:
154: // Get args
155:
156: for (int argn = 0; argn < args.length; argn++) {
157:
158: String s_arg = args[argn];
159: Integer i_arg;
160:
161: if (s_arg.equals("-n")) {
162: testtorun = args[++argn];
163: }
164: }
165:
166: if (testtorun == null) {
167: junit.textui.TestRunner.run(suite());
168: } else {
169: junit.textui.TestRunner.run(new F_securityTest(testtorun));
170: }
171: }
172: }
|