org.eclipse.osgi.internal.permadmin.PermissionInfoCollection Maven / Gradle / Ivy
The newest version!
/*******************************************************************************
* Copyright (c) 2008, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.osgi.internal.permadmin;
import java.io.File;
import java.lang.reflect.Constructor;
import java.security.*;
import java.util.*;
import org.osgi.service.permissionadmin.PermissionInfo;
public final class PermissionInfoCollection extends PermissionCollection {
private static final long serialVersionUID = 3140511562980923957L;
/* Used to find permission constructors in addPermissions */
static private final Class> twoStringClassArray[] = new Class[] {String.class, String.class};
static private final Class> oneStringClassArray[] = new Class[] {String.class};
static private final Class> noArgClassArray[] = new Class[] {};
static private final Class>[][] permClassArrayArgs = new Class[][] {noArgClassArray, oneStringClassArray, twoStringClassArray};
/* @GuardedBy(cachedPermisssionCollections) */
private final Map, PermissionCollection> cachedPermissionCollections = new HashMap<>();
private final boolean hasAllPermission;
private final PermissionInfo[] permInfos;
public PermissionInfoCollection(PermissionInfo[] permInfos) {
this.permInfos = permInfos;
boolean tempAllPermissions = false;
for (int i = 0; i < permInfos.length && !tempAllPermissions; i++)
if (permInfos[i].getType().equals(AllPermission.class.getName()))
tempAllPermissions = true;
this.hasAllPermission = tempAllPermissions;
setReadOnly(); // collections are managed with ConditionalPermissionAdmin
}
public void add(Permission arg0) {
throw new SecurityException();
}
public Enumeration elements() {
// TODO return an empty enumeration for now;
return BundlePermissions.EMPTY_ENUMERATION;
}
public boolean implies(Permission perm) {
if (hasAllPermission)
return true;
final Class extends Permission> permClass = perm.getClass();
PermissionCollection collection;
synchronized (cachedPermissionCollections) {
collection = cachedPermissionCollections.get(permClass);
}
// must populate the collection outside of the lock to prevent class loader deadlock
if (collection == null) {
collection = perm.newPermissionCollection();
if (collection == null) {
collection = new PermissionsHash();
}
try {
final PermissionCollection targetCollection = collection;
AccessController.doPrivileged(new PrivilegedExceptionAction
© 2015 - 2024 Weber Informatics LLC | Privacy Policy