User: starksm Date: 02/03/22 19:10:54 Added: src/main/org/jboss/test/security/test SRPUnitTestCase.java Log: Tests of the SRP protocol Revision Changes Path 1.1 jbosstest/src/main/org/jboss/test/security/test/SRPUnitTestCase.java Index: SRPUnitTestCase.java =================================================================== /* * JBoss, the OpenSource J2EE webOS * * Distributable under LGPL license. * See terms of license at gnu.org. */ package org.jboss.test.security.test; import java.io.IOException; import java.net.InetAddress; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.Handle; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; import javax.security.auth.login.*; import org.jboss.test.security.interfaces.StatelessSession; import org.jboss.test.security.interfaces.StatelessSessionHome; import junit.extensions.TestSetup; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import org.jboss.test.util.AppCallbackHandler; import org.jboss.test.JBossTestCase; import org.jboss.test.JBossTestSetup; /** Test of the secure remote password(SRP) service and its usage. @author [EMAIL PROTECTED] @version $Revision: 1.1 $ */ public class SRPUnitTestCase extends JBossTestCase { static final String JAR = "security-srp.sar"; static String username = "scott"; static char[] password = "echoman".toCharArray(); LoginContext lc; boolean loggedIn; public SRPUnitTestCase(String name) { super(name); } /** Test a login against the SRP service using the SRPLoginModule */ public void testSRPLogin() throws Exception { log.debug("+++ testSRPLogin"); login(); logout(); } /** Test that the echo method argument is encrypted by the SRP session key. */ public void testEchoArgs() throws Exception { log.debug("+++ testEchoArgs"); login(); Object obj = getInitialContext().lookup("srp.StatelessSession"); obj = PortableRemoteObject.narrow(obj, StatelessSessionHome.class); StatelessSessionHome home = (StatelessSessionHome) obj; log.debug("Found StatelessSessionHome"); StatelessSession bean = home.create(); log.debug("Created spec.StatelessSession"); log.debug("Bean.echo('Hello') -> "+bean.echo("Hello")); bean.remove(); logout(); } /** Login as user scott using the conf.name login config or 'srp-test' if conf.name is not defined. */ private void login() throws Exception { login(username, password); } private void login(String username, char[] password) throws Exception { if( loggedIn ) return; lc = null; String confName = System.getProperty("conf.name", "srp-test"); AppCallbackHandler handler = new AppCallbackHandler(username, password); log.debug("Creating LoginContext("+confName+")"); lc = new LoginContext(confName, handler); lc.login(); log.debug("Created LoginContext, subject="+lc.getSubject()); loggedIn = true; } private void logout() throws Exception { if( loggedIn ) { loggedIn = false; lc.logout(); } } /** * Setup the test suite. */ public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new TestSuite(SRPUnitTestCase.class)); // Create an initializer for the test suite TestSetup wrapper = new JBossTestSetup(suite) { protected void setUp() throws Exception { super.setUp(); deploy(JAR); } protected void tearDown() throws Exception { undeploy(JAR); super.tearDown(); } }; return wrapper; } }
_______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development