1 28 package net.sf.jguard.core.authentication.configuration; 29 30 import java.util.ArrayList ; 31 import java.util.HashMap ; 32 import java.util.List ; 33 import java.util.Map ; 34 35 import javax.security.auth.login.AppConfigurationEntry ; 36 import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag; 37 38 import junit.framework.TestCase; 39 import net.sf.jguard.core.CoreConstants; 40 41 42 public class JGuardConfigurationTest extends TestCase { 43 44 47 private List generateMockLoginModuleList() { 48 List loginModules = new ArrayList (); 49 50 Map first = new HashMap (); 51 first.put(CoreConstants.NAME,"net.sf.jguard.authentication.loginmodules.XmlLoginModule"); 52 first.put(CoreConstants.FLAG, "REQUIRED"); 53 Map firstOptions = new HashMap (); 54 firstOptions.put("debug", "false"); 55 firstOptions.put("fileLocation","WEB-INF/conf/jGuard/jGuardUsersPrincipals.xml"); 56 firstOptions.put("authenticationManager","net.sf.jguard.authentication.XmlAuthenticationManager"); 57 first.put(CoreConstants.LOGIN_MODULE_OPTIONS, firstOptions); 58 loginModules.add(first); 59 60 Map second = new HashMap (); 61 second.put(CoreConstants.NAME,"net.sf.jguard.authentication.loginmodules.PostgreSQLLoginModule"); 62 second.put(CoreConstants.FLAG, "OPTIONAL"); 63 Map secondOptions = new HashMap (); 64 secondOptions.put("authenticationUrl", "jdbc:postgresql://127.0.0.1:5434/test"); 65 secondOptions.put("authenticationLogin","testLogin"); 66 secondOptions.put("authenticationPassword","testPassword"); 67 secondOptions.put("authenticationDriver","org.postgresql.Driver"); 68 second.put(CoreConstants.LOGIN_MODULE_OPTIONS, secondOptions); 69 loginModules.add(second); 70 71 return loginModules; 72 } 73 74 77 public void testGetApplicationEntry() { 78 Map authenticationMap = new HashMap (); 79 authenticationMap.put(CoreConstants.DEBUG, "true"); 80 81 authenticationMap.put(CoreConstants.INCLUDE_OLD_CONFIG, "false"); 82 83 List loginModules = generateMockLoginModuleList(); 84 authenticationMap.put(CoreConstants.LOGIN_MODULES, loginModules); 85 86 String appName = "test"; 88 JGuardConfiguration jGuardConf = new JGuardConfiguration(); 89 ConfigurationHelper.addConfigurationEntryForWebapp(jGuardConf,appName,authenticationMap,false); 90 AppConfigurationEntry [] entries = jGuardConf.getAppConfigurationEntry("test"); 92 93 assertEquals(entries.length, 2); 96 97 AppConfigurationEntry xmlEntry = entries[0]; 99 100 assertEquals(xmlEntry.getLoginModuleName(), "net.sf.jguard.authentication.loginmodules.XmlLoginModule"); 102 assertEquals(xmlEntry.getControlFlag(), LoginModuleControlFlag.REQUIRED); 103 Map xmlEntryOptions = xmlEntry.getOptions(); 104 assertEquals( (String ) xmlEntryOptions.get("debug"), "false"); 105 assertEquals( (String ) xmlEntryOptions.get("fileLocation"), "WEB-INF/conf/jGuard/jGuardUsersPrincipals.xml"); 106 assertEquals( (String ) xmlEntryOptions.get("authenticationManager"), "net.sf.jguard.authentication.XmlAuthenticationManager"); 107 108 109 AppConfigurationEntry pgEntry = entries[1]; 111 112 assertEquals(pgEntry.getLoginModuleName(), "net.sf.jguard.authentication.loginmodules.PostgreSQLLoginModule"); 114 assertEquals(pgEntry.getControlFlag(), LoginModuleControlFlag.OPTIONAL); 115 Map pgEntryOptions = pgEntry.getOptions(); 116 assertEquals( (String ) pgEntryOptions.get("authenticationUrl"), "jdbc:postgresql://127.0.0.1:5434/test"); 117 assertEquals( (String ) pgEntryOptions.get("authenticationLogin"), "testLogin"); 118 assertEquals( (String ) pgEntryOptions.get("authenticationPassword"), "testPassword"); 119 assertEquals( (String ) pgEntryOptions.get("authenticationDriver"), "org.postgresql.Driver"); 120 121 } 122 123 } 124 | Popular Tags |