Skip to content

Commit

Permalink
Add Apache5 properties to be grabbed by config (#5536)
Browse files Browse the repository at this point in the history
* Add Apache5 properties to be grabbed by config

Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol authored Feb 16, 2024
1 parent 604cf2e commit f86cdf0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -29,6 +29,7 @@ class JerseySystemPropertiesConfigurationModel extends SystemPropertiesConfigura
"org.glassfish.jersey.servlet.ServletProperties",
"org.glassfish.jersey.message.MessageProperties",
"org.glassfish.jersey.apache.connector.ApacheClientProperties",
"org.glassfish.jersey.apache5.connector.Apache5ClientProperties",
"org.glassfish.jersey.helidon.connector.HelidonClientProperties",
"org.glassfish.jersey.jdk.connector.JdkConnectorProperties",
"org.glassfish.jersey.jetty.connector.JettyClientProperties",
Expand Down
31 changes: 6 additions & 25 deletions tests/integration/property-check/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2014, 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -72,6 +72,11 @@
<artifactId>jersey-apache-connector</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-apache5-connector</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.security</groupId>
<artifactId>oauth1-server</artifactId>
Expand Down Expand Up @@ -108,28 +113,4 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>jdk19+</id>
<activation>
<jdk>[19,)</jdk>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/SystemPropertiesConfigurationModelTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -32,6 +32,7 @@

import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.apache.connector.ApacheClientProperties;
import org.glassfish.jersey.apache5.connector.Apache5ClientProperties;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.internal.InternalProperties;
import org.glassfish.jersey.internal.util.JdkVersion;
Expand Down Expand Up @@ -79,24 +80,34 @@ public void allPropertyClassLoaded() throws IOException {
@Test
public void propertyLoadedWhenSecurityException() {
final String TEST_STRING = "test";
SecurityManager sm = System.getSecurityManager();
String policy = System.getProperty("java.security.policy");
final boolean isSm = JdkVersion.getJdkVersion().getMajor() < 19;
SecurityManager sm = null;
String policy = null;
if (isSm) {
sm = System.getSecurityManager();
policy = System.getProperty("java.security.policy");
}
try {
System.setProperty(CommonProperties.ALLOW_SYSTEM_PROPERTIES_PROVIDER, Boolean.TRUE.toString());
System.setProperty(ServerProperties.APPLICATION_NAME, TEST_STRING);
System.setProperty(ClientProperties.BACKGROUND_SCHEDULER_THREADPOOL_SIZE, TEST_STRING);
System.setProperty(ServletProperties.JAXRS_APPLICATION_CLASS, TEST_STRING);
System.setProperty(MessageProperties.IO_BUFFER_SIZE, TEST_STRING);
System.setProperty(ApacheClientProperties.DISABLE_COOKIES, TEST_STRING);
System.setProperty(Apache5ClientProperties.DISABLE_COOKIES, TEST_STRING);
System.setProperty(JettyClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION, TEST_STRING);
System.setProperty(MultiPartProperties.TEMP_DIRECTORY, TEST_STRING);
System.setProperty(OAuth1ServerProperties.REALM, TEST_STRING);
JerseySystemPropertiesConfigurationModel model = new JerseySystemPropertiesConfigurationModel();
assertTrue(model.as(CommonProperties.ALLOW_SYSTEM_PROPERTIES_PROVIDER, Boolean.class));
String securityPolicy = SystemPropertiesConfigurationModelTest.class.getResource("/server.policy").getFile();
System.setProperty("java.security.policy", securityPolicy);
SecurityManager manager = new SecurityManager();
System.setSecurityManager(manager);

if (isSm) {
String securityPolicy = SystemPropertiesConfigurationModelTest.class.getResource("/server.policy").getFile();
System.setProperty("java.security.policy", securityPolicy);
SecurityManager manager = new SecurityManager();
System.setSecurityManager(manager);
}

Map<String, Object> properties = model.getProperties();
assertEquals(TEST_STRING, properties.get(ServerProperties.APPLICATION_NAME));
assertEquals(Boolean.TRUE.toString(), properties.get(CommonProperties.ALLOW_SYSTEM_PROPERTIES_PROVIDER));
Expand All @@ -109,7 +120,9 @@ public void propertyLoadedWhenSecurityException() {
assertEquals(TEST_STRING, properties.get(MessageProperties.IO_BUFFER_SIZE));
assertFalse(properties.containsKey(MessageProperties.DEFLATE_WITHOUT_ZLIB));
assertEquals(TEST_STRING, properties.get(ApacheClientProperties.DISABLE_COOKIES));
assertEquals(TEST_STRING, properties.get(Apache5ClientProperties.DISABLE_COOKIES));
assertFalse(properties.containsKey(ApacheClientProperties.CONNECTION_MANAGER));
assertFalse(properties.containsKey(Apache5ClientProperties.CONNECTION_MANAGER));
assertEquals(TEST_STRING, properties.get(JettyClientProperties.ENABLE_SSL_HOSTNAME_VERIFICATION));
assertFalse(properties.containsKey(JettyClientProperties.DISABLE_COOKIES));
assertEquals(TEST_STRING, properties.get(MultiPartProperties.TEMP_DIRECTORY));
Expand All @@ -120,7 +133,9 @@ public void propertyLoadedWhenSecurityException() {
if (policy != null) {
System.setProperty("java.security.policy", policy);
}
System.setSecurityManager(sm);
if (isSm) {
System.setSecurityManager(sm);
}
}
}

Expand Down

0 comments on commit f86cdf0

Please sign in to comment.