1 package net.sf.jguard.ext.authentication; 2 3 import java.util.List ; 4 import java.util.Map ; 5 6 import junit.framework.TestCase; 7 import net.sf.jguard.core.CoreConstants; 8 import net.sf.jguard.ext.SecurityConstants; 9 import net.sf.jguard.ext.authentication.manager.AuthenticationHelper; 10 11 public class AuthenticationHelperTest extends TestCase { 12 13 public void testLoadConfiguration() { 14 15 String fileLocation = getClass().getResource("/jGuardAuthentication.xml").toString() ; 16 String appHomePath = ""; 17 18 Map authenticationConfiguration = null; 19 try{ 20 authenticationConfiguration = AuthenticationHelper.loadConfiguration(fileLocation, appHomePath); 21 } catch (Throwable t){ 22 fail("Authentication configuration loading failed : " + t.getMessage()); 23 } 24 assertNotNull("authentication Map must be initialized", authenticationConfiguration); 25 26 assertEquals("true", authenticationConfiguration.get(CoreConstants.DEBUG)); 27 assertEquals("false", authenticationConfiguration.get(CoreConstants.INCLUDE_OLD_CONFIG)); 28 assertEquals("false", authenticationConfiguration.get(CoreConstants.INCLUDE_CONFIG_FROM_JAVA_PARAM)); 29 assertEquals("false", authenticationConfiguration.get(SecurityConstants.INCLUDE_POLICY_FROM_JAVA_PARAM)); 30 assertEquals("MD5", authenticationConfiguration.get(SecurityConstants.DIGEST_ALGORITHM)); 31 assertEquals("qsd846sdq6ds4", authenticationConfiguration.get(SecurityConstants.SALT)); 32 33 assertEquals("net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager", authenticationConfiguration.get(SecurityConstants.AUTHENTICATION_MANAGER)); 34 Map authenticationManagerOptions = (Map )authenticationConfiguration.get(SecurityConstants.AUTHENTICATION_MANAGER_OPTIONS); 35 assertNotNull("AuthenticationManager options map must be initialized", authenticationManagerOptions); 36 assertEquals("WEB-INF/conf/jGuard/jGuardUsersPrincipals.xml", authenticationManagerOptions.get(SecurityConstants.AUTHENTICATION_XML_FILE_LOCATION)); 37 38 List loginModules = (List )authenticationConfiguration.get(CoreConstants.LOGIN_MODULES); 39 assertEquals(2, loginModules.size()); 40 41 Map loginModuleMap = (Map )loginModules.get(1); 42 assertEquals("net.sf.jguard.ext.authentication.loginmodules.XmlLoginModule", loginModuleMap.get(CoreConstants.NAME)); 43 assertEquals("REQUIRED", loginModuleMap.get(CoreConstants.FLAG)); 44 Map loginModuleOptions = (Map )loginModuleMap.get(CoreConstants.LOGIN_MODULE_OPTIONS); 45 assertNotNull("LoginModule options map must be initialized", loginModuleOptions); 46 assertEquals("false", loginModuleOptions.get("debug")); 47 48 } 49 50 } 51 | Popular Tags |