diff options
author | Thomas Watson | 2020-01-10 17:31:06 +0000 |
---|---|---|
committer | Thomas Watson | 2020-01-10 17:31:06 +0000 |
commit | 80382b413f30bd86f51e6811f8beb7ebddcca3f9 (patch) | |
tree | f213717727914ac5d55308743740af0a9331bc6c | |
parent | ec24686b6d435bf416450932d19ad7fd0317074b (diff) | |
parent | 3e96dadbb9329a4b6acd98e0eabf1ff7ebe09129 (diff) | |
download | rt.equinox.framework-80382b413f30bd86f51e6811f8beb7ebddcca3f9.tar.gz rt.equinox.framework-80382b413f30bd86f51e6811f8beb7ebddcca3f9.tar.xz rt.equinox.framework-80382b413f30bd86f51e6811f8beb7ebddcca3f9.zip |
Merge branch 'master' into osgiR8
17 files changed, 531 insertions, 539 deletions
diff --git a/bundles/org.eclipse.equinox.launcher/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.launcher/META-INF/MANIFEST.MF index 2902a2ad1..a90b09e48 100644 --- a/bundles/org.eclipse.equinox.launcher/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.launcher/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.launcher;singleton:=true -Bundle-Version: 1.5.600.qualifier +Bundle-Version: 1.5.700.qualifier Main-Class: org.eclipse.equinox.launcher.Main Bundle-ClassPath: . Bundle-Vendor: %providerName diff --git a/bundles/org.eclipse.equinox.launcher/pom.xml b/bundles/org.eclipse.equinox.launcher/pom.xml index c0c97ffe9..549a87f53 100644 --- a/bundles/org.eclipse.equinox.launcher/pom.xml +++ b/bundles/org.eclipse.equinox.launcher/pom.xml @@ -19,6 +19,6 @@ </parent> <groupId>org.eclipse.equinox</groupId> <artifactId>org.eclipse.equinox.launcher</artifactId> - <version>1.5.600-SNAPSHOT</version> + <version>1.5.700-SNAPSHOT</version> <packaging>eclipse-plugin</packaging> </project> diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java index bd9d17d00..456943ac4 100644 --- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java +++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java @@ -1287,25 +1287,7 @@ public class Main { } private static boolean canWrite(File installDir) { - if (installDir.canWrite() == false) - return false; - - if (!installDir.isDirectory()) - return false; - - File fileTest = null; - try { - // we use the .dll suffix to properly test on Vista virtual directories - // on Vista you are not allowed to write executable files on virtual directories like "Program Files" - fileTest = File.createTempFile("writableArea", ".dll", installDir); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (IOException e) { - //If an exception occured while trying to create the file, it means that it is not writtable - return false; - } finally { - if (fileTest != null) - fileTest.delete(); - } - return true; + return installDir.isDirectory() && Files.isWritable(installDir.toPath()); } /** diff --git a/bundles/org.eclipse.osgi.tests/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.osgi.tests/.settings/org.eclipse.jdt.core.prefs index 77c9cee27..efb352e27 100644 --- a/bundles/org.eclipse.osgi.tests/.settings/org.eclipse.jdt.core.prefs +++ b/bundles/org.eclipse.osgi.tests/.settings/org.eclipse.jdt.core.prefs @@ -9,8 +9,11 @@ org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullable.secondary= org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate @@ -22,6 +25,7 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.doc.comment.support=enabled org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000 +org.eclipse.jdt.core.compiler.problem.APILeak=warning org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore @@ -68,12 +72,14 @@ org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error org.eclipse.jdt.core.compiler.problem.nullReference=warning org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore @@ -89,22 +95,29 @@ org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning +org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning +org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled +org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedImport=error org.eclipse.jdt.core.compiler.problem.unusedLabel=warning org.eclipse.jdt.core.compiler.problem.unusedLocal=warning diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java index bb9cb8946..1feb04e42 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java @@ -1,26 +1,25 @@ /******************************************************************************* -n -n This program - * and the accompanying materials are made available under the terms of the - * Eclipse Public License 2.0 which accompanies this distribution, and is - * available at + * Copyright (c) 2020 Cognos Incorporated, IBM Corporation and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 which + * accompanies this distribution, and is available at * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - *******************************************************************************/ + ******************************************************************************/ package org.eclipse.equinox.log.test; -import java.util.ArrayList; -import java.util.List; +import java.util.LinkedList; import org.eclipse.equinox.log.ExtendedLogEntry; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.junit.Assert; import org.osgi.service.log.LogEntry; import org.osgi.service.log.LogListener; -class TestListener implements LogListener { +public class TestListener implements LogListener { private final String testBundleLoc; - private List<LogEntry> logs = new ArrayList<>(); + private LinkedList<LogEntry> logs = new LinkedList<>(); public TestListener() { this(null); @@ -45,11 +44,11 @@ class TestListener implements LogListener { public synchronized ExtendedLogEntry getEntryX(long timeToWait) throws InterruptedException { LogEntry logEntry; long startTime = System.currentTimeMillis(); - if (logs.size() == 0 && timeToWait > 0) { + if (logs.isEmpty() && timeToWait > 0) { this.wait(timeToWait); timeToWait = timeToWait - (System.currentTimeMillis() - startTime); } - logEntry = logs.size() == 0 ? null : logs.remove(0); + logEntry = logs.isEmpty() ? null : logs.removeFirst(); if (logEntry == null) { Assert.fail("No log entry logged."); } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index c59b1d8f8..1c459cb66 100755 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2018 IBM Corporation and others. + * Copyright (c) 2008, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -68,6 +68,7 @@ import junit.framework.TestSuite; import org.eclipse.core.runtime.adaptor.EclipseStarter; import org.eclipse.equinox.log.ExtendedLogReaderService; import org.eclipse.equinox.log.ExtendedLogService; +import org.eclipse.equinox.log.test.TestListener; import org.eclipse.equinox.log.test.TestListener2; import org.eclipse.osgi.container.Module; import org.eclipse.osgi.framework.util.FilePath; @@ -116,6 +117,7 @@ import org.osgi.resource.Requirement; import org.osgi.service.log.LogEntry; import org.osgi.service.log.LogLevel; import org.osgi.service.log.LogReaderService; +import org.osgi.service.log.LogService; import org.osgi.service.packageadmin.ExportedPackage; import org.osgi.service.packageadmin.PackageAdmin; import org.osgi.service.startlevel.StartLevel; @@ -3278,7 +3280,7 @@ public class SystemBundleTests extends AbstractBundleTests { } } - public static void doLoggingOnMultipleListeners(Equinox equinox) throws InterruptedException { + static void doLoggingOnMultipleListeners(Equinox equinox) throws InterruptedException { int listenersSize = 100; int logSize = 10000; BundleContext bc = equinox.getBundleContext(); @@ -3311,6 +3313,46 @@ public class SystemBundleTests extends AbstractBundleTests { } } + public void testCaptureLogEntryLocation() throws BundleException, InterruptedException { + doTestCaptureLogEntryLocation(true); + doTestCaptureLogEntryLocation(false); + } + + private void doTestCaptureLogEntryLocation(boolean captureLocation) throws BundleException, InterruptedException { + File config = OSGiTestsActivator.getContext().getDataFile(getName()); //$NON-NLS-1$ + Map configuration = new HashMap(); + configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()); + if (!captureLocation) { + // the default is true; only set for false + configuration.put(EquinoxConfiguration.PROP_LOG_CAPTURE_ENTRY_LOCATION, Boolean.toString(captureLocation)); + } + Equinox equinox = new Equinox(configuration); + try { + equinox.start(); + + BundleContext bc = equinox.getBundleContext(); + LogReaderService logReader = bc.getService(bc.getServiceReference(LogReaderService.class)); + LogService logService = bc.getService(bc.getServiceReference(LogService.class)); + + TestListener listener = new TestListener(Constants.SYSTEM_BUNDLE_LOCATION); + logReader.addLogListener(listener); + + final String testMsg = "TEST MESSAGE"; + logService.getLogger(this.getClass()).error(testMsg); + + LogEntry logEntry = listener.getEntryX(); + assertEquals("Wrong message.", testMsg, logEntry.getMessage()); + if (captureLocation) { + assertNotNull("No location found.", logEntry.getLocation()); + } else { + assertNull("Found location.", logEntry.getLocation()); + } + } finally { + equinox.stop(); + equinox.waitForStop(1000); + } + } + public void testSystemCapabilitiesBug522125() throws URISyntaxException, FileNotFoundException, IOException, BundleException, InterruptedException { String frameworkLocation = OSGiTestsActivator.getContext().getProperty(EquinoxConfiguration.PROP_FRAMEWORK); URI uri = new URI(frameworkLocation); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java index 8b2d82837..58a6fe975 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/securityadmin/SecurityAdminUnitTests.java @@ -46,6 +46,7 @@ import org.osgi.service.condpermadmin.ConditionalPermissionUpdate; import org.osgi.service.permissionadmin.PermissionAdmin; import org.osgi.service.permissionadmin.PermissionInfo; +@SuppressWarnings("deprecation") public class SecurityAdminUnitTests extends AbstractBundleTests { private static final PermissionInfo[] SOCKET_INFOS = new PermissionInfo[] {new PermissionInfo("java.net.SocketPermission", "localhost", "accept")}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -56,6 +57,8 @@ public class SecurityAdminUnitTests extends AbstractBundleTests { new PermissionInfo("java.io.FilePermission", "<<ALL FILES>>", "write") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ }; + private static final PermissionInfo[] RELATIVE_EXEC_FILE_INFOS = new PermissionInfo[] {new PermissionInfo("java.io.FilePermission", "bin/*", "execute")}; + private static final PermissionInfo[] RUNTIME_INFOS = new PermissionInfo[] {new PermissionInfo("java.lang.RuntimePermission", "exitVM", null)}; //$NON-NLS-1$ //$NON-NLS-2$ private static final ConditionInfo[] ALLLOCATION_CONDS = new ConditionInfo[] {new ConditionInfo("org.osgi.service.condpermadmin.BundleLocationCondition", new String[] {"*"})}; //$NON-NLS-1$ //$NON-NLS-2$ @@ -91,27 +94,27 @@ public class SecurityAdminUnitTests extends AbstractBundleTests { private static final long serialVersionUID = 3258131349494708277L; // A simple PermissionCollection that only has AllPermission - @Override + @Override public void add(Permission permission) { //no adding to this policy } - @Override + @Override public boolean implies(Permission permission) { return true; } - @Override + @Override public Enumeration elements() { return new Enumeration() { int cur = 0; - @Override + @Override public boolean hasMoreElements() { return cur < 1; } - @Override + @Override public Object nextElement() { if (cur == 0) { cur = 1; @@ -125,12 +128,12 @@ public class SecurityAdminUnitTests extends AbstractBundleTests { Policy.setPolicy(new Policy() { - @Override + @Override public PermissionCollection getPermissions(CodeSource codesource) { return allPermissions; } - @Override + @Override public void refresh() { // nothing } @@ -1052,15 +1055,115 @@ public class SecurityAdminUnitTests extends AbstractBundleTests { } public void testBug286307() { - Bundle test = installTestBundle("test.bug286307"); //$NON-NLS-1$ + Bundle test = installTestBundle("test.bug286307"); AccessControlContext acc = test.adapt(AccessControlContext.class); - testPermission(acc, new FilePermission("test", "read"), true); //$NON-NLS-1$ //$NON-NLS-2$ + testPermission(acc, new FilePermission("test", "read"), true); + testPermission(acc, new AllPermission(), false); + } + + public void testRelativeFilePermission() { + Bundle test = installTestBundle(TEST_BUNDLE); + File dataArea = test.getDataFile(""); + File testFile = new File(dataArea, "testFile.txt"); + File testExecutable = new File(dataArea, "bin/execFile"); + AccessControlContext acc = test.adapt(AccessControlContext.class); + + // test set by location + pa.setPermissions(test.getLocation(), RELATIVE_EXEC_FILE_INFOS); + + testPermission(acc, new FilePermission(testFile.getPath(), "write"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "read"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "execute"), false); + testPermission(acc, new FilePermission(testExecutable.getPath(), "write"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "read"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "execute"), true); testPermission(acc, new AllPermission(), false); + + // clear location + pa.setPermissions(test.getLocation(), null); + // goes back to all permission by default + testPermission(acc, new FilePermission(testFile.getPath(), "write"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "read"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "execute"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "write"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "read"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "execute"), true); + testPermission(acc, new AllPermission(), true); + + // test set by conditions + ConditionalPermissionUpdate update = cpa.newConditionalPermissionUpdate(); + List rows = update.getConditionalPermissionInfos(); + rows.add(cpa.newConditionalPermissionInfo(null, getLocationConditions(test.getLocation(), false), RELATIVE_EXEC_FILE_INFOS, ConditionalPermissionInfo.ALLOW)); + assertTrue("failed to commit", update.commit()); + + testPermission(acc, new FilePermission(testFile.getPath(), "write"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "read"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "execute"), false); + testPermission(acc, new FilePermission(testExecutable.getPath(), "write"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "read"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "execute"), true); + testPermission(acc, new AllPermission(), false); + + // update condition to only have read only, not that a bundle always + // implicitly has r/w permission to its data area + update = cpa.newConditionalPermissionUpdate(); + rows = update.getConditionalPermissionInfos(); + rows.clear(); + rows.add(cpa.newConditionalPermissionInfo(null, getLocationConditions(test.getLocation(), false), READONLY_INFOS, ConditionalPermissionInfo.ALLOW)); + assertTrue("failed to commit", update.commit()); + + testPermission(acc, new FilePermission(testFile.getPath(), "write"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "read"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "execute"), false); + testPermission(acc, new FilePermission(testExecutable.getPath(), "write"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "read"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "execute"), false); + testPermission(acc, new AllPermission(), false); + + // clear the conditions + update = cpa.newConditionalPermissionUpdate(); + update.getConditionalPermissionInfos().clear(); + assertTrue("failed to commit", update.commit()); + + // test that the default permissions of PA do not handle relative + pa.setDefaultPermissions(RELATIVE_EXEC_FILE_INFOS); + + testPermission(acc, new FilePermission(testFile.getPath(), "write"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "read"), true); + testPermission(acc, new FilePermission(testFile.getPath(), "execute"), false); + testPermission(acc, new FilePermission(testExecutable.getPath(), "write"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "read"), true); + testPermission(acc, new FilePermission(testExecutable.getPath(), "execute"), false); + testPermission(acc, new AllPermission(), false); + + // go back to default all permission + pa.setDefaultPermissions(null); + testPermission(acc, new AllPermission(), true); + + // Test that the ACC returned from CPA.getAccessControlContext does not handle relative file permissions + update = cpa.newConditionalPermissionUpdate(); + rows = update.getConditionalPermissionInfos(); + rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] {SIGNER_CONDITION1}, RELATIVE_EXEC_FILE_INFOS, ConditionalPermissionInfo.ALLOW)); + assertTrue("failed to commit", update.commit()); + + File relativeExecutable = new File("bin/executableFile"); + acc = cpa.getAccessControlContext(new String[] {"cn=t1,c=FR;cn=test1,c=US"}); + testPermission(acc, new FilePermission(relativeExecutable.getAbsolutePath(), "execute"), false); + + // update CPA to use absolute path + update = cpa.newConditionalPermissionUpdate(); + rows = update.getConditionalPermissionInfos(); + rows.clear(); + PermissionInfo[] absExectInfos = new PermissionInfo[] {new PermissionInfo("java.io.FilePermission", relativeExecutable.getAbsolutePath(), "execute")}; + rows.add(cpa.newConditionalPermissionInfo(null, new ConditionInfo[] {SIGNER_CONDITION1}, absExectInfos, ConditionalPermissionInfo.ALLOW)); + assertTrue("failed to commit", update.commit()); + + testPermission(acc, new FilePermission(relativeExecutable.getAbsolutePath(), "execute"), true); } private void checkInfos(ConditionalPermissionInfo testInfo1, ConditionalPermissionInfo testInfo2) { - assertTrue("Infos are not equal: " + testInfo1.getEncoded() + " " + testInfo2.getEncoded(), testInfo1.equals(testInfo2)); //$NON-NLS-1$ //$NON-NLS-2$ - assertEquals("Info hash code is not equal", testInfo1.hashCode(), testInfo2.hashCode()); //$NON-NLS-1$ + assertTrue("Infos are not equal: " + testInfo1.getEncoded() + " " + testInfo2.getEncoded(), testInfo1.equals(testInfo2)); + assertEquals("Info hash code is not equal", testInfo1.hashCode(), testInfo2.hashCode()); } private void checkBadInfo(String encoded) { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java index c08e80025..da2fb2dfa 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2019 IBM Corporation and others. + * Copyright (c) 2003, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -223,6 +223,7 @@ public class EquinoxConfiguration implements EnvironmentInfo { public static final String PROP_MODULE_AUTO_START_ON_RESOLVE = "osgi.module.auto.start.on.resolve"; //$NON-NLS-1$ public static final String PROP_ALLOW_RESTRICTED_PROVIDES = "osgi.equinox.allow.restricted.provides"; //$NON-NLS-1$ public static final String PROP_LOG_HISTORY_MAX = "equinox.log.history.max"; //$NON-NLS-1$ + public static final String PROP_LOG_CAPTURE_ENTRY_LOCATION = "equinox.log.capture.entry.location"; //$NON-NLS-1$ @Deprecated public static final String PROP_RESOLVER_THREAD_COUNT = "equinox.resolver.thead.count"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java index f718ea1fe..c9f574709 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/FilterImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2019 IBM Corporation and others. + * Copyright (c) 2003, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -466,146 +466,112 @@ public abstract class FilterImpl implements Filter { } } - static final class Present extends FilterImpl { - /** debug mode */ - final boolean debug; - private final String attr; - - Present(String attr, boolean debug) { - this.attr = attr; - this.debug = debug; - } - - @Override - boolean matches0(Map<String, ?> map) { - if (debug) { - Debug.println("PRESENT(" + attr + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - } - return map.get(attr) != null; - } - - @Override - StringBuilder normalize(StringBuilder sb) { - return sb.append('(').append(attr).append('=').append('*').append(')'); - } - - @Override - void getAttributesInternal(List<String> results) { - results.add(attr); - } - - @Override - void addAttributes(Map<String, String> attributes, Map<String, Range> versionAttrs, boolean not) { - attributes.put(attr, "*"); //$NON-NLS-1$ - } - } - static abstract class Item extends FilterImpl { /** debug mode */ final boolean debug; final String attr; - final Object value; - Item(String attr, Object value, boolean debug) { + Item(String attr, boolean debug) { this.attr = attr; - this.value = value; this.debug = debug; } @Override boolean matches0(Map<String, ?> map) { - return compare(map.get(attr), value); + return compare(map.get(attr)); } abstract String operation(); - private boolean compare(Object value1, Object value2) { + abstract String value(); + + private boolean compare(Object value1) { if (debug) { if (value1 == null) { - Debug.println("compare(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println("compare(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } else if (!(value1.getClass().isArray() || (value1 instanceof Collection<?>))) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } if (value1 == null) { return false; } if (value1 instanceof String) { - return compare_String((String) value1, value2); + return compare_String((String) value1); } if (value1 instanceof Version) { - return compare_Version((Version) value1, value2); + return compare_Version((Version) value1); } Class<?> clazz = value1.getClass(); if (clazz.isArray()) { Class<?> type = clazz.getComponentType(); if (type.isPrimitive()) { - return compare_PrimitiveArray(type, value1, value2); + return compare_PrimitiveArray(type, value1); } - return compare_ObjectArray((Object[]) value1, value2); + return compare_ObjectArray((Object[]) value1); } if (value1 instanceof Collection<?>) { - return compare_Collection((Collection<?>) value1, value2); + return compare_Collection((Collection<?>) value1); } if (value1 instanceof Integer) { - return compare_Integer(((Integer) value1).intValue(), value2); + return compare_Integer(((Integer) value1).intValue()); } if (value1 instanceof Long) { - return compare_Long(((Long) value1).longValue(), value2); + return compare_Long(((Long) value1).longValue()); } if (value1 instanceof Byte) { - return compare_Byte(((Byte) value1).byteValue(), value2); + return compare_Byte(((Byte) value1).byteValue()); } if (value1 instanceof Short) { - return compare_Short(((Short) value1).shortValue(), value2); + return compare_Short(((Short) value1).shortValue()); } if (value1 instanceof Character) { - return compare_Character(((Character) value1).charValue(), value2); + return compare_Character(((Character) value1).charValue()); } if (value1 instanceof Float) { - return compare_Float(((Float) value1).floatValue(), value2); + return compare_Float(((Float) value1).floatValue()); } if (value1 instanceof Double) { - return compare_Double(((Double) value1).doubleValue(), value2); + return compare_Double(((Double) value1).doubleValue()); } if (value1 instanceof Boolean) { - return compare_Boolean(((Boolean) value1).booleanValue(), value2); + return compare_Boolean(((Boolean) value1).booleanValue()); } if (value1 instanceof Comparable<?>) { @SuppressWarnings("unchecked") Comparable<Object> comparable = (Comparable<Object>) value1; - return compare_Comparable(comparable, value2); + return compare_Comparable(comparable); } - return compare_Unknown(value1, value2); + return compare_Unknown(value1); } - private boolean compare_Collection(Collection<?> collection, Object value2) { + private boolean compare_Collection(Collection<?> collection) { for (Object value1 : collection) { - if (compare(value1, value2)) { + if (compare(value1)) { return true; } } return false; } - private boolean compare_ObjectArray(Object[] array, Object value2) { + private boolean compare_ObjectArray(Object[] array) { for (Object value1 : array) { - if (compare(value1, value2)) { + if (compare(value1)) { return true; } } return false; } - private boolean compare_PrimitiveArray(Class<?> type, Object primarray, Object value2) { + private boolean compare_PrimitiveArray(Class<?> type, Object primarray) { if (Integer.TYPE.isAssignableFrom(type)) { int[] array = (int[]) primarray; for (int value1 : array) { if (debug) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - if (compare_Integer(value1, value2)) { + if (compare_Integer(value1)) { return true; } } @@ -615,9 +581,9 @@ public abstract class FilterImpl implements Filter { long[] array = (long[]) primarray; for (long value1 : array) { if (debug) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - if (compare_Long(value1, value2)) { + if (compare_Long(value1)) { return true; } } @@ -627,9 +593,9 @@ public abstract class FilterImpl implements Filter { byte[] array = (byte[]) primarray; for (byte value1 : array) { if (debug) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - if (compare_Byte(value1, value2)) { + if (compare_Byte(value1)) { return true; } } @@ -639,9 +605,9 @@ public abstract class FilterImpl implements Filter { short[] array = (short[]) primarray; for (short value1 : array) { if (debug) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - if (compare_Short(value1, value2)) { + if (compare_Short(value1)) { return true; } } @@ -651,9 +617,9 @@ public abstract class FilterImpl implements Filter { char[] array = (char[]) primarray; for (char value1 : array) { if (debug) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - if (compare_Character(value1, value2)) { + if (compare_Character(value1)) { return true; } } @@ -663,9 +629,9 @@ public abstract class FilterImpl implements Filter { float[] array = (float[]) primarray; for (float value1 : array) { if (debug) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - if (compare_Float(value1, value2)) { + if (compare_Float(value1)) { return true; } } @@ -675,9 +641,9 @@ public abstract class FilterImpl implements Filter { double[] array = (double[]) primarray; for (double value1 : array) { if (debug) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - if (compare_Double(value1, value2)) { + if (compare_Double(value1)) { return true; } } @@ -687,9 +653,9 @@ public abstract class FilterImpl implements Filter { boolean[] array = (boolean[]) primarray; for (boolean value1 : array) { if (debug) { - Debug.println(operation() + "(" + value1 + "," + value2 + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Debug.println(operation() + "(" + value1 + "," + value() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } - if (compare_Boolean(value1, value2)) { + if (compare_Boolean(value1)) { return true; } } @@ -698,51 +664,51 @@ public abstract class FilterImpl implements Filter { return false; } - boolean compare_String(String string, Object value2) { + boolean compare_String(String string) { return false; } - boolean compare_Version(Version value1, Object value2) { + boolean compare_Version(Version value1) { return false; } - boolean compare_Comparable(Comparable<Object> value1, Object value2) { + boolean compare_Comparable(Comparable<Object> value1) { return false; } - boolean compare_Unknown(Object value1, Object value2) { + boolean compare_Unknown(Object value1) { return false; } - boolean compare_Boolean(boolean boolval, Object value2) { + boolean compare_Boolean(boolean boolval) { return false; } - boolean compare_Byte(byte byteval, Object value2) { + boolean compare_Byte(byte byteval) { return false; } - boolean compare_Character(char charval, Object value2) { + boolean compare_Character(char charval) { return false; } - boolean compare_Double(double doubleval, Object value2) { + boolean compare_Double(double doubleval) { return false; } - boolean compare_Float(float floatval, Object value2) { + boolean compare_Float(float floatval) { return false; } - boolean compare_Integer(int intval, Object value2) { + boolean compare_Integer(int intval) { return false; } - boolean compare_Long(long longval, Object value2) { + boolean compare_Long(long longval) { return false; } - boolean compare_Short(short shortval, Object value2) { + boolean compare_Short(short shortval) { return false; } @@ -774,62 +740,47 @@ public abstract class FilterImpl implements Filter { results.add(attr); } - static Object valueOf(Class<?> target, String value2) { - do { - Method method; - try { - method = target.getMethod("valueOf", String.class); //$NON-NLS-1$ - } catch (NoSuchMethodException e) { - break; - } - if (Modifier.isStatic(method.getModifiers()) && target.isAssignableFrom(method.getReturnType())) { - setAccessible(method); - try { - return method.invoke(null, value2.trim()); - } catch (Error e) { - throw e; - } catch (Throwable e) { - return null; - } - } - } while (false); - - do { - Constructor<?> constructor; - try { - constructor = target.getConstructor(String.class); - } catch (NoSuchMethodException e) { - break; - } - setAccessible(constructor); - try { - return constructor.newInstance(value2.trim()); - } catch (Error e) { - throw e; - } catch (Throwable e) { - return null; - } - } while (false); + @Override + void addAttributes(Map<String, String> attributes, Map<String, Range> versionAttrs, boolean not) { + attributes.put(attr, value()); + } + } - return null; + static final class Present extends Item { + Present(String attr, boolean debug) { + super(attr, debug); } - private static void setAccessible(final AccessibleObject accessible) { - if (!accessible.isAccessible()) { - AccessController.doPrivileged(new PrivilegedAction<Void>() { - @Override - public Void run() { - accessible.setAccessible(true); - return null; - } - }); + @Override + boolean matches0(Map<String, ?> map) { + if (debug) { + Debug.println("PRESENT(" + attr + ")"); //$NON-NLS-1$ //$NON-NLS-2$ } + return map.get(attr) != null; + } + + @Override + String operation() { + return "PRESENT"; //$NON-NLS-1$ + } + + @Override + String value() { + return "*"; //$NON-NLS-1$ + } + + @Override + StringBuilder normalize(StringBuilder sb) { + return sb.append('(').append(attr).append('=').append('*').append(')'); } } static final class Substring extends Item { - Substring(String attr, Object value, boolean debug) { - super(attr, value, debug); + final String[] substrings; + + Substring(String attr, String[] substrings, boolean debug) { + super(attr, debug); + this.substrings = substrings; } @Override @@ -838,8 +789,12 @@ public abstract class FilterImpl implements Filter { } @Override - boolean compare_String(String string, Object value2) { - String[] substrings = (String[]) value2; + String value() { + return value(new StringBuilder()).toString(); + } + + @Override + boolean compare_String(String string) { int pos = 0; for (int i = 0, size = substrings.length; i < size; i++) { String substr = substrings[i]; @@ -896,7 +851,6 @@ public abstract class FilterImpl implements Filter { } private StringBuilder value(StringBuilder sb) { - String[] substrings = (String[]) value; for (String substr : substrings) { if (substr == null) /* * */ { sb.append('*'); @@ -906,16 +860,14 @@ public abstract class FilterImpl implements Filter { } return sb; } - - @Override - void addAttributes(Map<String, String> attributes, Map<String, Range> versionAttrs, boolean not) { - attributes.put(attr, value(new StringBuilder()).toString()); - } } static class Equal extends Item { - Equal(String attr, Object value, boolean debug) { - super(attr, value, debug); + final String value; + + Equal(String attr, String value, boolean debug) { + super(attr, debug); + this.value = value; } @Override @@ -924,15 +876,24 @@ public abstract class FilterImpl implements Filter { } @Override - boolean compare_String(String string, Object value2) { - return string.equals(value2); + String value() { + return value; + } + + boolean comparison(int compare) { + return compare == 0; + } + + @Override + boolean compare_String(String string) { + return comparison((string == value) ? 0 : string.compareTo(value)); } @Override - boolean compare_Version(Version value1, Object value2) { + boolean compare_Version(Version value1) { try { - Version version2 = Version.valueOf((String) value2); - return value1.compareTo(version2) == 0; + Version version2 = Version.valueOf(value); + return comparison(value1.compareTo(version2)); } catch (Exception e) { // if the valueOf or compareTo method throws an exception return false; @@ -940,85 +901,96 @@ public abstract class FilterImpl implements Filter { } @Override - boolean compare_Boolean(boolean boolval, Object value2) { - return boolval == Boolean.valueOf(((String) value2).trim()).booleanValue(); + boolean compare_Boolean(boolean boolval) { + boolean boolval2 = Boolean.parseBoolean(value.trim()); + return comparison(Boolean.compare(boolval, boolval2)); } @Override - boolean compare_Byte(byte byteval, Object value2) { + boolean compare_Byte(byte byteval) { + byte byteval2; try { - return byteval == Byte.parseByte(((String) value2).trim()); + byteval2 = Byte.parseByte(value.trim()); } catch (IllegalArgumentException e) { return false; } + return comparison(Byte.compare(byteval, byteval2)); } @Override - boolean compare_Character(char charval, Object value2) { + boolean compare_Character(char charval) { + char charval2; try { - return charval == ((String) value2).charAt(0); + charval2 = value.charAt(0); } catch (IndexOutOfBoundsException e) { return false; } + return comparison(Character.compare(charval, charval2)); } @Override - boolean compare_Double(double doubleval, Object value2) { + boolean compare_Double(double doubleval) { double doubleval2; try { - doubleval2 = Double.parseDouble(((String) value2).trim()); + doubleval2 = Double.parseDouble(value.trim()); } catch (IllegalArgumentException e) { return false; } - return Double.compare(doubleval, doubleval2) == 0; + return comparison(Double.compare(doubleval, doubleval2)); } @Override - boolean compare_Float(float floatval, Object value2) { + boolean compare_Float(float floatval) { float floatval2; try { - floatval2 = Float.parseFloat(((String) value2).trim()); + floatval2 = Float.parseFloat(value.trim()); } catch (IllegalArgumentException e) { return false; } - return Float.compare(floatval, floatval2) == 0; + return comparison(Float.compare(floatval, floatval2)); } @Override - boolean compare_Integer(int intval, Object value2) { + boolean compare_Integer(int intval) { + int intval2; try { - return intval == Integer.parseInt(((String) value2).trim()); + intval2 = Integer.parseInt(value.trim()); } catch (IllegalArgumentException e) { return false; } + return comparison(Integer.compare(intval, intval2)); } @Override - boolean compare_Long(long longval, Object value2) { + boolean compare_Long(long longval) { + long longval2; try { - return longval == Long.parseLong(((String) value2).trim()); + longval2 = Long.parseLong(value.trim()); } catch (IllegalArgumentException e) { return false; } + return comparison(Long.compare(longval, longval2)); } @Override - boolean compare_Short(short shortval, Object value2) { + boolean compare_Short(short shortval) { + short shortval2; try { - return shortval == Short.parseShort(((String) value2).trim()); + shortval2 = Short.parseShort(value.trim()); } catch (IllegalArgumentException e) { return false; } + return comparison(Short.compare(shortval, shortval2)); } @Override - boolean compare_Comparable(Comparable<Object> value1, Object value2) { - value2 = valueOf(value1.getClass(), (String) value2); + boolean compare_Comparable(Comparable<Object> value1) { + Object value2 = valueOf(value1.getClass()); if (value2 == null) { return false; } try { - return value1.compareTo(value2) == 0; + return comparison(value1.compareTo(value2)); } catch (Exception e) { // if the compareTo method throws an exception; return false return false; @@ -1026,8 +998,8 @@ public abstract class FilterImpl implements Filter { } @Override - boolean compare_Unknown(Object value1, Object value2) { - value2 = valueOf(value1.getClass(), (String) value2); + boolean compare_Unknown(Object value1) { + Object value2 = valueOf(value1.getClass()); if (value2 == null) { return false; } @@ -1042,13 +1014,65 @@ public abstract class FilterImpl implements Filter { @Override StringBuilder normalize(StringBuilder sb) { sb.append('(').append(attr).append('='); - return encodeValue(sb, (String) value).append(')'); + return encodeValue(sb, value).append(')'); + } + + Object valueOf(Class<?> target) { + do { + Method method; + try { + method = target.getMethod("valueOf", String.class); //$NON-NLS-1$ + } catch (NoSuchMethodException e) { + break; + } + if (Modifier.isStatic(method.getModifiers()) && target.isAssignableFrom(method.getReturnType())) { + setAccessible(method); + try { + return method.invoke(null, value.trim()); + } catch (Error e) { + throw e; + } catch (Throwable e) { + return null; + } + } + } while (false); + + do { + Constructor<?> constructor; + try { + constructor = target.getConstructor(String.class); + } catch (NoSuchMethodException e) { + break; + } + setAccessible(constructor); + try { + return constructor.newInstance(value.trim()); + } catch (Error e) { + throw e; + } catch (Throwable e) { + return null; + } + } while (false); + + return null; + } + + private static void setAccessible(final AccessibleObject accessible) { + if (!accessible.isAccessible()) { + AccessController.doPrivileged(new PrivilegedAction<Void>() { + @Override + public Void run() { + accessible.setAccessible(true); + return null; + } + }); + } } @Override public String getPrimaryKeyValue(String primaryKey) { - if (attr.equalsIgnoreCase(primaryKey) && (value instanceof String)) { - return (String) value; + if (attr.equalsIgnoreCase(primaryKey)) { + return value; } return null; } @@ -1056,7 +1080,7 @@ public abstract class FilterImpl implements Filter { @Override void addAttributes(Map<String, String> attributes, Map<String, Range> versionAttrs, boolean not) { if (!versionAttrs.containsKey(attr)) { - attributes.put(attr, (String) value); + attributes.put(attr, value); } else { // this is an exact range e.g. [value,value] Range currentRange = versionAttrs.get(attr); @@ -1064,13 +1088,13 @@ public abstract class FilterImpl implements Filter { if (not) { // this is an expanded form of the filter, e.g.: // [1.0,2.0) -> (&(version>=1.0)(version<=2.0)(!(version=2.0))) - currentRange.addExclude(Version.valueOf((String) value)); + currentRange.addExclude(Version.valueOf(value)); } else { throw new IllegalStateException("Invalid range for: " + attr); //$NON-NLS-1$ } } else { currentRange = new Range(); - Version version = Version.valueOf((String) value); + Version version = Version.valueOf(value); currentRange.setLeft('[', version); currentRange.setRight(']', version); versionAttrs.put(attr, currentRange); @@ -1079,8 +1103,8 @@ public abstract class FilterImpl implements Filter { } } - static final class Less extends Equal { - Less(String attr, Object value, boolean debug) { + static final class LessEqual extends Equal { + LessEqual(String attr, String value, boolean debug) { super(attr, value, debug); } @@ -1090,106 +1114,14 @@ public abstract class FilterImpl implements Filter { } @Override - boolean compare_String(String string, Object value2) { - return string.compareTo((String) value2) <= 0; - } - - @Override - boolean compare_Version(Version value1, Object value2) { - try { - Version version2 = Version.valueOf((String) value2); - return value1.compareTo(version2) <= 0; - } catch (Exception e) { - // if the valueOf or compareTo method throws an exception - return false; - } - } - - @Override - boolean compare_Byte(byte byteval, Object value2) { - try { - return byteval <= Byte.parseByte(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - } - - @Override - boolean compare_Character(char charval, Object value2) { - try { - return charval <= ((String) value2).charAt(0); - } catch (IndexOutOfBoundsException e) { - return false; - } - } - - @Override - boolean compare_Double(double doubleval, Object value2) { - double doubleval2; - try { - doubleval2 = Double.parseDouble(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - return Double.compare(doubleval, doubleval2) <= 0; - } - - @Override - boolean compare_Float(float floatval, Object value2) { - float floatval2; - try { - floatval2 = Float.parseFloat(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - return Float.compare(floatval, floatval2) <= 0; - } - - @Override - boolean compare_Integer(int intval, Object value2) { - try { - return intval <= Integer.parseInt(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - } - - @Override - boolean compare_Long(long longval, Object value2) { - try { - return longval <= Long.parseLong(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - } - - @Override - boolean compare_Short(short shortval, Object value2) { - try { - return shortval <= Short.parseShort(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - } - - @Override - boolean compare_Comparable(Comparable<Object> value1, Object value2) { - value2 = valueOf(value1.getClass(), (String) value2); - if (value2 == null) { - return false; - } - try { - return value1.compareTo(value2) <= 0; - } catch (Exception e) { - // if the compareTo method throws an exception; return false - return false; - } + boolean comparison(int compare) { + return compare <= 0; } @Override StringBuilder normalize(StringBuilder sb) { sb.append('(').append(attr).append('<').append('='); - return encodeValue(sb, (String) value).append(')'); + return encodeValue(sb, value).append(')'); } @Override @@ -1214,20 +1146,20 @@ public abstract class FilterImpl implements Filter { } if (not) { // this must be a range start "(value" - if (!currentRange.setLeft('(', Version.valueOf((String) value))) { + if (!currentRange.setLeft('(', Version.valueOf(value))) { throw new IllegalStateException("range start is already processed for attribute: " + attr); //$NON-NLS-1$ } } else { // this must be a range end "value]" - if (!currentRange.setRight(']', Version.valueOf((String) value))) { + if (!currentRange.setRight(']', Version.valueOf(value))) { throw new IllegalStateException("range end is already processed for attribute: " + attr); //$NON-NLS-1$ } } } } - static final class Greater extends Equal { - Greater(String attr, Object value, boolean debug) { + static final class GreaterEqual extends Equal { + GreaterEqual(String attr, String value, boolean debug) { super(attr, value, debug); } @@ -1237,106 +1169,14 @@ public abstract class FilterImpl implements Filter { } @Override - boolean compare_String(String string, Object value2) { - return string.compareTo((String) value2) >= 0; - } - - @Override - boolean compare_Version(Version value1, Object value2) { - try { - Version version2 = Version.valueOf((String) value2); - return value1.compareTo(version2) >= 0; - } catch (Exception e) { - // if the valueOf or compareTo method throws an exception - return false; - } - } - - @Override - boolean compare_Byte(byte byteval, Object value2) { - try { - return byteval >= Byte.parseByte(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - } - - @Override - boolean compare_Character(char charval, Object value2) { - try { - return charval >= ((String) value2).charAt(0); - } catch (IndexOutOfBoundsException e) { - return false; - } - } - - @Override - boolean compare_Double(double doubleval, Object value2) { - double doubleval2; - try { - doubleval2 = Double.parseDouble(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - return Double.compare(doubleval, doubleval2) >= 0; - } - - @Override - boolean compare_Float(float floatval, Object value2) { - float floatval2; - try { - floatval2 = Float.parseFloat(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - return Float.compare(floatval, floatval2) >= 0; - } - - @Override - boolean compare_Integer(int intval, Object value2) { - try { - return intval >= Integer.parseInt(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - } - - @Override - boolean compare_Long(long longval, Object value2) { - try { - return longval >= Long.parseLong(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - } - - @Override - boolean compare_Short(short shortval, Object value2) { - try { - return shortval >= Short.parseShort(((String) value2).trim()); - } catch (IllegalArgumentException e) { - return false; - } - } - - @Override - boolean compare_Comparable(Comparable<Object> value1, Object value2) { - value2 = valueOf(value1.getClass(), (String) value2); - if (value2 == null) { - return false; - } - try { - return value1.compareTo(value2) >= 0; - } catch (Exception e) { - // if the compareTo method throws an exception; return false - return false; - } + boolean comparison(int compare) { + return compare >= 0; } @Override StringBuilder normalize(StringBuilder sb) { sb.append('(').append(attr).append('>').append('='); - return encodeValue(sb, (String) value).append(')'); + return encodeValue(sb, value).append(')'); } @Override @@ -1361,12 +1201,12 @@ public abstract class FilterImpl implements Filter { } if (not) { // this must be a range end "value)" - if (!currentRange.setRight(')', Version.valueOf((String) value))) { + if (!currentRange.setRight(')', Version.valueOf(value))) { throw new IllegalStateException("range end is already processed for attribute: " + attr); //$NON-NLS-1$ } } else { // this must be a range start "[value" - if (!currentRange.setLeft('[', Version.valueOf((String) value))) { + if (!currentRange.setLeft('[', Version.valueOf(value))) { throw new IllegalStateException("range start is already processed for attribute: " + attr); //$NON-NLS-1$ } } @@ -1374,8 +1214,11 @@ public abstract class FilterImpl implements Filter { } static final class Approx extends Equal { - Approx(String attr, Object value, boolean debug) { + final String approx; + + Approx(String attr, String value, boolean debug) { super(attr, value, debug); + this.approx = approxString(value); } @Override @@ -1384,17 +1227,21 @@ public abstract class FilterImpl implements Filter { } @Override - boolean compare_String(String string, Object value2) { + String value() { + return approx; + } + + @Override + boolean compare_String(String string) { string = approxString(string); - String string2 = approxString((String) value2); - return string.equalsIgnoreCase(string2); + return string.equalsIgnoreCase(approx); } @Override - boolean compare_Character(char charval, Object value2) { + boolean compare_Character(char charval) { char charval2; try { - charval2 = ((String) value2).charAt(0); + charval2 = approx.charAt(0); } catch (IndexOutOfBoundsException e) { return false; } @@ -1404,7 +1251,7 @@ public abstract class FilterImpl implements Filter { @Override StringBuilder normalize(StringBuilder sb) { sb.append('(').append(attr).append('~').append('='); - return encodeValue(sb, approxString((String) value)).append(')'); + return encodeValue(sb, approx).append(')'); } /** @@ -1652,14 +1499,14 @@ public abstract class FilterImpl implements Filter { case '>' : { if (filterChars[pos + 1] == '=') { pos += 2; - return new FilterImpl.Greater(attr, parse_value(), debug); + return new FilterImpl.GreaterEqual(attr, parse_value(), debug); } break; } case '<' : { if (filterChars[pos + 1] == '=') { pos += 2; - return new FilterImpl.Less(attr, parse_value(), debug); + return new FilterImpl.LessEqual(attr, parse_value(), debug); } break; } @@ -1675,12 +1522,19 @@ public abstract class FilterImpl implements Filter { } pos++; - Object string = parse_substring(); + String[] substrings = parse_substring(); - if (string instanceof String) { - return new FilterImpl.Equal(attr, string, debug); + int length = substrings.length; + if (length == 0) { + return new FilterImpl.Equal(attr, "", debug); //$NON-NLS-1$ } - return new FilterImpl.Substring(attr, string, debug); + if (length == 1) { + String single = substrings[0]; + if (single != null) { + return new FilterImpl.Equal(attr, single, debug); + } + } + return new FilterImpl.Substring(attr, substrings, debug); } } @@ -1750,7 +1604,7 @@ public abstract class FilterImpl implements Filter { return sb.toString(); } - private Object parse_substring() throws InvalidSyntaxException { + private String[] parse_substring() throws InvalidSyntaxException { StringBuilder sb = new StringBuilder(filterChars.length - pos); List<String> operands = new ArrayList<>(10); @@ -1798,20 +1652,6 @@ public abstract class FilterImpl implements Filter { } } - int size = operands.size(); - - if (size == 0) { - return ""; //$NON-NLS-1$ - } - - if (size == 1) { - String single = operands.get(0); - - if (single != null) { - return single; - } - } - return operands.toArray(new String[0]); } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/EquinoxLogServices.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/EquinoxLogServices.java index 32ed55210..8040f9009 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/EquinoxLogServices.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/EquinoxLogServices.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2017 IBM Corporation and others. + * Copyright (c) 2006, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -101,7 +101,8 @@ public class EquinoxLogServices { //ignore and use LogLevel.WARN } - logServiceManager = new LogServiceManager(logHistoryMax, defaultLevel, logWriter, perfWriter); + boolean captureLogEntryLocation = "true".equals(environmentInfo.getConfiguration(EquinoxConfiguration.PROP_LOG_CAPTURE_ENTRY_LOCATION, "true")); //$NON-NLS-1$ //$NON-NLS-2$ + logServiceManager = new LogServiceManager(logHistoryMax, defaultLevel, captureLogEntryLocation, logWriter, perfWriter); eclipseLogFactory = new EquinoxLogFactory(logWriter, logServiceManager); rootFrameworkLog = eclipseLogFactory.createFrameworkLog(null, logWriter); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java index 75e2d9d5f..a6c3987cb 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/ExtendedLogServiceFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2018 Cognos Incorporated, IBM Corporation and others + * Copyright (c) 2006, 2020 Cognos Incorporated, IBM Corporation and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 which @@ -37,10 +37,15 @@ public class ExtendedLogServiceFactory implements ServiceFactory<ExtendedLogServ private final Permission logPermission = new LogPermission("*", LogPermission.LOG); //$NON-NLS-1$ final ExtendedLogReaderServiceFactory logReaderServiceFactory; private final LoggerAdmin loggerAdmin = new EquinoxLoggerAdmin(); + private final boolean captureLogEntryLocation; - public ExtendedLogServiceFactory(ExtendedLogReaderServiceFactory logReaderServiceFactory) { + public ExtendedLogServiceFactory(ExtendedLogReaderServiceFactory logReaderServiceFactory, boolean captureLogEntryLocation) { this.logReaderServiceFactory = logReaderServiceFactory; + this.captureLogEntryLocation = captureLogEntryLocation; + } + boolean captureLogEntryLocation() { + return captureLogEntryLocation; } @Override diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java index 38bdb07d7..a56948440 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2018 Cognos Incorporated, IBM Corporation and others + * Copyright (c) 2006, 2020 Cognos Incorporated, IBM Corporation and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 which @@ -61,9 +61,9 @@ public class LogServiceManager implements SynchronousBundleListener, FrameworkLi private EventAdminAdapter eventAdminAdapter; private ConfigAdminListener configAdminListener; - public LogServiceManager(int maxHistory, LogLevel defaultLevel, LogListener... systemListeners) { + public LogServiceManager(int maxHistory, LogLevel defaultLevel, boolean captureLogEntryLocation, LogListener... systemListeners) { logReaderServiceFactory = new ExtendedLogReaderServiceFactory(maxHistory, defaultLevel); - logServiceFactory = new ExtendedLogServiceFactory(logReaderServiceFactory); + logServiceFactory = new ExtendedLogServiceFactory(logReaderServiceFactory, captureLogEntryLocation); systemBundleLog = logServiceFactory.getLogService(new MockSystemBundle()); for (LogListener logListener : systemListeners) { if (logListener instanceof LogFilter) diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java index dafdcdcce..710d5ee09 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LoggerImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2018 Cognos Incorporated, IBM Corporation and others + * Copyright (c) 2006, 2020 Cognos Incorporated, IBM Corporation and others * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 which @@ -298,6 +298,9 @@ public class LoggerImpl implements Logger { } private StackTraceElement getLocation() { + if (!logServiceImpl.getFactory().captureLogEntryLocation()) { + return null; + } StackTraceElement[] elements = Thread.currentThread().getStackTrace(); if (elements.length == 0) { return null; diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/PermissionInfoCollection.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/PermissionInfoCollection.java index ab5a53b36..cb057962e 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/PermissionInfoCollection.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/PermissionInfoCollection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 IBM Corporation and others. + * Copyright (c) 2008, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -14,6 +14,7 @@ package org.eclipse.osgi.internal.permadmin; import java.io.File; +import java.io.FilePermission; import java.lang.reflect.Constructor; import java.security.AccessController; import java.security.AllPermission; @@ -33,19 +34,31 @@ public final class PermissionInfoCollection extends PermissionCollection { 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}; + static private final String ALL_PERMISSION_NAME = AllPermission.class.getName(); + static final String FILE_PERMISSION_NAME = FilePermission.class.getName(); + static final String ALL_FILES = "<<ALL FILES>>"; //$NON-NLS-1$ - /* @GuardedBy(cachedPermisssionCollections) */ + /* @GuardedBy(cachedPermissionCollections) */ private final Map<Class<? extends Permission>, PermissionCollection> cachedPermissionCollections = new HashMap<>(); + private final Map<BundlePermissions, PermissionCollection> cachedRelativeFilePermissionCollections; 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())) + boolean allAbsolutePaths = true; + for (PermissionInfo info : permInfos) { + if (ALL_PERMISSION_NAME.equals(info.getType())) { tempAllPermissions = true; + } else if (FILE_PERMISSION_NAME.equals(info.getType())) { + if (!(new File(info.getActions()).isAbsolute())) { + allAbsolutePaths = false; + } + } + } this.hasAllPermission = tempAllPermissions; + this.cachedRelativeFilePermissionCollections = allAbsolutePaths ? null : new HashMap<BundlePermissions, PermissionCollection>(); setReadOnly(); // collections are managed with ConditionalPermissionAdmin } @@ -62,13 +75,14 @@ public final class PermissionInfoCollection extends PermissionCollection { @Override public boolean implies(Permission perm) { + return implies(null, perm); + } + + boolean implies(final BundlePermissions bundlePermissions, Permission perm) { if (hasAllPermission) return true; final Class<? extends Permission> permClass = perm.getClass(); - PermissionCollection collection; - synchronized (cachedPermissionCollections) { - collection = cachedPermissionCollections.get(permClass); - } + PermissionCollection collection = getCachedCollection(bundlePermissions, permClass); // must populate the collection outside of the lock to prevent class loader deadlock if (collection == null) { collection = perm.newPermissionCollection(); @@ -80,10 +94,9 @@ public final class PermissionInfoCollection extends PermissionCollection { AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { @Override public Object run() throws Exception { - addPermissions(targetCollection, permClass); + addPermissions(bundlePermissions, targetCollection, permClass); return null; } - }); } catch (Exception e) { @@ -92,23 +105,43 @@ public final class PermissionInfoCollection extends PermissionCollection { } throw new SecurityException("Exception creating permissions: " + permClass + ": " + e.getMessage(), e); //$NON-NLS-1$ //$NON-NLS-2$ } - synchronized (cachedPermissionCollections) { - // check to see if another thread beat this thread at adding the collection - PermissionCollection exists = cachedPermissionCollections.get(permClass); - if (exists != null) - collection = exists; - else + collection = cacheCollection(bundlePermissions, permClass, collection); + } + return collection.implies(perm); + } + + PermissionCollection getCachedCollection(BundlePermissions bundlePermissions, Class<? extends Permission> permClass) { + synchronized (cachedPermissionCollections) { + if (bundlePermissions != null && cachedRelativeFilePermissionCollections != null && FILE_PERMISSION_NAME.equals(permClass.getName())) { + return cachedRelativeFilePermissionCollections.get(bundlePermissions); + } + return cachedPermissionCollections.get(permClass); + } + } + + private PermissionCollection cacheCollection(BundlePermissions bundlePermissions, Class<? extends Permission> permClass, PermissionCollection collection) { + synchronized (cachedPermissionCollections) { + // check to see if another thread beat this thread at adding the collection + boolean relativeFiles = bundlePermissions != null && cachedRelativeFilePermissionCollections != null && FILE_PERMISSION_NAME.equals(permClass.getName()); + PermissionCollection exists = relativeFiles ? cachedRelativeFilePermissionCollections.get(bundlePermissions) : cachedPermissionCollections.get(permClass); + if (exists != null) { + collection = exists; + } else { + if (relativeFiles) { + cachedRelativeFilePermissionCollections.put(bundlePermissions, collection); + } else { cachedPermissionCollections.put(permClass, collection); + } } + return collection; } - return collection.implies(perm); } PermissionInfo[] getPermissionInfos() { return permInfos; } - void addPermissions(PermissionCollection collection, Class<? extends Permission> permClass) throws Exception { + void addPermissions(BundlePermissions bundlePermissions, PermissionCollection collection, Class<? extends Permission> permClass) throws Exception { String permClassName = permClass.getName(); Constructor<? extends Permission> constructor = null; int numArgs = -1; @@ -121,8 +154,9 @@ public final class PermissionInfoCollection extends PermissionCollection { // ignore } } - if (constructor == null) + if (constructor == null) { throw new NoSuchMethodException(permClass.getName() + ".<init>()"); //$NON-NLS-1$ + } /* * TODO: We need to cache the permission constructors to enhance performance (see bug 118813). */ @@ -135,13 +169,17 @@ public final class PermissionInfoCollection extends PermissionCollection { if (numArgs > 1) { args[1] = permInfo.getActions(); } - if (permInfo.getType().equals("java.io.FilePermission")) { //$NON-NLS-1$ + if (permInfo.getType().equals(FILE_PERMISSION_NAME)) { // map FilePermissions for relative names to the bundle's data area - if (!args[0].equals("<<ALL FILES>>")) { //$NON-NLS-1$ + if (!args[0].equals(ALL_FILES)) { File file = new File(args[0]); if (!file.isAbsolute()) { // relative name - // TODO need to figure out how to do relative FilePermissions from the dataFile - continue; + File target = bundlePermissions == null ? null : bundlePermissions.getBundle().getDataFile(permInfo.getName()); + if (target == null) { + // ignore if we cannot find the data area + continue; + } + args[0] = target.getPath(); } } } @@ -153,6 +191,9 @@ public final class PermissionInfoCollection extends PermissionCollection { void clearPermissionCache() { synchronized (cachedPermissionCollections) { cachedPermissionCollections.clear(); + if (cachedRelativeFilePermissionCollections != null) { + cachedRelativeFilePermissionCollections.clear(); + } } } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java index 17072314f..b9bd97bd4 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/SecurityAdmin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 IBM Corporation and others. + * Copyright (c) 2008, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -95,13 +95,6 @@ public final class SecurityAdmin implements PermissionAdmin, ConditionalPermissi private final PermissionInfo[] impliedPermissionInfos; private final EquinoxSecurityManager supportedSecurityManager; - private SecurityAdmin(EquinoxSecurityManager supportedSecurityManager, PermissionInfo[] impliedPermissionInfos, PermissionInfoCollection permAdminDefaults) { - this.supportedSecurityManager = supportedSecurityManager; - this.impliedPermissionInfos = impliedPermissionInfos; - this.permAdminDefaults = permAdminDefaults; - this.permissionStorage = null; - } - public SecurityAdmin(EquinoxSecurityManager supportedSecurityManager, PermissionData permissionStorage) { this.supportedSecurityManager = supportedSecurityManager; this.permissionStorage = permissionStorage; @@ -160,7 +153,7 @@ public final class SecurityAdmin implements PermissionAdmin, ConditionalPermissi curPermAdminDefaults = permAdminDefaults; } if (locationCollection != null) - return locationCollection.implies(permission); + return locationCollection.implies(bundlePermissions, permission); // if conditional admin table is empty the fall back to defaults if (curCondAdminTable.isEmpty()) return curPermAdminDefaults != null ? curPermAdminDefaults.implies(permission) : DEFAULT_DEFAULT.implies(permission); @@ -281,8 +274,7 @@ public final class SecurityAdmin implements PermissionAdmin, ConditionalPermissi @Override public AccessControlContext getAccessControlContext(String[] signers) { - SecurityAdmin snapShot = getSnapShot(); - return new AccessControlContext(new ProtectionDomain[] {createProtectionDomain(createMockBundle(signers), snapShot)}); + return new AccessControlContext(new ProtectionDomain[] {createProtectionDomain(createMockBundle(signers), this)}); } /** @@ -317,19 +309,6 @@ public final class SecurityAdmin implements PermissionAdmin, ConditionalPermissi return setConditionalPermissionInfo(name, conds, perms, true); } - private SecurityAdmin getSnapShot() { - SecurityAdmin sa; - synchronized (lock) { - sa = new SecurityAdmin(supportedSecurityManager, impliedPermissionInfos, permAdminDefaults); - SecurityRow[] rows = condAdminTable.getRows(); - SecurityRow[] rowsSnapShot = new SecurityRow[rows.length]; - for (int i = 0; i < rows.length; i++) - rowsSnapShot[i] = new SecurityRow(sa, rows[i].getName(), rows[i].getConditionInfos(), rows[i].getPermissionInfos(), rows[i].getAccessDecision()); - sa.condAdminTable = new SecurityTable(sa, rowsSnapShot); - } - return sa; - } - private ConditionalPermissionInfo setConditionalPermissionInfo(String name, ConditionInfo[] conds, PermissionInfo[] perms, boolean firstTry) { ConditionalPermissionUpdate update = newConditionalPermissionUpdate(); List<ConditionalPermissionInfo> rows = update.getConditionalPermissionInfos(); @@ -427,8 +406,8 @@ public final class SecurityAdmin implements PermissionAdmin, ConditionalPermissi PermissionInfo[] results = new PermissionInfo[permissionInfos.length]; for (int i = 0; i < permissionInfos.length; i++) { results[i] = permissionInfos[i]; - if ("java.io.FilePermission".equals(permissionInfos[i].getType())) { //$NON-NLS-1$ - if (!"<<ALL FILES>>".equals(permissionInfos[i].getName())) { //$NON-NLS-1$ + if (PermissionInfoCollection.FILE_PERMISSION_NAME.equals(permissionInfos[i].getType())) { + if (!PermissionInfoCollection.ALL_FILES.equals(permissionInfos[i].getName())) { File file = new File(permissionInfos[i].getName()); if (!file.isAbsolute()) { // relative name try { diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/SecurityRow.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/SecurityRow.java index 64bdc0eb9..0dbb366ee 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/SecurityRow.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/permadmin/SecurityRow.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2016 IBM Corporation and others. + * Copyright (c) 2008, 2020 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -339,12 +339,12 @@ public final class SecurityRow implements ConditionalPermissionInfo { Decision evaluate(BundlePermissions bundlePermissions, Permission permission) { if (bundleConditions == null || bundlePermissions == null) - return evaluatePermission(permission); + return evaluatePermission(bundlePermissions, permission); Condition[] conditions = getConditions(bundlePermissions); if (conditions == ABSTAIN_LIST) return DECISION_ABSTAIN; if (conditions == SATISFIED_LIST) - return evaluatePermission(permission); + return evaluatePermission(bundlePermissions, permission); boolean empty = true; List<Condition> postponedConditions = null; @@ -370,7 +370,7 @@ public final class SecurityRow implements ConditionalPermissionInfo { } else { // postponed case if (postponedPermCheck == null) // perform a permission check now - postponedPermCheck = evaluatePermission(permission); + postponedPermCheck = evaluatePermission(bundlePermissions, permission); if (postponedPermCheck == DECISION_ABSTAIN) return postponedPermCheck; // no need to postpone the condition if the row abstains // this row will deny or allow the permission; must queue the postponed condition @@ -387,7 +387,7 @@ public final class SecurityRow implements ConditionalPermissionInfo { } if (postponedPermCheck != null) return new Decision(postponedPermCheck.decision | SecurityTable.POSTPONED, postponedConditions.toArray(new Condition[postponedConditions.size()]), this, bundlePermissions); - return evaluatePermission(permission); + return evaluatePermission(bundlePermissions, permission); } private boolean isPostponed(Condition condition) { @@ -395,8 +395,8 @@ public final class SecurityRow implements ConditionalPermissionInfo { return condition.isPostponed() && securityAdmin.getSupportedSecurityManager() != null; } - private Decision evaluatePermission(Permission permission) { - return permissionInfoCollection.implies(permission) ? (deny ? DECISION_DENIED : DECISION_GRANTED) : DECISION_ABSTAIN; + private Decision evaluatePermission(BundlePermissions bundlePermissions, Permission permission) { + return permissionInfoCollection.implies(bundlePermissions, permission) ? (deny ? DECISION_DENIED : DECISION_GRANTED) : DECISION_ABSTAIN; } @Override diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java index de8f3f794..634c069c7 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/StorageUtil.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Files; import java.util.Dictionary; import java.util.Hashtable; import java.util.concurrent.TimeUnit; @@ -169,25 +170,7 @@ public class StorageUtil { } public static boolean canWrite(File installDir) { - if (installDir.canWrite() == false) - return false; - - if (!installDir.isDirectory()) - return false; - - File fileTest = null; - try { - // we use the .dll suffix to properly test on Vista virtual directories - // on Vista you are not allowed to write executable files on virtual directories like "Program Files" - fileTest = File.createTempFile("writableArea", ".dll", installDir); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (IOException e) { - //If an exception occured while trying to create the file, it means that it is not writtable - return false; - } finally { - if (fileTest != null) - fileTest.delete(); - } - return true; + return installDir.isDirectory() && Files.isWritable(installDir.toPath()); } public static URL encodeFileURL(File file) throws MalformedURLException { |