001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.security.test;
023:
024: import java.util.Map;
025:
026: import javax.security.auth.login.Configuration;
027: import javax.security.auth.login.AppConfigurationEntry;
028:
029: import org.apache.log4j.Logger;
030:
031: import org.jboss.logging.XLevel;
032: import org.jboss.security.SecurityConstants;
033: import org.jboss.security.auth.login.XMLLoginConfigImpl;
034: import org.jboss.test.JBossTestCase;
035:
036: /**
037: * For changes made on JBAS-1477, the security domain name is added to every login
038: * module option map by the ApplicationInfo object. When TRACE logging is enable,
039: * a login module will then display this option value for trouble shooting. The
040: * first part of test, displays how the security domain option is properly set
041: * in a security domain that exists in Configuration. The second test shows
042: * how the "other" security domain is displayed when the original domain does not
043: * exist in Configuration.
044: *
045: * @author chris griffith
046: * @version $Revision: 57211 $
047: */
048: public class SecurityDomainLoginModuleOptionUnitTestCase extends
049: JBossTestCase {
050:
051: public SecurityDomainLoginModuleOptionUnitTestCase(String name) {
052: super (name);
053: }
054:
055: protected void setUp() throws Exception {
056: // Setup the replacement properties
057: System.setProperty("users.properties",
058: "/security/config/users.properites");
059: System.setProperty("roles.properties",
060: "/security/config/roles.properites");
061:
062: // Install the custom JAAS configuration
063: XMLLoginConfigImpl config = new XMLLoginConfigImpl();
064: config.setConfigResource("security/login-config.xml");
065: config.loadConfig();
066: Configuration.setConfiguration(config);
067:
068: // Turn on trace level logging
069: Logger root = Logger.getRootLogger();
070: root.setLevel(XLevel.TRACE);
071: }
072:
073: public void testSecurityDomainLoginModuleOption() throws Exception {
074: Configuration config = Configuration.getConfiguration();
075: String validSecurityDomain = "testUsersRoles";
076: String invalidSecurityDomain = "doesNotExist";
077:
078: getLog().info("testSecurityDomainLoginModuleOption");
079:
080: //get the app configuration for a valid security domain...
081: AppConfigurationEntry[] entries = config
082: .getAppConfigurationEntry(validSecurityDomain);
083: assertTrue("Entries not null", entries != null);
084:
085: //for each login module configured in domain, check that the option is set as expected.
086: for (int i = 0; i < entries.length; i++) {
087: String loginModuleClass = entries[i].getLoginModuleName();
088: String flag = entries[i].getControlFlag().toString();
089: Map options = entries[i].getOptions();
090:
091: getLog().info(
092: loginModuleClass + " is " + flag
093: + "\nWith options...\n" + options);
094:
095: String option = (String) options
096: .get(SecurityConstants.SECURITY_DOMAIN_OPTION);
097: assertTrue("Security domain option has value \"" + option
098: + "\", it should be \"" + validSecurityDomain
099: + "\"", option.equals(validSecurityDomain));
100: }
101:
102: //now get the app configuration for a domain that does not exist.
103: entries = config
104: .getAppConfigurationEntry(invalidSecurityDomain);
105: assertTrue("Entries not null", entries != null);
106:
107: //for each login module config'ed in domain, check that the option is set as "other"
108: for (int i = 0; i < entries.length; i++) {
109: String loginModuleClass = entries[i].getLoginModuleName();
110: String flag = entries[i].getControlFlag().toString();
111: Map options = entries[i].getOptions();
112:
113: getLog().info(
114: loginModuleClass + " is " + flag
115: + "\nWith options...\n" + options);
116:
117: String option = (String) options
118: .get(SecurityConstants.SECURITY_DOMAIN_OPTION);
119: assertTrue(
120: "Security domain option has value \""
121: + option
122: + "\", it should be \""
123: + SecurityConstants.DEFAULT_APPLICATION_POLICY
124: + "\"",
125: option
126: .equals(SecurityConstants.DEFAULT_APPLICATION_POLICY));
127: }
128: }
129: }
|