All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.enterprise.security.ee.PermissionCache Maven / Gradle / Ivy

There is a newer version: 4.1.2.181
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 1997-2012 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.
 */

package com.sun.enterprise.security.ee;

import com.sun.enterprise.security.common.AppservAccessController;
import java.security.CodeSource;
import java.security.AllPermission;
import java.security.Permission;
import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.Policy;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import javax.security.jacc.PolicyContext;
import com.sun.enterprise.security.ee.CachedPermissionImpl.Epoch;

import com.sun.logging.LogDomains;

/**
 * This class is 
 * @author Ron Monzillo
 */

public class PermissionCache extends Object {

    private static Logger _logger = 
    LogDomains.getLogger(PermissionCache.class,LogDomains.SECURITY_LOGGER);
    private static Policy policy = Policy.getPolicy();
    private static AllPermission allPermission = new AllPermission();

    private Permissions cache;
    private CodeSource codesource;
    private Permission[] protoPerms;
    private Class[] classes;
    private String name;
    private String pcID;
    private final Integer factoryKey;
    private volatile int epoch;
    private volatile boolean loading;
    private ReadWriteLock rwLock;
    private Lock rLock;
    private Lock wLock;
 
    /*
     * USE OF THIS CONSTRUCTOR WITH IS DISCOURAGED PLEASE USE THE Permission 
     * (object) based CONSTRUCTOR.
     * @param key -  Integer that uniquely identifies the cache at the factory
     * @param pcID - a string identifying the policy context and which must 
     *     be set when getPermissions is called (internally). this value may be 
     *     null, in which case the permisions of the default policy context
     *     will be cached.
     * @param codesource - the codesource argument to be used in the call to 
     *     getPermissions. this value may be null.
     * @param class - a single Class object that identifies the permission 
     *     type that will be managed by the cache. This value may be 
     *     null. When this argument is not null, only permissions of the 
     *     identified type  or that resolve to the identified type, 
     *     will be managed within the cache. When null is passed to this
     *     argument, permission type will not be a factor in determining
     *     the cached permissions.
     * @param name - a string corresponding to a value returned by 
     *     Permission.getName(). Only permissions whose getName() value 
     *     matches the name parameter will be included in the cache. This value 
     *     may be null, in which case permission name does not factor into
     *     the permission caching.
     */
    public PermissionCache(Integer key, String pcID, CodeSource codesource,
			   Class clazz, String name){
  	if (codesource == null) {
 	    this.codesource = 
 		new CodeSource(null,
 			       (java.security.cert.Certificate[])null);
  	} else {
  	    this.codesource = codesource;
  	}
 	this.factoryKey = key;
  	this.cache  = null;
  	this.pcID = pcID;
 	this.protoPerms = null;
 	if (clazz != null) {
 	    this.classes = new Class[] {clazz};
 	} else {
 	    this.classes = null;
 	}
  	this.name = name;
 	this.epoch = 1;
 	this.loading = false;
 	this.rwLock = new ReentrantReadWriteLock(true);
 	this.rLock = rwLock.readLock();
 	this.wLock = rwLock.writeLock();
    }
  
    /*
     * @param key -  Integer that uniquely identifies the cache at the factory
     * @param pcID - a string identifying the policy context and which must 
     *     be set when getPermissions is called (internally). this value may be 
     *     null, in which case the permisions of the default policy context
     *     will be cached.
     * @param codesource - the codesource argument to be used in the call to 
     *     getPermissions. this value may be null.
     * @param perms - an array of permission objects identifying the 
     *     permission types that will be managed by the cache. This value may be
     *     null. When this argument is not null, only permissions of the types 
     *     passed in the array or that resolve to the types identified in the 
     *     will be managed within the cache. When null is passed to this
     *     argument, permission type will not be a factor in determining the
     *     cached permissions.
     * @param name - a string corresponding to a value returned by 
     *     Permission.getName(). Only permissions whose getName() value 
     *     matches the name parameter will be included in the cache. This value 
     *     may be null, in which case permission name does not factor into
     *     the permission caching.
     */
    public PermissionCache(Integer key, String pcID, CodeSource codesource,
			   Permission[] perms, String name){
 	if (codesource == null) {
 	    this.codesource = 
 		new CodeSource(null,
 			       (java.security.cert.Certificate[])null);
 	} else {
 	    this.codesource = codesource;
 	}
 	this.factoryKey = key;
 	this.cache  = null;
 	this.pcID = pcID;
 	this.protoPerms = perms;
 	if (perms != null && perms.length>0) {
 	    this.classes = new Class[perms.length];
 	    for (int i=0; i 0) {
 	    for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy