KickJava   Java API By Example, From Geeks To Geeks.

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


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.Map JavaDoc;
25
26 import javax.security.auth.login.Configuration JavaDoc;
27 import javax.security.auth.login.AppConfigurationEntry JavaDoc;
28
29 import org.jboss.logging.Logger;
30
31 import org.jboss.logging.XLevel;
32 import org.jboss.security.SecurityConstants;
33 import org.jboss.security.auth.login.XMLLoginConfigImpl;
34 import org.jboss.test.JBossTestCase;
35
36 /**
37  * For changes made on JBAS-1477, the security domain name is added to every login
38  * module option map by the ApplicationInfo object. When TRACE logging is enable,
39  * a login module will then display this option value for trouble shooting. The
40  * first part of test, displays how the security domain option is properly set
41  * in a security domain that exists in Configuration. The second test shows
42  * how the "other" security domain is displayed when the original domain does not
43  * exist in Configuration.
44  *
45  * @author chris griffith
46  * @version $Revision: 58115 $
47  */

48 public class SecurityDomainLoginModuleOptionUnitTestCase extends JBossTestCase
49 {
50
51    public SecurityDomainLoginModuleOptionUnitTestCase(String JavaDoc name)
52    {
53       super(name);
54    }
55
56    protected void setUp() throws Exception JavaDoc
57    {
58       // Setup the replacement properties
59
System.setProperty("users.properties", "/security/config/users.properites");
60       System.setProperty("roles.properties", "/security/config/roles.properites");
61
62       // Install the custom JAAS configuration
63
XMLLoginConfigImpl config = new XMLLoginConfigImpl();
64       config.setConfigResource("security/login-config.xml");
65       config.loadConfig();
66       Configuration.setConfiguration(config);
67    }
68
69    public void testSecurityDomainLoginModuleOption() throws Exception JavaDoc
70    {
71       Configuration JavaDoc config = Configuration.getConfiguration();
72       String JavaDoc validSecurityDomain = "testUsersRoles";
73       String JavaDoc invalidSecurityDomain = "doesNotExist";
74
75       getLog().info("testSecurityDomainLoginModuleOption");
76
77       //get the app configuration for a valid security domain...
78
AppConfigurationEntry JavaDoc[] entries = config.getAppConfigurationEntry(validSecurityDomain);
79       assertTrue("Entries not null",entries != null);
80
81       //for each login module configured in domain, check that the option is set as expected.
82
for (int i=0;i<entries.length;i++)
83       {
84      String JavaDoc loginModuleClass = entries[i].getLoginModuleName();
85          String JavaDoc flag = entries[i].getControlFlag().toString();
86      Map JavaDoc options = entries[i].getOptions();
87
88      getLog().info(loginModuleClass + " is " + flag + "\nWith options...\n" + options);
89      
90      String JavaDoc option = (String JavaDoc)options.get(SecurityConstants.SECURITY_DOMAIN_OPTION);
91      assertTrue("Security domain option has value \"" + option +
92             "\", it should be \"" + validSecurityDomain + "\"",
93             option.equals(validSecurityDomain));
94       }
95
96       //now get the app configuration for a domain that does not exist.
97
entries = config.getAppConfigurationEntry(invalidSecurityDomain);
98       assertTrue("Entries not null", entries != null);
99
100       //for each login module config'ed in domain, check that the option is set as "other"
101
for (int i=0;i<entries.length;i++)
102       {
103      String JavaDoc loginModuleClass = entries[i].getLoginModuleName();
104          String JavaDoc flag = entries[i].getControlFlag().toString();
105      Map JavaDoc options = entries[i].getOptions();
106
107      getLog().info(loginModuleClass + " is " + flag + "\nWith options...\n" + options);
108      
109      String JavaDoc option = (String JavaDoc)options.get(SecurityConstants.SECURITY_DOMAIN_OPTION);
110      assertTrue("Security domain option has value \"" + option +
111             "\", it should be \"" + SecurityConstants.DEFAULT_APPLICATION_POLICY + "\"",
112             option.equals(SecurityConstants.DEFAULT_APPLICATION_POLICY));
113       }
114    }
115 }
116
Popular Tags