01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb;
17:
18: import junit.framework.TestCase;
19: import org.apache.openejb.server.ejbd.EjbServer;
20: import org.apache.openejb.server.ServiceDaemon;
21: import org.apache.openejb.core.ServerFederation;
22: import org.apache.openejb.loader.SystemInstance;
23:
24: import javax.naming.Context;
25: import javax.naming.InitialContext;
26: import javax.naming.NamingException;
27: import java.util.Properties;
28:
29: /**
30: * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $
31: */
32: public class AuthTest extends TestCase {
33: public void test() throws Exception {
34: EjbServer ejbServer = new EjbServer();
35:
36: Properties initProps = new Properties();
37: initProps.setProperty("openejb.deployments.classpath.include",
38: "");
39: initProps.setProperty(
40: "openejb.deployments.classpath.filter.descriptors",
41: "true");
42: OpenEJB.init(initProps, new ServerFederation());
43: ejbServer.init(new Properties());
44:
45: ServiceDaemon serviceDaemon = new ServiceDaemon(ejbServer, 0,
46: "localhost");
47: serviceDaemon.start();
48:
49: int port = serviceDaemon.getPort();
50:
51: try {
52:
53: // good creds
54: Properties props = new Properties();
55: props
56: .put("java.naming.factory.initial",
57: "org.apache.openejb.client.RemoteInitialContextFactory");
58: props.put("java.naming.provider.url", "ejbd://127.0.0.1:"
59: + port);
60: props.put(Context.SECURITY_PRINCIPAL, "jonathan");
61: props.put(Context.SECURITY_CREDENTIALS, "secret");
62: new InitialContext(props);
63:
64: try {
65: props.put(Context.SECURITY_PRINCIPAL, "alfred");
66: props.put(Context.SECURITY_CREDENTIALS, "doesnotexist");
67: new InitialContext(props);
68: } catch (javax.naming.AuthenticationException e) {
69: // pass -- user does not exist
70: }
71:
72: } catch (NamingException e) {
73: throw e;
74: } finally {
75: serviceDaemon.stop();
76: OpenEJB.destroy();
77: }
78:
79: }
80: }
|