1 /*
2  * Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 import java.util.jar.*;
25 import java.io.*;
26 
27 public class TestUtil {
28 
29     private boolean isUnlimited;
30     private static TestUtil instance = null;
31 
32     static {
33         instance = new TestUtil();
34     }
35 
TestUtil()36     private TestUtil() {
37         try {
38             isUnlimited = isUnlimitedPolicy();
39         } catch (Exception ex) {
40             RuntimeException re = new RuntimeException
41                 ("Cannot locate the jurisdiction policy files");
42             re.initCause(ex);
43             throw re;
44         }
45     }
46 
isUnlimitedPolicy()47     private static boolean isUnlimitedPolicy() throws IOException {
48         if (instance == null) {
49             String jreDir = System.getProperty("java.home");
50             String localPolicyPath = jreDir + File.separator + "lib" +
51                 File.separator + "security" + File.separator +
52                 "local_policy.jar";
53             JarFile localPolicy = new JarFile(localPolicyPath);
54             if (localPolicy.getEntry("exempt_local.policy") == null) {
55                 return true;
56             } else {
57                 return false;
58             }
59         } else {
60             return instance.isUnlimited;
61         }
62     }
63 
handleSE(SecurityException ex)64     public static void handleSE(SecurityException ex)
65         throws SecurityException {
66         if (instance == null) {
67             instance = new TestUtil();
68         }
69         if ((instance.isUnlimited) ||
70             !(ex.getMessage().startsWith("Unsupported keysize"))) {
71             throw ex;
72         }
73     }
74 }
75