1 /* 2 * Copyright (c) 2016, 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 /** 25 * @test 26 * @bug 8154009 27 * @summary make sure getProviders() doesn't require additional permissions 28 * @run main/othervm/policy=EmptyPolicy.policy GetProviders 29 */ 30 31 import java.security.Provider; 32 import java.security.Security; 33 import java.util.HashMap; 34 import java.util.Map; 35 36 public class GetProviders { 37 38 private static final String serviceAlgFilter = "Signature.SHA1withRSA"; 39 private static final String emptyServAlgFilter = "wrongSig.wrongAlg"; 40 main(String[] args)41 public static void main(String[] args) throws Exception { 42 try { 43 Provider[] providers1 = Security.getProviders(); 44 System.out.println("Amount of providers1: " + providers1.length); 45 46 Provider[] providers2 = Security.getProviders(serviceAlgFilter); 47 System.out.println("Amount of providers2: " + providers2.length); 48 49 Map<String, String> filter = new HashMap<String, String>(); 50 filter.put(serviceAlgFilter, ""); 51 Provider[] providers3 = Security.getProviders(filter); 52 System.out.println("Amount of providers3: " + providers3.length); 53 54 Provider[] emptyProv1 = Security.getProviders(emptyServAlgFilter); 55 if (emptyProv1 != null) { 56 throw new RuntimeException("Empty Filter returned: " + 57 emptyProv1.length + " providers"); 58 } 59 System.out.println("emptyProv1 is empty as expected"); 60 61 Map<String, String> emptyFilter = new HashMap<String, String>(); 62 emptyFilter.put(emptyServAlgFilter, ""); 63 Provider[] emptyProv2 = Security.getProviders(emptyFilter); 64 if (emptyProv2 != null) { 65 throw new RuntimeException("Empty Filter returned: " + 66 emptyProv2.length + " providers"); 67 } 68 System.out.println("emptyProv2 is empty as expected"); 69 70 } catch(ExceptionInInitializerError e) { 71 e.printStackTrace(System.out); 72 throw new RuntimeException("Provider initialization error due to " 73 + e.getCause()); 74 } 75 System.out.println("Test passed"); 76 } 77 78 } 79