ProvidersSnapshot.java revision 4359:a015dda3bdc6
1169691Skan/*
2169691Skan * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3169691Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4169691Skan *
5169691Skan * This code is free software; you can redistribute it and/or modify it
6169691Skan * under the terms of the GNU General Public License version 2 only, as
7169691Skan * published by the Free Software Foundation.
8169691Skan *
9169691Skan * This code is distributed in the hope that it will be useful, but WITHOUT
10169691Skan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11169691Skan * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12169691Skan * version 2 for more details (a copy is included in the LICENSE file that
13169691Skan * accompanied this code).
14169691Skan *
15169691Skan * You should have received a copy of the GNU General Public License version
16169691Skan * 2 along with this work; if not, write to the Free Software Foundation,
17169691Skan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18169691Skan *
19169691Skan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20169691Skan * or visit www.oracle.com if you need additional information or have any
21169691Skan * questions.
22169691Skan */
23169691Skan
24169691Skanimport java.security.Provider;
25169691Skanimport java.security.Security;
26169691Skan
27169691Skanpublic class ProvidersSnapshot {
28169691Skan
29169691Skan    private Provider[] oldProviders;
30169691Skan
31169691Skan    private ProvidersSnapshot() {
32169691Skan        oldProviders = Security.getProviders();
33169691Skan    }
34169691Skan
35169691Skan    public static ProvidersSnapshot create() {
36169691Skan        return new ProvidersSnapshot();
37169691Skan    }
38169691Skan
39169691Skan    public void restore() {
40169691Skan        Provider[] newProviders = Security.getProviders();
41169691Skan        for (Provider p: newProviders) {
42169691Skan            Security.removeProvider(p.getName());
43169691Skan        }
44169691Skan        for (Provider p: oldProviders) {
45169691Skan            Security.addProvider(p);
46169691Skan        }
47169691Skan    }
48169691Skan}
49169691Skan