Path: blob/master/test/jdk/java/security/Security/removing/RemoveProviders.java
41154 views
/*1* Copyright (c) 2003, 2011, 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 4963416 705491826* @library ../../testlibrary27* @summary make sure removeProvider() always works correctly28* @author Andreas Sterbenz29*/3031import java.util.*;3233import java.security.*;3435public class RemoveProviders {3637public static void main(String[] args) throws Exception {38ProvidersSnapshot snapshot = ProvidersSnapshot.create();39try {40main0(args);41} finally {42snapshot.restore();43}44}4546public static void main0(String[] args) throws Exception {47Provider[] providers = Security.getProviders();48System.out.println("Providers: " + Arrays.asList(providers));4950// remove each provider and add it back in at the end of the list51for (int i = 0; i < providers.length; i++) {52Provider p = providers[i];53String name = p.getName();54Security.removeProvider(name);55if (Security.getProvider(name) != null) {56throw new Exception("Provider not removed: " + name);57}58Security.addProvider(p);59}60if (Arrays.equals(providers, Security.getProviders()) == false) {61throw new Exception("Provider mismatch: " + Arrays.asList(Security.getProviders()));62}6364// remove non-existing provider65Security.removeProvider("foo");66if (Arrays.equals(providers, Security.getProviders()) == false) {67throw new Exception("Provider mismatch: " + Arrays.asList(Security.getProviders()));68}6970// remove from the middle of the list71Security.removeProvider("SunJCE");72if (Security.getProvider("SunJCE") != null) {73throw new Exception("not removed");74}7576System.out.println("Done.");77}7879}808182