KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > groovy > security > SignedJarTest


1 package groovy.security;
2
3 import junit.framework.Test;
4 import junit.framework.TestSuite;
5 import junit.textui.TestRunner;
6
7
8 /**
9  * Read a .groovy file from a signed jar and verify that a policy file grant with a signedBy field
10  * works. The following steps were used to create and manage the keys used to sign and read the jar:
11  * <ol>
12  * <li>keytool -genkey -alias groovy -keypass keypass -keystore groovystore -storepass storepass -validity 7000
13  * <li>keytool -export -keystore groovystore -alias groovy -file GroovyDev.cer
14  * <li>keytool -import -alias groovy -file GroovyDev.cer -keystore groovykeys
15  * </ol>
16  * Once the keys are constructed, creat the jar and sign:
17  * <ol>
18  * <li>jar -cvf Groovy.jar groovy
19  * <li>jarsigner -keystore groovystore -signedjar GroovyJarTest.jar Groovy.jar groovy
20  * </ol>
21  * Add the keystore to the policy file and write the grant:
22  * <ol>
23  * <li>keystore "file:${user.dir}/src/test/groovy/security/groovykeys";
24  * </ol>
25  */

26 public class SignedJarTest extends SecurityTestSupport {
27
28     public static void main(String JavaDoc[] args) {
29         TestRunner.run( suite() );
30     }
31    
32     public static Test suite() {
33         return new TestSuite(SignedJarTest.class);
34     }
35
36     public void testReadSignedJar() throws Exception JavaDoc {
37         if (!isSecurityAvailable()) {
38             return;
39         }
40         Class JavaDoc c = loader.loadClass("groovy.security.JarTest");
41         executeTest(c, null);
42     }
43 }
44
Popular Tags