jdk/src/share/classes/sun/security/provider/AuthPolicyFile.java
author mullan
Mon, 19 Aug 2013 17:17:17 -0400
changeset 19439 57876ed3c426
child 20754 3d7b2fafc34b
permissions -rw-r--r--
8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode Summary: Move default javax.security.auth.Policy implementation to compact1 profile Reviewed-by: vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19439
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     1
/*
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     4
 *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    10
 *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    15
 * accompanied this code).
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    16
 *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    20
 *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    23
 * questions.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    24
 */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    25
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    26
package sun.security.provider;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    27
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    28
import java.io.*;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    29
import java.lang.reflect.*;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    30
import java.net.URL;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    31
import java.util.*;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    32
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    33
import java.security.AccessController;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    34
import java.security.CodeSource;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    35
import java.security.KeyStore;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    36
import java.security.KeyStoreException;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    37
import java.security.Permission;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    38
import java.security.Permissions;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    39
import java.security.PermissionCollection;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    40
import java.security.Principal;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    41
import java.security.PrivilegedAction;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    42
import java.security.UnresolvedPermission;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    43
import java.security.Security;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    44
import java.security.cert.Certificate;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    45
import java.security.cert.X509Certificate;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    46
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    47
import javax.security.auth.Subject;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    48
import javax.security.auth.PrivateCredentialPermission;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    49
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    50
import sun.security.provider.PolicyParser.GrantEntry;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    51
import sun.security.provider.PolicyParser.PermissionEntry;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    52
import sun.security.provider.PolicyParser.PrincipalEntry;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    53
import sun.security.util.Debug;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    54
import sun.security.util.PolicyUtil;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    55
import sun.security.util.PropertyExpander;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    56
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    57
/**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    58
 * See {@code com.sun.security.auth.PolicyFile} for the class description.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    59
 * This class is necessary in order to support a default
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    60
 * {@code javax.security.auth.Policy} implementation on the compact1 and
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    61
 * compact2 profiles.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    62
 *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    63
 * @deprecated As of JDK 1.4, replaced by
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    64
 *             {@code sun.security.provider.PolicyFile}.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    65
 *             This class is entirely deprecated.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    66
 */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    67
