KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
25 import javax.security.auth.Subject JavaDoc;
26 import javax.security.auth.login.AppConfigurationEntry JavaDoc;
27 import javax.security.auth.login.Configuration JavaDoc;
28 import javax.security.auth.login.LoginContext JavaDoc;
29
30 /** A JUnit TestCase for the JAAS LoginContext usage.
31  *
32  * @author Scott.Stark@jboss.org
33  * @version $Revision: 37406 $
34  */

35 public class LoginContextUnitTestCase
36    extends junit.framework.TestCase
37 {
38    Subject JavaDoc subject1;
39    Subject JavaDoc subject2;
40
41    static class MyConfig extends Configuration JavaDoc
42    {
43       AppConfigurationEntry JavaDoc[] entry;
44       MyConfig()
45       {
46          entry = new AppConfigurationEntry JavaDoc[1];
47          HashMap JavaDoc opt0 = new HashMap JavaDoc();
48          opt0.put("principal", "starksm");
49          entry[0] = new AppConfigurationEntry JavaDoc("org.jboss.security.auth.spi.IdentityLoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, opt0);
50          //entry[1] = new AppConfigurationEntry("org.jboss.security.plugins.samples.RolesLoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, new HashMap());
51
}
52
53       public AppConfigurationEntry JavaDoc[] getAppConfigurationEntry(String JavaDoc appName)
54       {
55          return entry;
56       }
57       public void refresh()
58       {
59       }
60    }
61
62    public LoginContextUnitTestCase(String JavaDoc name)
63    {
64       super(name);
65    }
66
67    protected void setUp() throws Exception JavaDoc
68    {
69       Configuration.setConfiguration(new MyConfig());
70    }
71
72    public void testLogin1() throws Exception JavaDoc
73    {
74       subject1 = new Subject JavaDoc();
75       LoginContext JavaDoc lc = new LoginContext JavaDoc("LoginContext", subject1);
76       lc.login();
77       Subject JavaDoc lcSubject = lc.getSubject();
78       assertTrue("subject == lcSubject", subject1 == lcSubject );
79    }
80    public void testLogin2() throws Exception JavaDoc
81    {
82       subject2 = new Subject JavaDoc();
83       LoginContext JavaDoc lc = new LoginContext JavaDoc("LoginContext", subject2);
84       lc.login();
85       Subject JavaDoc lcSubject = lc.getSubject();
86       assertTrue("subject == lcSubject", subject2 == lcSubject );
87    }
88 }
89
Popular Tags