From d2d988af90ed5fbf43837c1ef48c88624653b21a Mon Sep 17 00:00:00 2001 From: Aleksey Shipilev Date: Tue, 27 Feb 2024 10:28:55 +0000 Subject: [PATCH] 8292182: [TESTLIB] Enhance JAXPPolicyManager to setup required permissions for jtreg version 7 jar Backport-of: aa5b71893307b9fe6137bc3541edccaab73735ac --- .../jaxp/libs/jaxp/library/JAXPPolicyManager.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/jaxp/javax/xml/jaxp/libs/jaxp/library/JAXPPolicyManager.java b/test/jaxp/javax/xml/jaxp/libs/jaxp/library/JAXPPolicyManager.java index 652997edd15..4d0598696f3 100644 --- a/test/jaxp/javax/xml/jaxp/libs/jaxp/library/JAXPPolicyManager.java +++ b/test/jaxp/javax/xml/jaxp/libs/jaxp/library/JAXPPolicyManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,9 @@ package jaxp.library; +import java.net.URI; import java.net.URL; +import java.nio.file.Path; import java.security.CodeSource; import java.security.Permission; import java.security.PermissionCollection; @@ -161,7 +163,7 @@ void removeTmpPermission(int index) { */ class TestPolicy extends Policy { private final static Set TEST_JARS = - Set.of("jtreg.jar", "javatest.jar", "testng.jar", "jcommander.jar"); + Set.of("jtreg.*jar", "javatest.*jar", "testng.*jar", "jcommander.*jar"); private final PermissionCollection permissions = new Permissions(); private ThreadLocal> transientPermissions = new ThreadLocal<>(); @@ -213,9 +215,10 @@ public PermissionCollection getPermissions(CodeSource codesource) { private boolean isTestMachineryDomain(ProtectionDomain domain) { CodeSource cs = (domain == null) ? null : domain.getCodeSource(); URL loc = (cs == null) ? null : cs.getLocation(); - String path = (loc == null) ? null : loc.getPath(); - return path != null && TEST_JARS.stream() - .filter(path::endsWith) + URI uri = (loc == null) ? null : URI.create(loc.toString()); + String name = (uri == null) ? null : Path.of(uri).getFileName().toString(); + return name != null && TEST_JARS.stream() + .filter(name::matches) .findAny() .isPresent(); }