Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/*
* BasePolicyWrapper.java
*
* @author Harpreet Singh ([email protected])
* @author Ron Monzillo
* @version
*
* Created on May 23, 2002, 1:56 PM
*/
// Portions Copyright [2018] [Payara Foundation and/or its affiliates]
package com.sun.enterprise.security.provider;
import static java.io.File.separatorChar;
import static java.lang.Boolean.getBoolean;
import static java.lang.System.getSecurityManager;
import static java.security.AccessController.doPrivileged;
import static java.util.logging.Level.FINE;
import static java.util.logging.Level.FINEST;
import static java.util.logging.Level.WARNING;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.Policy;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.security.Security;
import java.util.Enumeration;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.management.MBeanPermission;
import javax.security.jacc.EJBRoleRefPermission;
import javax.security.jacc.PolicyContext;
import javax.security.jacc.PolicyContextException;
import javax.security.jacc.WebResourcePermission;
import javax.security.jacc.WebRoleRefPermission;
import com.sun.enterprise.util.LocalStringManagerImpl;
import com.sun.logging.LogDomains;
import fish.payara.jacc.ContextProvider;
import fish.payara.jacc.JaccConfigurationFactory;
import sun.net.www.ParseUtil;
import sun.security.provider.PolicyFile;
import sun.security.util.PropertyExpander;
import sun.security.util.PropertyExpander.ExpandException;
/**
* This class is a wrapper around the default jdk policy file implementation. BasePolicyWrapper is installed as the JRE
* policy object It multiples policy decisions to the context specific instance of sun.security.provider.PolicyFile.
* Although this Policy provider is implemented using another Policy class, this class is not a "delegating Policy
* provider" as defined by JACC, and as such it SHOULD not be configured using the JACC system property
* javax.security.jacc.policy.provider.
*
* @author Harpreet Singh ([email protected])
* @author Jean-Francois Arcand
* @author Ron Monzillo
*
*/
public class JDKPolicyFileWrapper extends Policy {
private static Logger logger = Logger.getLogger(LogDomains.SECURITY_LOGGER);
private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(JDKPolicyFileWrapper.class);
/**
* This method repeats the policy file loading algorithm of sun.security.provider.Policyfile to determine if the refresh
* resulted in a change to the loaded policy.
*
* Note: For backward compatibility with JAAS 1.0 it loads both java.auth.policy and java.policy. However it is
* recommended that java.auth.policy be not used and the java.policy contain all grant entries including that contain
* principal-based entries.
*
*
*
* This object stores the policy for entire Java runtime, and is the amalgamation of multiple static policy
* configurations that resides in files. The algorithm for locating the policy file(s) and reading their information
* into this Policy object is:
*
*
*
Loop through the java.security.Security properties, policy.url.1, policy.url.2, ...,
* policy.url.X" and auth.policy.url.1, auth.policy.url.2, ..., auth.policy.url.X". These
* properties are set in the Java security properties file, which is located in the file named
* <JAVA_HOME>/lib/security/java.security, where <JAVA_HOME> refers to the directory where the JDK was
* installed. Each property value specifies a URL pointing to a policy file to be loaded. Read in and load
* each policy.
*
* auth.policy.url is supported only for backward compatibility.
*
*
The java.lang.System property java.security.policy may also be set to a URL
* pointing to another policy file (which is the case when a user uses the -D switch at runtime). If this property is
* defined, and its use is allowed by the security property file (the Security property,
* policy.allowSystemProperty is set to true), also load that policy.
*
*
The java.lang.System property java.security.auth.policy may also be set to a URL
* pointing to another policy file (which is the case when a user uses the -D switch at runtime). If this property is
* defined, and its use is allowed by the security property file (the Security property,
* policy.allowSystemProperty is set to true), also load that policy.
*
* java.security.auth.policy is supported only for backward compatibility.
*
* If the java.security.policy or java.security.auth.policy property is defined using "==" (rather than
* "="), then ignore all other specified policies and only load this policy.
*
*/
private static final String POLICY = "java.security.policy";
private static final String POLICY_URL = "policy.url.";
private static final String AUTH_POLICY = "java.security.auth.policy";
private static final String AUTH_POLICY_URL = "auth.policy.url.";
/**
* Name of the system property that effects whether or not application policy objects are forced to refresh whenever the
* default context policy object is refreshed. Normally app policy objects only refresh when their app sepcifc policy
* files have changes. Since app policy objects alos include the rules of the default context; so they should be
* refreshed whenever the default context files are changed, but the algorithm by which a policy module finds its policy
* files is complex; and dependent on configuration; so this force switch is provided to ensure refresh of the app
* contexts (when the performace cost of doing so is acceptable). When this switch is not set, it may be necessary to
* restart the appserver to force changes in the various policy files to be in effect for specific applications.
*/
private static final String FORCE_APP_REFRESH_PROP_NAME = "com.sun.enterprise.security.provider.PolicyWrapper.force_app_refresh";
/**
* Flag to indicate if application specific policy objects are forced to refresh (independent of whether or not their
* app specific policy files have changed).
*/
private static final boolean forceAppRefresh = Boolean.getBoolean(FORCE_APP_REFRESH_PROP_NAME);
private long refreshTime;
// This is the jdk policy file instance
private Policy policy;
private static final String REUSE = "java.security.Policy.supportsReuse";
/**
* Name of the system property to enable detecting and avoiding reentrancy. This property can be set using
* in domain.xml. If not set or set to false, this class will detect or avoid reentrancy in policy evaluation. Note that
* if SecurityManager is turned off, this feature is always turned off. Another design approach is to name the property
* differently and use a list of context ids as its value, so that this feature may be enabled for selected contexts.
*/
private static final String IGNORE_REENTRANCY_PROP_NAME = "com.sun.enterprise.security.provider.PolicyWrapper.ignoreReentrancy";
/**
* Flag to indicate if detecting and avoiding reentrancy is enabled. If SecurityManager is turned off, reentrancy is
* less likely to occur and this feature is always off; else if the system property IGNORE_REENTRANCY_PROP_NAME is not
* set, or set to false in domain.xml, this feature is on;
*
*/
private static final boolean avoidReentrancy = !getBoolean(IGNORE_REENTRANCY_PROP_NAME) && getSecurityManager() != null;
/**
* ThreadLocal object to keep track of the reentrancy status of each thread. It contains a byte[] object whose single
* element is either 0 (initial value or no reentrancy), or 1 (current thread is reentrant). When a thread exists the
* implies method, byte[0] is alwasy reset to 0.
*/
private static ThreadLocal