@Deprecated
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    68
public class AuthPolicyFile extends javax.security.auth.Policy {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    69
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    70
    static final ResourceBundle rb =
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    71
        AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    72
            @Override public ResourceBundle run() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    73
                return (ResourceBundle.getBundle
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    74
                        ("sun.security.util.AuthResources"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    75
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    76
        });
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    77
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    78
    private static final Debug debug = Debug.getInstance("policy",
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    79
                                                         "\t[Auth Policy]");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    80
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    81
    private static final String AUTH_POLICY = "java.security.auth.policy";
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    82
    private static final String SECURITY_MANAGER = "java.security.manager";
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    83
    private static final String AUTH_POLICY_URL = "auth.policy.url.";
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    84
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    85
    private Vector<PolicyEntry> policyEntries;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    86
    private Hashtable<Object, Object> aliasMapping;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    87
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    88
    private boolean initialized = false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    89
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    90
    private boolean expandProperties = true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    91
    private boolean ignoreIdentityScope = true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    92
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    93
    // for use with the reflection API
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    94
    private static final Class[] PARAMS = { String.class, String.class};
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    95
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    96
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    97
     * Initializes the Policy object and reads the default policy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    98
     * configuration file(s) into the Policy object.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
    99
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   100
    public AuthPolicyFile() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   101
        // initialize Policy if either the AUTH_POLICY or
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   102
        // SECURITY_MANAGER properties are set
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   103
        String prop = System.getProperty(AUTH_POLICY);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   104
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   105
        if (prop == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   106
            prop = System.getProperty(SECURITY_MANAGER);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   107
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   108
        if (prop != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   109
            init();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   110
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   111
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   112
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   113
    private synchronized void init() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   114
        if (initialized) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   115
            return;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   116
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   117
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   118
        policyEntries = new Vector<PolicyEntry>();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   119
        aliasMapping = new Hashtable<Object, Object>(11);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   120
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   121
        initPolicyFile();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   122
        initialized = true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   123
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   124
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   125
    @Override
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   126
    public synchronized void refresh() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   127
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   128
        java.lang.SecurityManager sm = System.getSecurityManager();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   129
        if (sm != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   130
            sm.checkPermission(new javax.security.auth.AuthPermission
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   131
                                ("refreshPolicy"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   132
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   133
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   134
        // XXX
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   135
        //
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   136
        // 1)   if code instantiates PolicyFile directly, then it will need
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   137
        //      all the permissions required for the PolicyFile initialization
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   138
        // 2)   if code calls Policy.getPolicy, then it simply needs
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   139
        //      AuthPermission(getPolicy), and the javax.security.auth.Policy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   140
        //      implementation instantiates PolicyFile in a doPrivileged block
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   141
        // 3)   if after instantiating a Policy (either via #1 or #2),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   142
        //      code calls refresh, it simply needs
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   143
        //      AuthPermission(refreshPolicy).  then PolicyFile wraps
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   144
        //      the refresh in a doPrivileged block.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   145
        initialized = false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   146
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   147
            @Override public Void run() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   148
                init();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   149
                return null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   150
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   151
        });
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   152
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   153
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   154
    private KeyStore initKeyStore(URL policyUrl, String keyStoreName,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   155
                                  String keyStoreType) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   156
        if (keyStoreName != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   157
            try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   158
                /*
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   159
                 * location of keystore is specified as absolute URL in policy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   160
                 * file, or is relative to URL of policy file
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   161
                 */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   162
                URL keyStoreUrl = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   163
                try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   164
                    keyStoreUrl = new URL(keyStoreName);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   165
                    // absolute URL
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   166
                } catch (java.net.MalformedURLException e) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   167
                    // relative URL
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   168
                    keyStoreUrl = new URL(policyUrl, keyStoreName);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   169
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   170
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   171
                if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   172
                    debug.println("reading keystore"+keyStoreUrl);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   173
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   174
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   175
                InputStream inStream = new BufferedInputStream(
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   176
                    PolicyUtil.getInputStream(keyStoreUrl));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   177
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   178
                KeyStore ks;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   179
                if (keyStoreType != null)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   180
                    ks = KeyStore.getInstance(keyStoreType);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   181
                else
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   182
                    ks = KeyStore.getInstance(KeyStore.getDefaultType());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   183
                ks.load(inStream, null);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   184
                inStream.close();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   185
                return ks;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   186
            } catch (Exception e) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   187
                // ignore, treat it like we have no keystore
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   188
                if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   189
                    e.printStackTrace();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   190
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   191
                return null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   192
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   193
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   194
        return null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   195
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   196
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   197
    private void initPolicyFile() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   198
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   199
        String prop = Security.getProperty("policy.expandProperties");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   200
        if (prop != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   201
            expandProperties = prop.equalsIgnoreCase("true");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   202
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   203
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   204
        String iscp = Security.getProperty("policy.ignoreIdentityScope");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   205
        if (iscp != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   206
            ignoreIdentityScope = iscp.equalsIgnoreCase("true");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   207
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   208
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   209
        String allowSys = Security.getProperty("policy.allowSystemProperty");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   210
        if (allowSys != null && allowSys.equalsIgnoreCase("true")) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   211
            String extra_policy = System.getProperty(AUTH_POLICY);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   212
            if (extra_policy != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   213
                boolean overrideAll = false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   214
                if (extra_policy.startsWith("=")) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   215
                    overrideAll = true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   216
                    extra_policy = extra_policy.substring(1);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   217
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   218
                try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   219
                    extra_policy = PropertyExpander.expand(extra_policy);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   220
                    URL policyURL;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   221
                    File policyFile = new File(extra_policy);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   222
                    if (policyFile.exists()) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   223
                        policyURL =
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   224
                            new URL("file:" + policyFile.getCanonicalPath());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   225
                    } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   226
                        policyURL = new URL(extra_policy);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   227
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   228
                    if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   229
                        debug.println("reading " + policyURL);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   230
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   231
                    init(policyURL);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   232
                } catch (Exception e) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   233
                    // ignore.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   234
                    if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   235
                        debug.println("caught exception: " + e);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   236
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   237
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   238
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   239
                if (overrideAll) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   240
                    if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   241
                        debug.println("overriding other policies!");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   242
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   243
                    return;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   244
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   245
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   246
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   247
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   248
        int n = 1;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   249
        boolean loaded_one = false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   250
        String policy_url;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   251
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   252
        while ((policy_url = Security.getProperty(AUTH_POLICY_URL+n)) != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   253
            try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   254
                policy_url = PropertyExpander.expand(policy_url).replace
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   255
                                                (File.separatorChar, '/');
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   256
                if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   257
                    debug.println("reading " + policy_url);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   258
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   259
                init(new URL(policy_url));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   260
                loaded_one = true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   261
            } catch (Exception e) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   262
                if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   263
                    debug.println("error reading policy " + e);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   264
                    e.printStackTrace();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   265
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   266
                // ignore that policy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   267
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   268
            n++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   269
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   270
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   271
        if (loaded_one == false) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   272
            // do not load a static policy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   273
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   274
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   275
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   276
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   277
     * Checks public key. If it is marked as trusted in
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   278
     * the identity database, add it to the policy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   279
     * with the AllPermission.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   280
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   281
    private boolean checkForTrustedIdentity(final Certificate cert) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   282
        return false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   283
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   284
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   285
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   286
     * Reads a policy configuration into the Policy object using a
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   287
     * Reader object.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   288
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   289
     * @param policyFile the policy Reader object.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   290
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   291
    private void init(URL policy) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   292
        PolicyParser pp = new PolicyParser(expandProperties);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   293
        try (InputStreamReader isr
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   294
                = new InputStreamReader(PolicyUtil.getInputStream(policy))) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   295
            pp.read(isr);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   296
            KeyStore keyStore = initKeyStore(policy, pp.getKeyStoreUrl(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   297
                                             pp.getKeyStoreType());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   298
            Enumeration<GrantEntry> enum_ = pp.grantElements();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   299
            while (enum_.hasMoreElements()) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   300
                GrantEntry ge = enum_.nextElement();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   301
                addGrantEntry(ge, keyStore);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   302
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   303
        } catch (PolicyParser.ParsingException pe) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   304
            System.err.println(AUTH_POLICY +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   305
                               rb.getString(".error.parsing.") + policy);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   306
            System.err.println(AUTH_POLICY + rb.getString("COLON") +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   307
                               pe.getMessage());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   308
            if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   309
                pe.printStackTrace();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   310
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   311
        } catch (Exception e) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   312
            if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   313
                debug.println("error parsing " + policy);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   314
                debug.println(e.toString());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   315
                e.printStackTrace();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   316
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   317
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   318
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   319
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   320
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   321
     * Given a PermissionEntry, create a codeSource.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   322
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   323
     * @return null if signedBy alias is not recognized
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   324
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   325
    CodeSource getCodeSource(GrantEntry ge, KeyStore keyStore)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   326
            throws java.net.MalformedURLException
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   327
    {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   328
        Certificate[] certs = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   329
        if (ge.signedBy != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   330
            certs = getCertificates(keyStore, ge.signedBy);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   331
            if (certs == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   332
                // we don't have a key for this alias,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   333
                // just return
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   334
                if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   335
                    debug.println(" no certs for alias " +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   336
                                       ge.signedBy + ", ignoring.");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   337
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   338
                return null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   339
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   340
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   341
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   342
        URL location;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   343
        if (ge.codeBase != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   344
            location = new URL(ge.codeBase);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   345
        } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   346
            location = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   347
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   348
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   349
        if (ge.principals == null || ge.principals.size() == 0) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   350
            return (canonicalizeCodebase
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   351
                        (new CodeSource(location, certs),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   352
                        false));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   353
        } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   354
            return (canonicalizeCodebase
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   355
                (new SubjectCodeSource(null, ge.principals, location, certs),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   356
                false));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   357
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   358
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   359
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   360
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   361
     * Add one policy entry to the vector.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   362
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   363
    private void addGrantEntry(GrantEntry ge, KeyStore keyStore) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   364
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   365
        if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   366
            debug.println("Adding policy entry: ");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   367
            debug.println("  signedBy " + ge.signedBy);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   368
            debug.println("  codeBase " + ge.codeBase);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   369
            if (ge.principals != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   370
                for (PrincipalEntry pppe : ge.principals) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   371
                    debug.println("  " + pppe.getPrincipalClass() +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   372
                                        " " + pppe.getPrincipalName());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   373
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   374
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   375
            debug.println();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   376
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   377
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   378
        try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   379
            CodeSource codesource = getCodeSource(ge, keyStore);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   380
            // skip if signedBy alias was unknown...
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   381
            if (codesource == null) return;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   382
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   383
            PolicyEntry entry = new PolicyEntry(codesource);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   384
            Enumeration<PermissionEntry> enum_ = ge.permissionElements();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   385
            while (enum_.hasMoreElements()) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   386
                PermissionEntry pe = enum_.nextElement();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   387
                try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   388
                    // XXX special case PrivateCredentialPermission-SELF
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   389
                    Permission perm;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   390
                    if (pe.permission.equals
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   391
                        ("javax.security.auth.PrivateCredentialPermission") &&
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   392
                        pe.name.endsWith(" self")) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   393
                        perm = getInstance(pe.permission,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   394
                                         pe.name + " \"self\"",
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   395
                                         pe.action);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   396
                    } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   397
                        perm = getInstance(pe.permission,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   398
                                         pe.name,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   399
                                         pe.action);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   400
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   401
                    entry.add(perm);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   402
                    if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   403
                        debug.println("  "+perm);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   404
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   405
                } catch (ClassNotFoundException cnfe) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   406
                    Certificate certs[];
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   407
                    if (pe.signedBy != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   408
                        certs = getCertificates(keyStore, pe.signedBy);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   409
                    } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   410
                        certs = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   411
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   412
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   413
                    // only add if we had no signer or we had a
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   414
                    // a signer and found the keys for it.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   415
                    if (certs != null || pe.signedBy == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   416
                            Permission perm = new UnresolvedPermission(
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   417
                                             pe.permission,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   418
                                             pe.name,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   419
                                             pe.action,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   420
                                             certs);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   421
                            entry.add(perm);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   422
                            if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   423
                                debug.println("  "+perm);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   424
                            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   425
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   426
                } catch (java.lang.reflect.InvocationTargetException ite) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   427
                    System.err.println
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   428
                        (AUTH_POLICY +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   429
                        rb.getString(".error.adding.Permission.") +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   430
                        pe.permission +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   431
                        rb.getString("SPACE") +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   432
                        ite.getTargetException());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   433
                } catch (Exception e) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   434
                    System.err.println
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   435
                        (AUTH_POLICY +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   436
                        rb.getString(".error.adding.Permission.") +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   437
                        pe.permission +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   438
                        rb.getString("SPACE") +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   439
                        e);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   440
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   441
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   442
            policyEntries.addElement(entry);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   443
        } catch (Exception e) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   444
            System.err.println
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   445
                (AUTH_POLICY +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   446
                rb.getString(".error.adding.Entry.") +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   447
                ge +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   448
                rb.getString("SPACE") +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   449
                e);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   450
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   451
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   452
        if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   453
            debug.println();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   454
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   455
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   456
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   457
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   458
     * Returns a new Permission object of the given Type. The Permission is
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   459
     * created by getting the
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   460
     * Class object using the <code>Class.forName</code> method, and using
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   461
     * the reflection API to invoke the (String name, String actions)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   462
     * constructor on the
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   463
     * object.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   464
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   465
     * @param type the type of Permission being created.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   466
     * @param name the name of the Permission being created.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   467
     * @param actions the actions of the Permission being created.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   468
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   469
     * @exception  ClassNotFoundException  if the particular Permission
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   470
     *             class could not be found.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   471
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   472
     * @exception  IllegalAccessException  if the class or initializer is
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   473
     *               not accessible.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   474
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   475
     * @exception  InstantiationException  if getInstance tries to
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   476
     *               instantiate an abstract class or an interface, or if the
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   477
     *               instantiation fails for some other reason.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   478
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   479
     * @exception  NoSuchMethodException if the (String, String) constructor
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   480
     *               is not found.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   481
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   482
     * @exception  InvocationTargetException if the underlying Permission
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   483
     *               constructor throws an exception.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   484
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   485
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   486
    private static final Permission getInstance(String type,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   487
                                    String name,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   488
                                    String actions)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   489
        throws ClassNotFoundException,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   490
               InstantiationException,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   491
               IllegalAccessException,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   492
               NoSuchMethodException,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   493
               InvocationTargetException
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   494
    {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   495
        //XXX we might want to keep a hash of created factories...
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   496
        Class<?> pc = Class.forName(type);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   497
        Constructor<?> c = pc.getConstructor(PARAMS);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   498
        return (Permission) c.newInstance(new Object[] { name, actions });
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   499
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   500
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   501
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   502
     * Fetch all certs associated with this alias.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   503
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   504
    Certificate[] getCertificates(KeyStore keyStore, String aliases) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   505
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   506
        Vector<Certificate> vcerts = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   507
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   508
        StringTokenizer st = new StringTokenizer(aliases, ",");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   509
        int n = 0;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   510
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   511
        while (st.hasMoreTokens()) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   512
            String alias = st.nextToken().trim();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   513
            n++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   514
            Certificate cert = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   515
            // See if this alias's cert has already been cached
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   516
            cert = (Certificate) aliasMapping.get(alias);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   517
            if (cert == null && keyStore != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   518
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   519
                try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   520
                    cert = keyStore.getCertificate(alias);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   521
                } catch (KeyStoreException kse) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   522
                    // never happens, because keystore has already been loaded
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   523
                    // when we call this
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   524
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   525
                if (cert != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   526
                    aliasMapping.put(alias, cert);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   527
                    aliasMapping.put(cert, alias);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   528
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   529
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   530
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   531
            if (cert != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   532
                if (vcerts == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   533
                    vcerts = new Vector<Certificate>();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   534
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   535
                vcerts.addElement(cert);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   536
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   537
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   538
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   539
        // make sure n == vcerts.size, since we are doing a logical *and*
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   540
        if (vcerts != null && n == vcerts.size()) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   541
            Certificate[] certs = new Certificate[vcerts.size()];
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   542
            vcerts.copyInto(certs);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   543
            return certs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   544
        } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   545
            return null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   546
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   547
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   548
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   549
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   550
     * Enumerate all the entries in the global policy object.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   551
     * This method is used by policy admin tools.   The tools
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   552
     * should use the Enumeration methods on the returned object
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   553
     * to fetch the elements sequentially.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   554
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   555
    private final synchronized Enumeration<PolicyEntry> elements() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   556
        return policyEntries.elements();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   557
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   558
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   559
    @Override
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   560
    public PermissionCollection getPermissions(final Subject subject,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   561
                                               final CodeSource codesource) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   562
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   563
        // 1)   if code instantiates PolicyFile directly, then it will need
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   564
        //      all the permissions required for the PolicyFile initialization
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   565
        // 2)   if code calls Policy.getPolicy, then it simply needs
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   566
        //      AuthPermission(getPolicy), and the javax.security.auth.Policy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   567
        //      implementation instantiates PolicyFile in a doPrivileged block
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   568
        // 3)   if after instantiating a Policy (either via #1 or #2),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   569
        //      code calls getPermissions, PolicyFile wraps the call
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   570
        //      in a doPrivileged block.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   571
        return AccessController.doPrivileged
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   572
            (new PrivilegedAction<PermissionCollection>() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   573
            @Override public PermissionCollection run() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   574
                SubjectCodeSource scs = new SubjectCodeSource(
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   575
                    subject, null,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   576
                    codesource == null ? null : codesource.getLocation(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   577
                    codesource == null ? null : codesource.getCertificates());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   578
                if (initialized) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   579
                    return getPermissions(new Permissions(), scs);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   580
                } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   581
                    return new PolicyPermissions(AuthPolicyFile.this, scs);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   582
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   583
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   584
        });
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   585
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   586
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   587
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   588
     * Examines the global policy for the specified CodeSource, and
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   589
     * creates a PermissionCollection object with
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   590
     * the set of permissions for that principal's protection domain.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   591
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   592
     * @param CodeSource the codesource associated with the caller.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   593
     * This encapsulates the original location of the code (where the code
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   594
     * came from) and the public key(s) of its signer.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   595
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   596
     * @return the set of permissions according to the policy.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   597
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   598
    PermissionCollection getPermissions(CodeSource codesource) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   599
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   600
        if (initialized) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   601
            return getPermissions(new Permissions(), codesource);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   602
        } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   603
            return new PolicyPermissions(this, codesource);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   604
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   605
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   606
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   607
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   608
     * Examines the global policy for the specified CodeSource, and
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   609
     * creates a PermissionCollection object with
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   610
     * the set of permissions for that principal's protection domain.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   611
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   612
     * @param permissions the permissions to populate
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   613
     * @param codesource the codesource associated with the caller.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   614
     * This encapsulates the original location of the code (where the code
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   615
     * came from) and the public key(s) of its signer.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   616
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   617
     * @return the set of permissions according to the policy.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   618
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   619
    Permissions getPermissions(final Permissions perms,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   620
                               final CodeSource cs)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   621
    {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   622
        if (!initialized) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   623
            init();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   624
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   625
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   626
        final CodeSource codesource[] = {null};
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   627
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   628
        codesource[0] = canonicalizeCodebase(cs, true);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   629
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   630
        if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   631
            debug.println("evaluate(" + codesource[0] + ")\n");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   632
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   633
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   634
        // needs to be in a begin/endPrivileged block because
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   635
        // codesource.implies calls URL.equals which does an
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   636
        // InetAddress lookup
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   637
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   638
        for (int i = 0; i < policyEntries.size(); i++) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   639
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   640
           PolicyEntry entry = policyEntries.elementAt(i);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   641
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   642
           if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   643
                debug.println("PolicyFile CodeSource implies: " +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   644
                              entry.codesource.toString() + "\n\n" +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   645
                              "\t" + codesource[0].toString() + "\n\n");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   646
           }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   647
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   648
           if (entry.codesource.implies(codesource[0])) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   649
               for (int j = 0; j < entry.permissions.size(); j++) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   650
                    Permission p = entry.permissions.elementAt(j);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   651
                    if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   652
                        debug.println("  granting " + p);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   653
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   654
                    if (!addSelfPermissions(p, entry.codesource,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   655
                                            codesource[0], perms)) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   656
                        // we could check for duplicates
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   657
                        // before adding new permissions,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   658
                        // but the SubjectDomainCombiner
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   659
                        // already checks for duplicates later
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   660
                        perms.add(p);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   661
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   662
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   663
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   664
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   665
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   666
        // now see if any of the keys are trusted ids.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   667
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   668
        if (!ignoreIdentityScope) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   669
            Certificate certs[] = codesource[0].getCertificates();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   670
            if (certs != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   671
                for (int k=0; k < certs.length; k++) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   672
                    if (aliasMapping.get(certs[k]) == null &&
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   673
                        checkForTrustedIdentity(certs[k])) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   674
                        // checkForTrustedIdentity added it
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   675
                        // to the policy for us. next time
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   676
                        // around we'll find it. This time
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   677
                        // around we need to add it.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   678
                        perms.add(new java.security.AllPermission());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   679
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   680
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   681
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   682
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   683
        return perms;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   684
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   685
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   686
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   687
     * Returns true if 'Self' permissions were added to the provided
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   688
     * 'perms', and false otherwise.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   689
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   690
     * <p>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   691
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   692
     * @param p check to see if this Permission is a "SELF"
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   693
     *                  PrivateCredentialPermission. <p>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   694
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   695
     * @param entryCs the codesource for the Policy entry.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   696
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   697
     * @param accCs the codesource for from the current AccessControlContext.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   698
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   699
     * @param perms the PermissionCollection where the individual
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   700
     *                  PrivateCredentialPermissions will be added.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   701
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   702
    private boolean addSelfPermissions(final Permission p,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   703
                                       CodeSource entryCs,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   704
                                       CodeSource accCs,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   705
                                       Permissions perms) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   706
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   707
        if (!(p instanceof PrivateCredentialPermission)) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   708
            return false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   709
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   710
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   711
        if (!(entryCs instanceof SubjectCodeSource)) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   712
            return false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   713
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   714
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   715
        PrivateCredentialPermission pcp = (PrivateCredentialPermission)p;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   716
        SubjectCodeSource scs = (SubjectCodeSource)entryCs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   717
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   718
        // see if it is a SELF permission
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   719
        String[][] pPrincipals = pcp.getPrincipals();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   720
        if (pPrincipals.length <= 0 ||
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   721
            !pPrincipals[0][0].equalsIgnoreCase("self") ||
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   722
            !pPrincipals[0][1].equalsIgnoreCase("self")) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   723
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   724
            // regular PrivateCredentialPermission
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   725
            return false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   726
        } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   727
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   728
            // granted a SELF permission - create a
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   729
            // PrivateCredentialPermission for each
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   730
            // of the Policy entry's CodeSource Principals
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   731
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   732
            if (scs.getPrincipals() == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   733
                // XXX SubjectCodeSource has no Subject???
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   734
                return true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   735
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   736
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   737
            for (PrincipalEntry principal : scs.getPrincipals()) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   738
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   739
                //      if the Policy entry's Principal does not contain a
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   740
                //              WILDCARD for the Principal name, then a
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   741
                //              new PrivateCredentialPermission is created
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   742
                //              for the Principal listed in the Policy entry.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   743
                //      if the Policy entry's Principal contains a WILDCARD
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   744
                //              for the Principal name, then a new
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   745
                //              PrivateCredentialPermission is created
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   746
                //              for each Principal associated with the Subject
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   747
                //              in the current ACC.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   748
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   749
                String[][] principalInfo = getPrincipalInfo(principal, accCs);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   750
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   751
                for (int i = 0; i < principalInfo.length; i++) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   752
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   753
                    // here's the new PrivateCredentialPermission
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   754
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   755
                    PrivateCredentialPermission newPcp =
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   756
                        new PrivateCredentialPermission
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   757
                                (pcp.getCredentialClass() +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   758
                                        " " +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   759
                                        principalInfo[i][0] +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   760
                                        " " +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   761
                                        "\"" + principalInfo[i][1] + "\"",
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   762
                                "read");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   763
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   764
                    if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   765
                        debug.println("adding SELF permission: " +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   766
                                        newPcp.toString());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   767
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   768
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   769
                    perms.add(newPcp);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   770
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   771
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   772
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   773
        return true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   774
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   775
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   776
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   777
     * return the principal class/name pair in the 2D array.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   778
     * array[x][y]:     x corresponds to the array length.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   779
     *                  if (y == 0), it's the principal class.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   780
     *                  if (y == 1), it's the principal name.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   781
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   782
    private String[][] getPrincipalInfo(PrincipalEntry principal,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   783
                                        final CodeSource accCs) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   784
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   785
        // there are 3 possibilities:
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   786
        // 1) the entry's Principal class and name are not wildcarded
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   787
        // 2) the entry's Principal name is wildcarded only
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   788
        // 3) the entry's Principal class and name are wildcarded
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   789
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   790
        if (!principal.getPrincipalClass().equals
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   791
                (PrincipalEntry.WILDCARD_CLASS) &&
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   792
            !principal.getPrincipalName().equals
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   793
                (PrincipalEntry.WILDCARD_NAME)) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   794
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   795
            // build a PrivateCredentialPermission for the principal
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   796
            // from the Policy entry
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   797
            String[][] info = new String[1][2];
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   798
            info[0][0] = principal.getPrincipalClass();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   799
            info[0][1] = principal.getPrincipalName();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   800
            return info;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   801
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   802
        } else if (!principal.getPrincipalClass().equals
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   803
                (PrincipalEntry.WILDCARD_CLASS) &&
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   804
            principal.getPrincipalName().equals
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   805
                (PrincipalEntry.WILDCARD_NAME)) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   806
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   807
            // build a PrivateCredentialPermission for all
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   808
            // the Subject's principals that are instances of principalClass
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   809
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   810
            // the accCs is guaranteed to be a SubjectCodeSource
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   811
            // because the earlier CodeSource.implies succeeded
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   812
            SubjectCodeSource scs = (SubjectCodeSource)accCs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   813
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   814
            Set<? extends Principal> principalSet = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   815
            try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   816
                // principal.principalClass should extend Principal
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   817
                // If it doesn't, we should stop here with a ClassCastException.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   818
                @SuppressWarnings("unchecked")
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   819
                Class<? extends Principal> pClass = (Class<? extends Principal>)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   820
                        Class.forName(principal.getPrincipalClass(), false,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   821
                                      ClassLoader.getSystemClassLoader());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   822
                principalSet = scs.getSubject().getPrincipals(pClass);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   823
            } catch (Exception e) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   824
                if (debug != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   825
                    debug.println("problem finding Principal Class " +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   826
                                  "when expanding SELF permission: " +
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   827
                                  e.toString());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   828
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   829
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   830
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   831
            if (principalSet == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   832
                // error
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   833
                return new String[0][0];
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   834
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   835
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   836
            String[][] info = new String[principalSet.size()][2];
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   837
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   838
            int i = 0;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   839
            for (Principal p : principalSet) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   840
                info[i][0] = p.getClass().getName();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   841
                info[i][1] = p.getName();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   842
                i++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   843
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   844
            return info;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   845
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   846
        } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   847
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   848
            // build a PrivateCredentialPermission for every
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   849
            // one of the current Subject's principals
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   850
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   851
            // the accCs is guaranteed to be a SubjectCodeSource
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   852
            // because the earlier CodeSource.implies succeeded
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   853
            SubjectCodeSource scs = (SubjectCodeSource)accCs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   854
            Set<Principal> principalSet = scs.getSubject().getPrincipals();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   855
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   856
            String[][] info = new String[principalSet.size()][2];
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   857
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   858
            int i = 0;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   859
            for (Principal p : principalSet) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   860
                info[i][0] = p.getClass().getName();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   861
                info[i][1] = p.getName();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   862
                i++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   863
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   864
            return info;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   865
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   866
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   867
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   868
    /*
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   869
     * Returns the signer certificates from the list of certificates associated
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   870
     * with the given code source.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   871
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   872
     * The signer certificates are those certificates that were used to verify
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   873
     * signed code originating from the codesource location.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   874
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   875
     * This method assumes that in the given code source, each signer
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   876
     * certificate is followed by its supporting certificate chain
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   877
     * (which may be empty), and that the signer certificate and its
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   878
     * supporting certificate chain are ordered bottom-to-top (i.e., with the
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   879
     * signer certificate first and the (root) certificate authority last).
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   880
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   881
    Certificate[] getSignerCertificates(CodeSource cs) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   882
        Certificate[] certs = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   883
        if ((certs = cs.getCertificates()) == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   884
            return null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   885
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   886
        for (int i = 0; i < certs.length; i++) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   887
            if (!(certs[i] instanceof X509Certificate))
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   888
                return cs.getCertificates();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   889
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   890
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   891
        // Do we have to do anything?
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   892
        int i = 0;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   893
        int count = 0;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   894
        while (i < certs.length) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   895
            count++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   896
            while (((i+1) < certs.length)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   897
                   && ((X509Certificate)certs[i]).getIssuerDN().equals(
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   898
                           ((X509Certificate)certs[i+1]).getSubjectDN())) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   899
                i++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   900
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   901
            i++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   902
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   903
        if (count == certs.length) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   904
            // Done
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   905
            return certs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   906
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   907
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   908
        ArrayList<Certificate> userCertList = new ArrayList<>();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   909
        i = 0;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   910
        while (i < certs.length) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   911
            userCertList.add(certs[i]);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   912
            while (((i+1) < certs.length)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   913
                   && ((X509Certificate)certs[i]).getIssuerDN().equals(
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   914
                           ((X509Certificate)certs[i+1]).getSubjectDN())) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   915
                i++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   916
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   917
            i++;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   918
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   919
        Certificate[] userCerts = new Certificate[userCertList.size()];
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   920
        userCertList.toArray(userCerts);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   921
        return userCerts;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   922
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   923
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   924
    private CodeSource canonicalizeCodebase(CodeSource cs,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   925
                                            boolean extractSignerCerts) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   926
        CodeSource canonCs = cs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   927
        if (cs.getLocation() != null &&
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   928
            cs.getLocation().getProtocol().equalsIgnoreCase("file")) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   929
            try {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   930
                String path = cs.getLocation().getFile().replace
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   931
                                                        ('/',
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   932
                                                        File.separatorChar);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   933
                URL csUrl = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   934
                if (path.endsWith("*")) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   935
                    // remove trailing '*' because it causes canonicalization
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   936
                    // to fail on win32
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   937
                    path = path.substring(0, path.length()-1);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   938
                    boolean appendFileSep = false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   939
                    if (path.endsWith(File.separator)) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   940
                        appendFileSep = true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   941
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   942
                    if (path.equals("")) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   943
                        path = System.getProperty("user.dir");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   944
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   945
                    File f = new File(path);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   946
                    path = f.getCanonicalPath();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   947
                    StringBuffer sb = new StringBuffer(path);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   948
                    // reappend '*' to canonicalized filename (note that
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   949
                    // canonicalization may have removed trailing file
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   950
                    // separator, so we have to check for that, too)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   951
                    if (!path.endsWith(File.separator) &&
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   952
                        (appendFileSep || f.isDirectory())) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   953
                        sb.append(File.separatorChar);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   954
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   955
                    sb.append('*');
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   956
                    path = sb.toString();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   957
                } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   958
                    path = new File(path).getCanonicalPath();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   959
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   960
                csUrl = new File(path).toURL();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   961
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   962
                if (cs instanceof SubjectCodeSource) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   963
                    SubjectCodeSource scs = (SubjectCodeSource)cs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   964
                    if (extractSignerCerts) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   965
                        canonCs = new SubjectCodeSource(scs.getSubject(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   966
                                                        scs.getPrincipals(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   967
                                                        csUrl,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   968
                                                        getSignerCertificates(scs));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   969
                    } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   970
                        canonCs = new SubjectCodeSource(scs.getSubject(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   971
                                                        scs.getPrincipals(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   972
                                                        csUrl,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   973
                                                        scs.getCertificates());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   974
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   975
                } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   976
                    if (extractSignerCerts) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   977
                        canonCs = new CodeSource(csUrl,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   978
                                                 getSignerCertificates(cs));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   979
                    } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   980
                        canonCs = new CodeSource(csUrl,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   981
                                                 cs.getCertificates());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   982
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   983
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   984
            } catch (IOException ioe) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   985
                // leave codesource as it is, unless we have to extract its
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   986
                // signer certificates
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   987
                if (extractSignerCerts) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   988
                    if (!(cs instanceof SubjectCodeSource)) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   989
                        canonCs = new CodeSource(cs.getLocation(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   990
                                                getSignerCertificates(cs));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   991
                    } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   992
                        SubjectCodeSource scs = (SubjectCodeSource)cs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   993
                        canonCs = new SubjectCodeSource(scs.getSubject(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   994
                                                scs.getPrincipals(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   995
                                                scs.getLocation(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   996
                                                getSignerCertificates(scs));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   997
                    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   998
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
   999
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1000
        } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1001
            if (extractSignerCerts) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1002
                if (!(cs instanceof SubjectCodeSource)) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1003
                    canonCs = new CodeSource(cs.getLocation(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1004
                                        getSignerCertificates(cs));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1005
                } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1006
                    SubjectCodeSource scs = (SubjectCodeSource)cs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1007
                    canonCs = new SubjectCodeSource(scs.getSubject(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1008
                                        scs.getPrincipals(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1009
                                        scs.getLocation(),
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1010
                                        getSignerCertificates(scs));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1011
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1012
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1013
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1014
        return canonCs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1015
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1016
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1017
    /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1018
     * Each entry in the policy configuration file is represented by a
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1019
     * PolicyEntry object.  <p>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1020
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1021
     * A PolicyEntry is a (CodeSource,Permission) pair.  The
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1022
     * CodeSource contains the (URL, PublicKey) that together identify
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1023
     * where the Java bytecodes come from and who (if anyone) signed
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1024
     * them.  The URL could refer to localhost.  The URL could also be
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1025
     * null, meaning that this policy entry is given to all comers, as
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1026
     * long as they match the signer field.  The signer could be null,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1027
     * meaning the code is not signed. <p>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1028
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1029
     * The Permission contains the (Type, Name, Action) triplet. <p>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1030
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1031
     * For now, the Policy object retrieves the public key from the
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1032
     * X.509 certificate on disk that corresponds to the signedBy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1033
     * alias specified in the Policy config file.  For reasons of
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1034
     * efficiency, the Policy object keeps a hashtable of certs already
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1035
     * read in.  This could be replaced by a secure internal key
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1036
     * store.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1037
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1038
     * <p>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1039
     * For example, the entry
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1040
     * <pre>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1041
     *          permission java.io.File "/tmp", "read,write",
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1042
     *          signedBy "Duke";
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1043
     * </pre>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1044
     * is represented internally
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1045
     * <pre>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1046
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1047
     * FilePermission f = new FilePermission("/tmp", "read,write");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1048
     * PublicKey p = publickeys.get("Duke");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1049
     * URL u = InetAddress.getLocalHost();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1050
     * CodeBase c = new CodeBase( p, u );
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1051
     * pe = new PolicyEntry(f, c);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1052
     * </pre>
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1053
     *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1054
     * @author Marianne Mueller
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1055
     * @author Roland Schemers
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1056
     * @see java.security.CodeSource
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1057
     * @see java.security.Policy
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1058
     * @see java.security.Permissions
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1059
     * @see java.security.ProtectionDomain
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1060
     */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1061
    private static class PolicyEntry {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1062
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1063
        CodeSource codesource;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1064
        Vector<Permission> permissions;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1065
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1066
        /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1067
         * Given a Permission and a CodeSource, create a policy entry.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1068
         *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1069
         * XXX Decide if/how to add validity fields and "purpose" fields to
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1070
         * XXX policy entries
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1071
         *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1072
         * @param cs the CodeSource, which encapsulates the URL and the public
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1073
         *        key attributes from the policy config file. Validity checks
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1074
         *        are performed on the public key before PolicyEntry is called.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1075
         *
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1076
         */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1077
        PolicyEntry(CodeSource cs) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1078
            this.codesource = cs;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1079
            this.permissions = new Vector<Permission>();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1080
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1081
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1082
        /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1083
         * add a Permission object to this entry.
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1084
         */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1085
        void add(Permission p) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1086
            permissions.addElement(p);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1087
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1088
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1089
        /**
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1090
         * Return the CodeSource for this policy entry
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1091
         */
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1092
        CodeSource getCodeSource() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1093
            return this.codesource;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1094
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1095
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1096
        @Override
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1097
        public String toString(){
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1098
            StringBuffer sb = new StringBuffer();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1099
            sb.append(rb.getString("LPARAM"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1100
            sb.append(getCodeSource());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1101
            sb.append("\n");
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1102
            for (int j = 0; j < permissions.size(); j++) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1103
                Permission p = permissions.elementAt(j);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1104
                sb.append(rb.getString("SPACE"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1105
                sb.append(rb.getString("SPACE"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1106
                sb.append(p);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1107
                sb.append(rb.getString("NEWLINE"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1108
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1109
            sb.append(rb.getString("RPARAM"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1110
            sb.append(rb.getString("NEWLINE"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1111
            return sb.toString();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1112
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1113
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1114
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1115
}
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1116
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1117
@SuppressWarnings("deprecation")
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1118
class PolicyPermissions extends PermissionCollection {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1119
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1120
    private static final long serialVersionUID = -1954188373270545523L;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1121
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1122
    private CodeSource codesource;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1123
    private Permissions perms;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1124
    private AuthPolicyFile policy;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1125
    private boolean notInit; // have we pulled in the policy permissions yet?
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1126
    private Vector<Permission> additionalPerms;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1127
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1128
    PolicyPermissions(AuthPolicyFile policy,
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1129
                      CodeSource codesource)
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1130
    {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1131
        this.codesource = codesource;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1132
        this.policy = policy;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1133
        this.perms = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1134
        this.notInit = true;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1135
        this.additionalPerms = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1136
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1137
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1138
    @Override
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1139
    public void add(Permission permission) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1140
        if (isReadOnly())
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1141
            throw new SecurityException
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1142
            (AuthPolicyFile.rb.getString
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1143
            ("attempt.to.add.a.Permission.to.a.readonly.PermissionCollection"));
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1144
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1145
        if (perms == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1146
            if (additionalPerms == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1147
                additionalPerms = new Vector<Permission>();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1148
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1149
            additionalPerms.add(permission);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1150
        } else {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1151
            perms.add(permission);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1152
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1153
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1154
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1155
    private synchronized void init() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1156
        if (notInit) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1157
            if (perms == null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1158
                perms = new Permissions();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1159
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1160
            if (additionalPerms != null) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1161
                Enumeration<Permission> e = additionalPerms.elements();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1162
                while (e.hasMoreElements()) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1163
                    perms.add(e.nextElement());
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1164
                }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1165
                additionalPerms = null;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1166
            }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1167
            policy.getPermissions(perms, codesource);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1168
            notInit = false;
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1169
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1170
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1171
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1172
    @Override
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1173
    public boolean implies(Permission permission) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1174
        if (notInit) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1175
            init();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1176
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1177
        return perms.implies(permission);
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1178
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1179
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1180
    @Override
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1181
    public Enumeration<Permission> elements() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1182
        if (notInit) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1183
            init();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1184
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1185
        return perms.elements();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1186
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1187
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1188
    @Override
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1189
    public String toString() {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1190
        if (notInit) {
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1191
            init();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1192
        }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1193
        return perms.toString();
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1194
    }
57876ed3c426 8016850: JCK javax.security.auth.Policy tests fail when run in Profiles mode
mullan
parents:
diff changeset
  1195
}