1 22 package org.jboss.test.security.container.auth.config; 23 24 import java.io.InputStream ; 26 import java.io.InputStreamReader ; 27 import java.util.Map ; 28 29 import javax.security.auth.login.AppConfigurationEntry ; 30 31 import org.jboss.security.auth.container.config.AuthModuleEntry; 32 import org.jboss.security.auth.login.AuthenticationInfo; 33 import org.jboss.security.auth.login.BaseAuthenticationInfo; 34 import org.jboss.security.auth.login.JASPIAuthenticationInfo; 35 import org.jboss.security.auth.login.LoginConfigObjectModelFactory; 36 import org.jboss.security.auth.login.LoginModuleStackHolder; 37 import org.jboss.security.auth.spi.UsersObjectModelFactory; 38 import org.jboss.security.config.ApplicationPolicy; 39 import org.jboss.security.config.PolicyConfig; 40 import org.jboss.test.JBossTestCase; 41 import org.jboss.xb.binding.Unmarshaller; 42 import org.jboss.xb.binding.UnmarshallerFactory; 43 44 49 public class JASPIConfigurationTestCase extends JBossTestCase 50 { 51 public JASPIConfigurationTestCase(String name) 52 { 53 super(name); 54 } 55 56 public void testJaasAuthenticationInfo() throws Exception 57 { 58 PolicyConfig config = getPolicyConfig("security/jaspi/login-config-jaspi.xml", 59 new LoginConfigObjectModelFactory()); 60 assertNotNull("Returned PolicyConfig is != null ?", config); 61 ApplicationPolicy aPolicy = config.get("JBossWS"); 62 BaseAuthenticationInfo infoBase = aPolicy.getAuthenticationInfo(); 63 assertTrue("infoBase==AuthenticationInfo", infoBase instanceof AuthenticationInfo); 64 AuthenticationInfo info = (AuthenticationInfo)infoBase; 65 assertTrue("JBossWS != null", info != null); 66 AppConfigurationEntry [] entries = info.getAppConfigurationEntry(); 67 assertTrue("entries.length == 1", entries.length == 1); 68 AppConfigurationEntry ace = entries[0]; 69 assertTrue("org.jboss.security.auth.spi.UsersRolesLoginModule", 70 ace.getLoginModuleName().equals("org.jboss.security.auth.spi.UsersRolesLoginModule")); 71 Map options = ace.getOptions(); 72 assertTrue("Options.size == 3", options.size() == 3); 73 String guest = (String ) options.get("unauthenticatedIdentity"); 74 assertTrue("anonymous", guest.equals("anonymous")); 75 String users = (String ) options.get("usersProperties"); 76 assertTrue("anonymous", users.equals("props/jbossws-users.properties")); 77 String roles = (String ) options.get("rolesProperties"); 78 assertTrue("anonymous", roles.equals("props/jbossws-roles.properties")); 79 } 80 81 public void testJaspiAuthenticationInfo() throws Exception 82 { 83 LoginConfigObjectModelFactory lcomf = new LoginConfigObjectModelFactory(); 84 PolicyConfig config = getPolicyConfig("security/jaspi/login-config-jaspi.xml",lcomf); 85 assertNotNull("Returned PolicyConfig is != null ?", config); 86 ApplicationPolicy aPolicy = config.get("jaspi"); 87 BaseAuthenticationInfo infoBase = aPolicy.getAuthenticationInfo(); 88 assertTrue("infoBase==AuthenticationJaspiInfo", infoBase instanceof JASPIAuthenticationInfo); 89 JASPIAuthenticationInfo info = (JASPIAuthenticationInfo)infoBase; 90 assertTrue("jaspi != null", info != null); 91 AuthModuleEntry[] authEntry = info.getAuthModuleEntry(); 92 AuthModuleEntry aEntry1 = authEntry[0]; 94 validateAuthModule1(aEntry1); 95 AuthModuleEntry aEntry2 = authEntry[1]; 97 validateAuthModule2(aEntry2); 98 } 99 100 protected void validateAuthModule1(AuthModuleEntry aEntry1) 101 { 102 assertEquals("auth.module1.class.name", aEntry1.getAuthModuleName()); 103 Map aEntry1Options = aEntry1.getOptions(); 104 assertNotNull("Options in the first AuthModule != null", aEntry1Options); 105 assertTrue( "Length of options == 3", aEntry1Options.size() == 3); 106 String usersProperties = (String ) aEntry1Options.get("usersProperties"); 107 assertNotNull("options.usersProperties exists", usersProperties); 108 assertTrue("options.usersProperties == props/jbossws-users.properties", 109 usersProperties.equals("props/jbossws-users.properties")); 110 String rolesProperties = (String ) aEntry1Options.get("rolesProperties"); 111 assertNotNull("options.rolesProperties exists", rolesProperties); 112 assertTrue("options.rolesProperties == props/jbossws-roles.properties", 113 rolesProperties.equals("props/jbossws-roles.properties")); 114 } 115 116 protected void validateAuthModule2(AuthModuleEntry aEntry2) 117 { 118 assertEquals("auth.module2.class.name", aEntry2.getAuthModuleName()); 119 LoginModuleStackHolder lmsh = aEntry2.getLoginModuleStackHolder(); 120 assertNotNull("LoginModuleStackHolder != null", lmsh); 121 assertEquals("lm-stack", lmsh.getName()); 122 } 123 124 protected PolicyConfig getPolicyConfig(String config, 125 LoginConfigObjectModelFactory lcomf ) throws Exception 126 { 127 UsersObjectModelFactory uomf = new UsersObjectModelFactory(); 128 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(config); 129 InputStreamReader xmlReader = new InputStreamReader (is); 130 Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller(); 131 unmarshaller.setNamespaceAware(true); 132 unmarshaller.setValidation(true); 133 unmarshaller.mapFactoryToNamespace(uomf, "http://www.jboss.org/j2ee/schemas/XMLLoginModule"); 134 return (PolicyConfig) unmarshaller.unmarshal(xmlReader, lcomf, null); 135 } 136 } 137 | Popular Tags |