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.security.test;
23:
24: import java.util.Properties;
25: import java.security.Principal;
26:
27: import javax.naming.Context;
28: import javax.naming.InitialContext;
29: import javax.rmi.PortableRemoteObject;
30:
31: import org.jboss.test.JBossTestCase;
32: import org.jboss.test.security.clientlogin.IClientLoginHome;
33: import org.jboss.test.security.clientlogin.IClientLogin;
34: import junit.framework.Test;
35:
36: /** Tests of the interaction between the ClientLoginModule and the
37: SecurityAssocation context for secured ejbs
38:
39: @author Scott.Stark@jboss.org
40: @version $Revision: 57211 $
41: */
42: public class ClientLoginModuleEJBUnitTestCase extends JBossTestCase {
43: public ClientLoginModuleEJBUnitTestCase(String name) {
44: super (name);
45: }
46:
47: /**
48: Call BeanA using jduke/theduke
49: +-- call BeanB switching idenity using ClientLoginModule
50: +---- call BeanC switching idenity using ClientLoginModule
51: validing the expected caller principal with different ejb method permissions
52: @throws Exception
53: */
54: public void testClientLoginModule() throws Exception {
55: log.debug("+++ testPublicMethod()");
56: Properties env = new Properties();
57: env
58: .setProperty(Context.INITIAL_CONTEXT_FACTORY,
59: "org.jboss.security.jndi.JndiLoginInitialContextFactory");
60: env.setProperty(Context.SECURITY_PRINCIPAL, "jduke");
61: env.setProperty(Context.SECURITY_CREDENTIALS, "theduke");
62: InitialContext ctx = new InitialContext(env);
63: Object obj = ctx.lookup("client-login-tests/BeanA");
64: obj = PortableRemoteObject.narrow(obj, IClientLoginHome.class);
65: IClientLoginHome home = (IClientLoginHome) obj;
66: log.debug("Found IClientLoginHome");
67: IClientLogin bean = home.create();
68: log.debug("Created IClientLogin");
69:
70: Principal user = bean.callBeanAsClientLoginUser();
71: assertTrue("callBeanAsClientLoginUser value == jduke", user
72: .getName().equals("jduke"));
73: bean.remove();
74: }
75:
76: public static Test suite() throws Exception {
77: return JBossTestCase.getDeploySetup(
78: ClientLoginModuleEJBUnitTestCase.class,
79: "client-login-tests.jar");
80: }
81:
82: }
|