KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jguard > ext > authentication > loginmodules > CertificateBasedTestCase


1 /*
2 jGuard is a security framework based on top of jaas (java authentication and authorization security).
3 it is written for web applications, to resolve simply, access control problems.
4 version $Name: v080beta1 $
5 http://sourceforge.net/projects/jguard/
6
7 Copyright (C) 2004 Charles GAY
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23
24 jGuard project home page:
25 http://sourceforge.net/projects/jguard/
26
27 */

28 package net.sf.jguard.ext.authentication.loginmodules;
29
30 import java.net.URL JavaDoc;
31 import java.security.cert.X509Certificate JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Map JavaDoc;
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 JavaDoc myApp = null;
50     protected static final String JavaDoc SKIP_CERTIFICATE_TESTS = "certificate.test.skip";
51     
52     public void setUp()throws Exception JavaDoc{
53         if (!"false".equals(System.getProperty(SKIP_CERTIFICATE_TESTS))) {
54             return;
55         }
56         try {
57             super.setUp();
58         } catch (Exception JavaDoc e) {
59             System.out.println(e.getMessage());
60         }
61         
62         myApp ="myApp";
63         Map JavaDoc authNOptions = new HashMap JavaDoc();
64         URL JavaDoc 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 JavaDoc[] certificates = new X509Certificate JavaDoc[1];
72         URL JavaDoc url2 = new URL JavaDoc(url,"superAdmin.der");
73         X509Certificate JavaDoc 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