Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/security/Security/GetProviders.java
38811 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 815400926* @summary make sure getProviders() doesn't require additional permissions27* @run main/othervm/policy=EmptyPolicy.policy GetProviders28*/2930import java.security.Provider;31import java.security.Security;32import java.util.HashMap;33import java.util.Map;3435public class GetProviders {3637private static final String serviceAlgFilter = "Signature.SHA1withRSA";38private static final String emptyServAlgFilter = "wrongSig.wrongAlg";3940public static void main(String[] args) throws Exception {41try {42Provider[] providers1 = Security.getProviders();43System.out.println("Amount of providers1: " + providers1.length);4445Provider[] providers2 = Security.getProviders(serviceAlgFilter);46System.out.println("Amount of providers2: " + providers2.length);4748Map<String, String> filter = new HashMap<String, String>();49filter.put(serviceAlgFilter, "");50Provider[] providers3 = Security.getProviders(filter);51System.out.println("Amount of providers3: " + providers3.length);5253Provider[] emptyProv1 = Security.getProviders(emptyServAlgFilter);54if (emptyProv1 != null) {55throw new RuntimeException("Empty Filter returned: " +56emptyProv1.length + " providers");57}58System.out.println("emptyProv1 is empty as expected");5960Map<String, String> emptyFilter = new HashMap<String, String>();61emptyFilter.put(emptyServAlgFilter, "");62Provider[] emptyProv2 = Security.getProviders(emptyFilter);63if (emptyProv2 != null) {64throw new RuntimeException("Empty Filter returned: " +65emptyProv2.length + " providers");66}67System.out.println("emptyProv2 is empty as expected");6869} catch(ExceptionInInitializerError e) {70e.printStackTrace(System.out);71throw new RuntimeException("Provider initialization error due to "72+ e.getCause());73}74System.out.println("Test passed");75}7677}787980