1 7 package org.jboss.test; 8 9 import java.io.InputStreamReader ; 10 import java.net.URL ; 11 import javax.security.auth.login.AppConfigurationEntry ; 12 import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag; 13 14 import junit.framework.TestCase; 15 16 import org.jboss.security.auth.login.SunConfigParser; 17 import org.jboss.security.auth.login.XMLLoginConfigImpl; 18 19 24 public class SunConfigParserTestCase extends TestCase 25 { 26 27 public SunConfigParserTestCase(String name) 28 { 29 super(name); 30 } 31 32 36 public void testParser() throws Exception 37 { 38 XMLLoginConfigImpl config = new XMLLoginConfigImpl(); 39 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 40 URL configURL = loader.getResource("login-config.conf"); 41 InputStreamReader configFile = new InputStreamReader (configURL.openStream()); 42 SunConfigParser.doParse(configFile, config, true); 43 44 AppConfigurationEntry [] entry = config.getAppConfigurationEntry("case1"); 45 assertTrue("case1 entry != null", entry != null); 46 assertTrue("case1.length == 2", entry.length == 2); 47 assertTrue("case1[0].module == org.jboss.test.TestLoginModule", 48 entry[0].getLoginModuleName().equals("org.jboss.test.TestLoginModule")); 49 assertTrue("case1[0].flag == required", 50 entry[0].getControlFlag() == LoginModuleControlFlag.REQUIRED); 51 assertTrue("case1[0].option(name) == 1.1", 52 entry[0].getOptions().get("name").equals("1.1")); 53 assertTrue("case1[0].option(succeed) == true", 54 entry[0].getOptions().get("succeed").equals("true")); 55 assertTrue("case1[0].option(throwEx) == false", 56 entry[0].getOptions().get("throwEx").equals("false")); 57 58 entry = config.getAppConfigurationEntry("case2"); 59 assertTrue("case2 entry != null", entry != null); 60 assertTrue("case2.length == 2", entry.length == 2); 61 assertTrue("case2[0].module = org.jboss.test.TestLoginModule", 62 entry[0].getLoginModuleName().equals("org.jboss.test.TestLoginModule")); 63 assertTrue("case2[0].flag == optional", 64 entry[0].getControlFlag() == LoginModuleControlFlag.OPTIONAL); 65 assertTrue("case2[1].option(name) == 2.2", 66 entry[1].getOptions().get("name").equals("2.2")); 67 assertTrue("case2[1].option(succeed) == false", 68 entry[1].getOptions().get("succeed").equals("false")); 69 assertTrue("case2[1].option(throwEx) == true", 70 entry[1].getOptions().get("throwEx").equals("true")); 71 } 72 73 78 public void testSunLoginConfig() throws Exception 79 { 80 XMLLoginConfigImpl config = new XMLLoginConfigImpl(); 81 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 82 URL configURL = loader.getResource("login-config.conf"); 83 config.setConfigURL(configURL); 84 config.loadConfig(); 85 86 AppConfigurationEntry [] entry = config.getAppConfigurationEntry("case1"); 87 assertTrue("case1 entry != null", entry != null); 88 assertTrue("case1.length == 2", entry.length == 2); 89 assertTrue("case1[0].module == org.jboss.test.TestLoginModule", 90 entry[0].getLoginModuleName().equals("org.jboss.test.TestLoginModule")); 91 assertTrue("case1[0].flag == required", 92 entry[0].getControlFlag() == LoginModuleControlFlag.REQUIRED); 93 assertTrue("case1[0].option(name) == 1.1", 94 entry[0].getOptions().get("name").equals("1.1")); 95 assertTrue("case1[0].option(succeed) == true", 96 entry[0].getOptions().get("succeed").equals("true")); 97 assertTrue("case1[0].option(throwEx) == false", 98 entry[0].getOptions().get("throwEx").equals("false")); 99 100 entry = config.getAppConfigurationEntry("case2"); 101 assertTrue("case2 entry != null", entry != null); 102 assertTrue("case2.length == 2", entry.length == 2); 103 assertTrue("case2[0].module = org.jboss.test.TestLoginModule", 104 entry[0].getLoginModuleName().equals("org.jboss.test.TestLoginModule")); 105 assertTrue("case2[0].flag == optional", 106 entry[0].getControlFlag() == LoginModuleControlFlag.OPTIONAL); 107 assertTrue("case2[1].option(name) == 2.2", 108 entry[1].getOptions().get("name").equals("2.2")); 109 assertTrue("case2[1].option(succeed) == false", 110 entry[1].getOptions().get("succeed").equals("false")); 111 assertTrue("case2[1].option(throwEx) == true", 112 entry[1].getOptions().get("throwEx").equals("true")); 113 } 114 } 115 | Popular Tags |