| 1 28 package net.sf.jguard.ext.authentication.loginmodules; 29 30 import java.net.URL ; 31 import java.security.cert.X509Certificate ; 32 import java.util.HashMap ; 33 import java.util.Map ; 34 35 import junit.framework.TestCase; 36 import net.sf.jguard.core.authentication.configuration.JGuardConfiguration; 37 import net.sf.jguard.ext.authentication.manager.AuthenticationManagerFactory; 38 import net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager; 39 import net.sf.jguard.jee.authentication.callbacks.HttpCallbackHandler; 40 import net.sf.jguard.jee.authentication.http.HttpConstants; 41 import net.sf.jguard.jee.authentication.http.HttpServletRequestSimulator; 42 43 import com.kizna.servletunit.HttpServletResponseSimulator; 44 45 public abstract class CertificateBasedTestCase extends TestCase { 46 47 protected JGuardConfiguration configuration = null; 48 protected HttpCallbackHandler cbh = null; 49 protected String myApp = null; 50 protected static final String SKIP_CERTIFICATE_TESTS = "certificate.test.skip"; 51 52 public void setUp()throws Exception { 53 if (!"false".equals(System.getProperty(SKIP_CERTIFICATE_TESTS))) { 54 return; 55 } 56 try { 57 super.setUp(); 58 } catch (Exception e) { 59 System.out.println(e.getMessage()); 60 } 61 62 myApp ="myApp"; 63 Map authNOptions = new HashMap (); 64 URL url = getClass().getResource("/OCSPTestUsersPrincipals.xml"); 65 authNOptions.put("authenticationXmlFileLocation",url.toString()); 66 67 AuthenticationManagerFactory.createAuthenticationManager(XmlAuthenticationManager.class.getName(), authNOptions); 68 HttpServletRequestSimulator request = new HttpServletRequestSimulator(); 69 request.setScheme("https"); 70 request.setSecure(true); 71 X509Certificate [] certificates = new X509Certificate [1]; 72 URL url2 = new URL (url,"superAdmin.der"); 73 X509Certificate certificate = OCSPLoginModule.getCertFromFile(url2.toString()); 74 certificates[0] = certificate; 75 request.setAttribute("javax.servlet.request.X509Certificate", certificates); 76 HttpServletResponseSimulator response = new HttpServletResponseSimulator(); 77 cbh = new HttpCallbackHandler(request, response, HttpConstants.CLIENT_CERT_AUTH); 78 79 80 } 81 82 public JGuardConfiguration getConfiguration() { 83 return configuration; 84 } 85 86 public void setConfiguration(JGuardConfiguration configuration) { 87 this.configuration = configuration; 88 } 89 90 } 91 | Popular Tags |