KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > test > ClientLoginModuleEJBUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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 JavaDoc;
25 import java.security.Principal JavaDoc;
26
27 import javax.naming.Context JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
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: 41294 $
41  */

42 public class ClientLoginModuleEJBUnitTestCase
43    extends JBossTestCase
44 {
45    public ClientLoginModuleEJBUnitTestCase(String JavaDoc name)
46    {
47       super(name);
48    }
49
50    /**
51     Call BeanA using jduke/theduke
52     +-- call BeanB switching idenity using ClientLoginModule
53     +---- call BeanC switching idenity using ClientLoginModule
54     validing the expected caller principal with different ejb method permissions
55     @throws Exception
56     */

57    public void testClientLoginModule() throws Exception JavaDoc
58    {
59       log.debug("+++ testPublicMethod()");
60       Properties JavaDoc env = new Properties JavaDoc();
61       env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
62          "org.jboss.security.jndi.JndiLoginInitialContextFactory");
63       env.setProperty(Context.SECURITY_PRINCIPAL, "jduke");
64       env.setProperty(Context.SECURITY_CREDENTIALS, "theduke");
65       InitialContext JavaDoc ctx = new InitialContext JavaDoc(env);
66       Object JavaDoc obj = ctx.lookup("client-login-tests/BeanA");
67       obj = PortableRemoteObject.narrow(obj, IClientLoginHome.class);
68       IClientLoginHome home = (IClientLoginHome) obj;
69       log.debug("Found IClientLoginHome");
70       IClientLogin bean = home.create();
71       log.debug("Created IClientLogin");
72
73       Principal JavaDoc user = bean.callBeanAsClientLoginUser();
74       assertTrue("callBeanAsClientLoginUser value == jduke",
75          user.getName().equals("jduke"));
76       bean.remove();
77    }
78
79    public static Test suite() throws Exception JavaDoc
80    {
81       return JBossTestCase.getDeploySetup(ClientLoginModuleEJBUnitTestCase.class,
82          "client-login-tests.jar");
83    }
84
85 }
86
Popular Tags