1 17 18 package org.apache.geronimo.security.jaas; 19 20 import org.apache.geronimo.gbean.AbstractName; 21 import org.apache.geronimo.gbean.GBeanData; 22 import org.apache.geronimo.security.AbstractTest; 23 import org.apache.geronimo.security.ContextManager; 24 import org.apache.geronimo.security.DomainPrincipal; 25 import org.apache.geronimo.security.IdentificationPrincipal; 26 import org.apache.geronimo.security.RealmPrincipal; 27 import org.apache.geronimo.security.realm.GenericSecurityRealm; 28 29 import javax.security.auth.Subject ; 30 import javax.security.auth.login.LoginContext ; 31 import java.io.File ; 32 import java.util.Properties ; 33 import java.util.Set ; 34 35 36 39 public class TimeoutTest extends AbstractTest { 40 41 protected AbstractName testCE; 42 protected AbstractName testRealm; 43 protected AbstractName clientLM; 44 protected AbstractName clientCE; 45 46 public void setUp() throws Exception { 47 timeoutTest = true; 48 needServerInfo = true; 49 needLoginConfiguration = true; 50 super.setUp(); 51 52 GBeanData gbean; 53 54 56 gbean = buildGBeanData ("name", "PropertiesLoginModule", LoginModuleGBean.getGBeanInfo()); 57 testCE = gbean.getAbstractName(); 58 gbean.setAttribute("loginModuleClass", "org.apache.geronimo.security.realm.providers.PropertiesFileLoginModule"); 59 gbean.setAttribute("serverSide", Boolean.TRUE); 60 Properties props = new Properties (); 61 props.put("usersURI", new File (BASEDIR, "src/test/data/data/users.properties").toURI().toString()); 62 props.put("groupsURI", new File (BASEDIR, "src/test/data/data/groups.properties").toURI().toString()); 63 gbean.setAttribute("options", props); 64 gbean.setAttribute("loginDomainName", "PropertiesDomain"); 65 gbean.setAttribute("wrapPrincipals", Boolean.TRUE); 66 kernel.loadGBean(gbean, LoginModuleGBean.class.getClassLoader()); 67 68 gbean = buildGBeanData("name", "PropertiesLoginModuleUse", JaasLoginModuleUse.getGBeanInfo()); 69 AbstractName testUseName = gbean.getAbstractName(); 70 gbean.setAttribute("controlFlag", "REQUIRED"); 71 gbean.setReferencePattern("LoginModule", testCE); 72 kernel.loadGBean(gbean, JaasLoginModuleUse.class.getClassLoader()); 73 74 gbean = buildGBeanData("name", "PropertiesSecurityRealm", GenericSecurityRealm.getGBeanInfo()); 75 testRealm = gbean.getAbstractName(); 76 gbean.setAttribute("realmName", "properties-realm"); 77 gbean.setReferencePattern("LoginModuleConfiguration", testUseName); 78 gbean.setReferencePattern("ServerInfo", serverInfo); 79 gbean.setReferencePattern("LoginService", loginService); 80 kernel.loadGBean(gbean, GenericSecurityRealm.class.getClassLoader()); 81 82 gbean = buildGBeanData("name", "ClientPropertiesLoginModule", LoginModuleGBean.getGBeanInfo()); 83 clientLM = gbean.getAbstractName(); 84 gbean.setAttribute("loginModuleClass", "org.apache.geronimo.security.jaas.client.JaasLoginCoordinator"); 85 gbean.setAttribute("serverSide", Boolean.FALSE); 86 props = new Properties (); 87 props.put("host", "localhost"); 88 props.put("port", "4242"); 89 props.put("realm", "properties-realm"); 90 gbean.setAttribute("options", props); 91 kernel.loadGBean(gbean, LoginModuleGBean.class.getClassLoader()); 92 93 gbean = buildGBeanData("name", "ClientConfigurationEntry", DirectConfigurationEntry.getGBeanInfo()); 94 clientCE = gbean.getAbstractName(); 95 gbean.setAttribute("applicationConfigName", "properties-client"); 96 gbean.setAttribute("controlFlag", LoginModuleControlFlag.REQUIRED); 97 gbean.setReferencePattern("Module", clientLM); 98 kernel.loadGBean(gbean, DirectConfigurationEntry.class.getClassLoader()); 99 100 kernel.startGBean(loginConfiguration); 101 kernel.startGBean(clientLM); 102 kernel.startGBean(clientCE); 103 kernel.startGBean(testCE); 104 kernel.startGBean(testUseName); 105 kernel.startGBean(testRealm); 106 } 107 108 public void tearDown() throws Exception { 109 kernel.stopGBean(testRealm); 110 kernel.stopGBean(testCE); 111 kernel.stopGBean(clientCE); 112 kernel.stopGBean(clientLM); 113 kernel.stopGBean(loginConfiguration); 114 kernel.stopGBean(serverInfo); 115 116 kernel.unloadGBean(testCE); 117 kernel.unloadGBean(testRealm); 118 kernel.unloadGBean(clientCE); 119 kernel.unloadGBean(clientLM); 120 kernel.unloadGBean(loginConfiguration); 121 kernel.unloadGBean(serverInfo); 122 123 kernel.stopGBean(serverStub); 124 kernel.stopGBean(loginService); 125 126 kernel.unloadGBean(loginService); 127 kernel.unloadGBean(serverStub); 128 129 kernel.shutdown(); 130 } 131 132 public void testNothing() { 133 } 134 135 public void testTimeout() throws Exception { 136 137 LoginContext context = new LoginContext ("properties-client", new AbstractTest.UsernamePasswordCallback("alan", "starcraft")); 138 139 context.login(); 140 Subject subject = context.getSubject(); 141 assertTrue("expected non-null client subject", subject != null); 142 Set set = subject.getPrincipals(IdentificationPrincipal.class); 143 assertEquals("client subject should have one ID principal", set.size(), 1); 144 IdentificationPrincipal idp = (IdentificationPrincipal) set.iterator().next(); 145 subject = ContextManager.getRegisteredSubject(idp.getId()); 146 147 assertTrue("expected non-null server subject", subject != null); 148 assertTrue("server subject should have one remote principal", subject.getPrincipals(IdentificationPrincipal.class).size() == 1); 149 IdentificationPrincipal remote = (IdentificationPrincipal) subject.getPrincipals(IdentificationPrincipal.class).iterator().next(); 150 assertTrue("server subject should be associated with remote id", ContextManager.getRegisteredSubject(remote.getId()) != null); 151 assertEquals("server-side subject should have seven principal", 7, subject.getPrincipals().size()); 152 assertTrue("server subject should have two realm principal", subject.getPrincipals(RealmPrincipal.class).size() == 2); 153 assertTrue("server subject should have two domain principal", subject.getPrincipals(DomainPrincipal.class).size() == 2); 154 155 assertTrue("id of server subject should be non-null", ContextManager.getSubjectId(subject) != null); 156 157 Thread.sleep(3000); 159 assertTrue("id of server subject should be non-null", ContextManager.getSubjectId(subject) != null); 160 161 Thread.sleep(7000); 163 assertTrue("id of server subject should be null", ContextManager.getSubjectId(subject) == null); 164 } 165 } 166 | Popular Tags |