-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #433 from jamezp/issue431
[431] Add an ApplicationArchiveProcessor to add the appropriate permi…
- Loading branch information
Showing
10 changed files
with
241 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
rest-client-base/src/main/java/org/jboss/resteasy/microprofile/client/SecurityActions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2025 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jboss.resteasy.microprofile.client; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
/** | ||
* This class <strong>must</strong> never be made public. | ||
* | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
class SecurityActions { | ||
|
||
/** | ||
* Returns the current threads context class loader. | ||
* | ||
* @return the current threads context class loader or {@code null} if there is not one | ||
*/ | ||
static ClassLoader getContextClassLoader() { | ||
if (System.getSecurityManager() == null) { | ||
return Thread.currentThread().getContextClassLoader(); | ||
} | ||
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> Thread.currentThread() | ||
.getContextClassLoader()); | ||
} | ||
|
||
/** | ||
* Gets the current context class loader or the class loader of the passed in class. | ||
* | ||
* @param clazz the class to get the class loader from if the context class loader is {@code null} | ||
* | ||
* @return the available class loader | ||
*/ | ||
static ClassLoader getClassLoader(final Class<?> clazz) { | ||
if (System.getSecurityManager() == null) { | ||
final ClassLoader cl = Thread.currentThread().getContextClassLoader(); | ||
return cl == null ? clazz.getClassLoader() : cl; | ||
} | ||
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> { | ||
final ClassLoader cl = Thread.currentThread().getContextClassLoader(); | ||
return cl == null ? clazz.getClassLoader() : cl; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...a/dev/resteasy/microprofile/rest/client/tck/RestClientTckApplicationArchiveProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2025 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.resteasy.microprofile.rest.client.tck; | ||
|
||
import java.io.FilePermission; | ||
import java.lang.reflect.ReflectPermission; | ||
import java.net.SocketPermission; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.PropertyPermission; | ||
|
||
import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; | ||
import org.jboss.arquillian.test.spi.TestClass; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.container.ManifestContainer; | ||
import org.wildfly.testing.tools.deployments.DeploymentDescriptors; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
public class RestClientTckApplicationArchiveProcessor implements ApplicationArchiveProcessor { | ||
private static final List<String> ALL_FILE_TESTS = List.of( | ||
// Creates a /tmp/ssl* keystore file | ||
"org.eclipse.microprofile.rest.client.tck.ssl.SslContextTest", | ||
"org.eclipse.microprofile.rest.client.tck.ssl.SslHostnameVerifierTest", | ||
"org.eclipse.microprofile.rest.client.tck.ssl.SslMutualTest", | ||
"org.eclipse.microprofile.rest.client.tck.ssl.SslTrustStoreTest"); | ||
|
||
private static final List<String> GET_CLASS_LOADER_TESTS = List.of( | ||
// The org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher requires getClassLoader() | ||
"org.eclipse.microprofile.rest.client.tck.cditests.CDIProxyServerTest", | ||
"org.eclipse.microprofile.rest.client.tck.ssl.SslHostnameVerifierTest", | ||
"org.eclipse.microprofile.rest.client.tck.ssl.SslMutualTest", | ||
"org.eclipse.microprofile.rest.client.tck.ssl.SslTrustStoreTest", | ||
// Required for the Jetty thread pool | ||
"org.eclipse.microprofile.rest.client.tck.ProxyServerTest"); | ||
|
||
private static final List<String> JETTY_SERVER_TESTS = List.of( | ||
"org.eclipse.microprofile.rest.client.tck.ProxyServerTest", | ||
"org.eclipse.microprofile.rest.client.tck.cditests.CDIProxyServerTest"); | ||
|
||
@Override | ||
public void process(final Archive<?> applicationArchive, final TestClass testClass) { | ||
if (applicationArchive instanceof ManifestContainer<?>) { | ||
final var container = (ManifestContainer<?>) applicationArchive; | ||
|
||
final var permissions = new ArrayList<>(List.of( | ||
// Required by the Arquillian ServiceLoader to allow access to the constructor | ||
new ReflectPermission("suppressAccessChecks"), | ||
new PropertyPermission("arquillian.*", "read"), | ||
// Required by Jetty | ||
new PropertyPermission("jetty.*", "read,write"), | ||
// Required by the MP REST Client TCK | ||
new PropertyPermission("org.eclipse.microprofile.rest.client.*", "read"), | ||
new RuntimePermission("getenv.JETTY_AVAILABLE_PROCESSORS"), | ||
// Required of OTel is available on the deployment class path | ||
new RuntimePermission("getenv.OTEL_JAVAAGENT_DEBUG"), | ||
new RuntimePermission("getenv.OTEL_INSTRUMENTATION_EXPERIMENTAL_SPAN_SUPPRESSION_STRATEGY"), | ||
// Required by TestNG | ||
new PropertyPermission("testng.*", "read"), | ||
new PropertyPermission("user.dir", "read"), | ||
new RuntimePermission("accessDeclaredMembers"), | ||
// Required by Wiremock | ||
new PropertyPermission("wiremock.*", "read"), | ||
new SocketPermission("localhost", "resolve"), | ||
new SocketPermission("localhost:*", "connect,listen,resolve"), | ||
new SocketPermission("127.0.0.1:*", "connect,resolve"))); | ||
|
||
if (ALL_FILE_TESTS.contains(testClass.getName())) { | ||
permissions.add(new FilePermission("<<ALL FILES>>", "read")); | ||
} | ||
if (GET_CLASS_LOADER_TESTS.contains(testClass.getName())) { | ||
permissions.add(new RuntimePermission("getClassLoader")); | ||
} | ||
if (JETTY_SERVER_TESTS.contains(testClass.getName())) { | ||
permissions.add(new RuntimePermission("modifyThread")); | ||
} | ||
|
||
var currentPermissionsXml = applicationArchive.delete("META-INF/permissions.xml"); | ||
// A WAR might be in a different location | ||
if (currentPermissionsXml == null) { | ||
currentPermissionsXml = applicationArchive.delete("WEB-INF/classes/META-INF/permissions.yaml"); | ||
} | ||
if (currentPermissionsXml != null) { | ||
container.addAsManifestResource( | ||
DeploymentDescriptors.appendPermissions(currentPermissionsXml.getAsset(), permissions), | ||
"permissions.xml"); | ||
} else { | ||
container.addAsManifestResource(DeploymentDescriptors.createPermissionsXmlAsset(permissions), | ||
"permissions.xml"); | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...t-tck/src/main/java/dev/resteasy/microprofile/rest/client/tck/RestClientTckExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* | ||
* Copyright 2025 Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.resteasy.microprofile.rest.client.tck; | ||
|
||
import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; | ||
import org.jboss.arquillian.core.spi.LoadableExtension; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
public class RestClientTckExtension implements LoadableExtension { | ||
@Override | ||
public void register(final ExtensionBuilder builder) { | ||
builder.service(ApplicationArchiveProcessor.class, RestClientTckApplicationArchiveProcessor.class); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...-tck/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev.resteasy.microprofile.rest.client.tck.RestClientTckExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters