KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashSet JavaDoc;
25 import java.util.Properties JavaDoc;
26 import javax.naming.Context JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.rmi.PortableRemoteObject JavaDoc;
29
30 import junit.framework.Test;
31 import org.jboss.security.SimplePrincipal;
32 import org.jboss.test.JBossTestCase;
33 import org.jboss.test.security.interfaces.SubjectSession;
34 import org.jboss.test.security.interfaces.SubjectSessionHome;
35
36
37 /** Tests of the caller context state
38  
39  @author Scott.Stark@jboss.org
40  @version $Revision: 37406 $
41  */

42 public class CallerInfoUnitTestCase
43    extends JBossTestCase
44 {
45    public CallerInfoUnitTestCase(String JavaDoc name)
46    {
47       super(name);
48    }
49
50    /** Test return of a custom principal from getCallerPrincipal.
51     */

52    public void testCallerSubject() throws Exception JavaDoc
53    {
54       log.debug("+++ testCallerSubject()");
55       Properties JavaDoc env = new Properties JavaDoc();
56       env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
57          "org.jboss.security.jndi.JndiLoginInitialContextFactory");
58       env.setProperty(Context.SECURITY_PRINCIPAL, "jduke");
59       env.setProperty(Context.SECURITY_CREDENTIALS, "theduke");
60       InitialContext JavaDoc ctx = new InitialContext JavaDoc(env);
61       Object JavaDoc obj = ctx.lookup("caller-info.SubjectSessionFacade");
62       obj = PortableRemoteObject.narrow(obj, SubjectSessionHome.class);
63       SubjectSessionHome home = (SubjectSessionHome) obj;
64       log.debug("Found CustomPrincipalHome");
65       SubjectSession bean = home.create();
66       log.debug("Created CustomPrincipal");
67
68       HashSet JavaDoc principals = new HashSet JavaDoc();
69       principals.add(new SimplePrincipal("CallerInfoFacadeRole"));
70       principals.add(new SimplePrincipal("CallerInfoStatelessRole"));
71       principals.add(new SimplePrincipal("CallerInfoStatefulRole"));
72       principals.add(new SimplePrincipal("CallerInfoEntityRole"));
73       bean.validateCallerContext("callerJduke", principals);
74       bean.remove();
75    }
76
77    public static Test suite() throws Exception JavaDoc
78    {
79       return JBossTestCase.getDeploySetup(CallerInfoUnitTestCase.class, "caller-info.jar");
80    }
81
82 }
83
Popular Tags