jdk/test/java/security/testlibrary/ProvidersSnapshot.java
author jjg
Mon, 25 Nov 2013 17:42:28 -0800
changeset 21894 3535c1819067
parent 10057 03ae05289550
permissions -rw-r--r--
8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10057
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     1
/*
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     4
 *
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     8
 *
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    13
 * accompanied this code).
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    14
 *
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    18
 *
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    21
 * questions.
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    22
 */
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    23
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    24
import java.security.Provider;
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    25
import java.security.Security;
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    26
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    27
public class ProvidersSnapshot {
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    28
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    29
    private Provider[] oldProviders;
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    30
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    31
    private ProvidersSnapshot() {
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    32
        oldProviders = Security.getProviders();
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    33
    }
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    34
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    35
    public static ProvidersSnapshot create() {
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    36
        return new ProvidersSnapshot();
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    37
    }
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    38
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    39
    public void restore() {
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    40
        Provider[] newProviders = Security.getProviders();
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    41
        for (Provider p: newProviders) {
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    42
            Security.removeProvider(p.getName());
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    43
        }
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    44
        for (Provider p: oldProviders) {
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    45
            Security.addProvider(p);
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    46
        }
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    47
    }
03ae05289550 7054918: jdk_security1 test target cleanup
weijun
parents:
diff changeset
    48
}