KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jacc > test > CallerInRoleUnitTestCase


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.jacc.test;
23
24 import javax.rmi.PortableRemoteObject JavaDoc;
25 import javax.security.auth.login.Configuration JavaDoc;
26 import javax.security.auth.login.LoginContext JavaDoc;
27
28 import junit.extensions.TestSetup;
29 import junit.framework.Test;
30 import junit.framework.TestSuite;
31
32 import org.jboss.security.auth.login.XMLLoginConfigImpl;
33 import org.jboss.test.JBossTestCase;
34 import org.jboss.test.JBossTestSetup;
35 import org.jboss.test.security.interfaces.UsefulStatelessSession;
36 import org.jboss.test.security.interfaces.UsefulStatelessSessionHome;
37 import org.jboss.test.util.AppCallbackHandler;
38
39 //$Id: CallerInRoleUnitTestCase.java 46073 2006-07-05 18:30:35Z asaldhana $
40

41 /**
42  * JBAS-2661:EJB context isCallerInRole not delegating to JACC when installed
43  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
44  * @since Apr 20, 2006
45  * @version $Revision: 46073 $
46  */

47 public class CallerInRoleUnitTestCase extends JBossTestCase
48 {
49    LoginContext JavaDoc lc;
50    public CallerInRoleUnitTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54    
55    public void testCallerInRoleForBean1() throws Exception JavaDoc
56    {
57       login("anil","opensource".toCharArray());
58       Object JavaDoc obj = getInitialContext().lookup("bean1.UsefulStatelessSessionBean");
59       obj = PortableRemoteObject.narrow(obj, UsefulStatelessSessionHome.class);
60       UsefulStatelessSessionHome home = (UsefulStatelessSessionHome) obj;
61       UsefulStatelessSession bean = home.create();
62       assertEquals("NiceUser is true", "true", ""+bean.isCallerInRole("NiceUser") );
63       assertEquals("BadRole is false", "false", ""+bean.isCallerInRole("BadRole") );
64       bean.remove();
65       logout();
66    }
67    
68    private void login(String JavaDoc username, char[] password) throws Exception JavaDoc
69    {
70       lc = null;
71       String JavaDoc confName = System.getProperty("conf.name", "spec-test");
72       AppCallbackHandler handler = new AppCallbackHandler(username, password);
73       log.debug("Creating LoginContext("+confName+")");
74       lc = new LoginContext JavaDoc(confName, handler);
75       lc.login();
76       log.debug("Created LoginContext, subject="+lc.getSubject());
77    }
78    
79    private void logout() throws Exception JavaDoc
80    {
81          lc.logout();
82    }
83    
84    /**
85     * Setup the test suite.
86     */

87    public static Test suite() throws Exception JavaDoc
88    {
89       TestSuite suite = new TestSuite();
90       suite.addTest(new TestSuite(CallerInRoleUnitTestCase.class));
91
92       // Create an initializer for the test suite
93
TestSetup wrapper = new JBossTestSetup(suite)
94       {
95          protected void setUp() throws Exception JavaDoc
96          {
97             super.setUp();
98             Configuration.setConfiguration(new XMLLoginConfigImpl());
99             redeploy("security-jacc-callerinrole.jar");
100          }
101          protected void tearDown() throws Exception JavaDoc
102          {
103             undeploy("security-jacc-callerinrole.jar");
104             super.tearDown();
105          }
106       };
107       return wrapper;
108    }
109 }
110
Popular Tags