test/jdk/java/security/Security/AddProvider.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 40416 jdk/test/java/security/Security/AddProvider.java@5d91b2fd668c
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19193
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
     1
/*
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 19193
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
19193
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
     4
 *
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
     8
 *
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    13
 * accompanied this code).
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    14
 *
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    18
 *
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    21
 * questions.
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    22
 */
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    23
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    24
/*
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    25
 * @test
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 19193
diff changeset
    26
 * @bug 8001319 8130181
19193
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    27
 * @summary check that SecurityPermission insertProvider permission is enforced
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    28
 *          correctly
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    29
 * @run main/othervm/policy=AddProvider.policy.1 AddProvider 1
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    30
 * @run main/othervm/policy=AddProvider.policy.2 AddProvider 2
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    31
 * @run main/othervm/policy=AddProvider.policy.3 AddProvider 3
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    32
 */
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    33
import java.security.Provider;
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    34
import java.security.Security;
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    35
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    36
public class AddProvider {
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    37
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    39
        boolean legacy = args[0].equals("2");
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    40
        Security.addProvider(new TestProvider("Test1"));
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    41
        Security.insertProviderAt(new TestProvider("Test2"), 1);
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    42
        try {
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    43
            Security.addProvider(new TestProvider("Test3"));
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    44
            if (legacy) {
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    45
                throw new Exception("Expected SecurityException");
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    46
            }
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    47
        } catch (SecurityException se) {
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    48
            if (!legacy) {
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    49
                throw se;
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    50
            }
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    51
        }
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    52
    }
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    53
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    54
    private static class TestProvider extends Provider {
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    55
        TestProvider(String name) {
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 19193
diff changeset
    56
            super(name, "0.0", "Not for use in production systems!");
19193
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    57
        }
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    58
    }
103262cae675 8001319: Add SecurityPermission "insertProvider" target name
mullan
parents:
diff changeset
    59
}