Skip to content

Commit 54331f5

Browse files
committed
[EJBCLIENT-400] Refactoring classes & decreasing visibility
1 parent 6a5f9e9 commit 54331f5

18 files changed

+300
-140
lines changed

src/main/java/org/jboss/ejb/_private/SystemProperties.java

Lines changed: 0 additions & 99 deletions
This file was deleted.

src/main/java/org/jboss/ejb/client/ClusterNodeSelector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.concurrent.atomic.AtomicInteger;
2626

2727
import org.jboss.ejb._private.Logs;
28-
import org.jboss.ejb._private.SystemProperties;
2928
import org.wildfly.common.Assert;
3029

3130
/**
@@ -91,7 +90,7 @@ public String selectNode(final String clusterName, final String[] connectedNodes
9190
* If no local node is used the DEFAULT will be used and connect a minimum of 5 nodes and select it randomly.
9291
*/
9392
ClusterNodeSelector DEFAULT_PREFER_LOCAL = new ClusterNodeSelector() {
94-
private final String localNodeName = SystemProperties.getString(SystemProperties.JBOSS_NODE_NAME);
93+
private final String localNodeName = SecurityUtils.getString(SystemProperties.JBOSS_NODE_NAME);
9594

9695
public String selectNode(String clusterName, String[] connectedNodes, String[] totalAvailableNodes) {
9796
// Check if more than one node is available
@@ -110,7 +109,7 @@ public String selectNode(String clusterName, String[] connectedNodes, String[] t
110109
};
111110

112111
ClusterNodeSelector RANDOM_PREFER_LOCAL = new ClusterNodeSelector() {
113-
private final String localNodeName = SystemProperties.getString(SystemProperties.JBOSS_NODE_NAME);
112+
private final String localNodeName = SecurityUtils.getString(SystemProperties.JBOSS_NODE_NAME);
114113

115114
public String selectNode(String clusterName, String[] connectedNodes, String[] totalAvailableNodes) {
116115
// Check if more than one node is available

src/main/java/org/jboss/ejb/client/DeploymentNodeSelector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.concurrent.atomic.AtomicInteger;
2727

2828
import org.jboss.ejb._private.Logs;
29-
import org.jboss.ejb._private.SystemProperties;
3029
import org.wildfly.common.Assert;
3130

3231
/**
@@ -124,7 +123,7 @@ public String selectNode(final String[] eligibleNodes, final String appName, fin
124123
* A deployment node selector which check the server name if inside and prefer it if available for selection.
125124
*/
126125
DeploymentNodeSelector RANDOM_PREFER_LOCAL = new DeploymentNodeSelector() {
127-
private final String localNodeName = SystemProperties.getString(SystemProperties.JBOSS_NODE_NAME);
126+
private final String localNodeName = SecurityUtils.getString(SystemProperties.JBOSS_NODE_NAME);
128127

129128
public String selectNode(final String[] eligibleNodes, final String appName, final String moduleName, final String distinctName) {
130129
if(Logs.MAIN.isTraceEnabled()) {

src/main/java/org/jboss/ejb/client/DiscoveryEJBClientInterceptor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949

5050
import org.jboss.ejb._private.Keys;
5151
import org.jboss.ejb._private.Logs;
52-
import org.jboss.ejb._private.SystemProperties;
5352
import org.jboss.ejb.client.annotation.ClientInterceptorPriority;
5453
import org.wildfly.common.Assert;
5554
import org.wildfly.common.net.CidrAddress;
@@ -74,11 +73,11 @@ public final class DiscoveryEJBClientInterceptor implements EJBClientInterceptor
7473
private static final Supplier<Discovery> DISCOVERY_SUPPLIER = doPrivileged((PrivilegedAction<Supplier<Discovery>>) Discovery.getContextManager()::getPrivilegedSupplier);
7574

7675
private static final String[] NO_STRINGS = new String[0];
77-
private static final boolean WILDFLY_TESTSUITE_HACK = SystemProperties.getBoolean(SystemProperties.WILDFLY_TESTSUITE_HACK);
76+
private static final boolean WILDFLY_TESTSUITE_HACK = SecurityUtils.getBoolean(SystemProperties.WILDFLY_TESTSUITE_HACK);
7877
// This provides a way timeout a discovery, avoiding blocking on some edge cases. See EJBCLIENT-311.
79-
private static final long DISCOVERY_TIMEOUT = SystemProperties.getLong(SystemProperties.DISCOVERY_TIMEOUT, 0L);
78+
private static final long DISCOVERY_TIMEOUT = SecurityUtils.getLong(SystemProperties.DISCOVERY_TIMEOUT, 0L);
8079
//how long to wait if at least one node has already been discovered. This one is in ms rather than s
81-
private static final long DISCOVERY_ADDITIONAL_TIMEOUT = SystemProperties.getLong(SystemProperties.DISCOVERY_ADDITIONAL_NODE_TIMEOUT, 0L);
80+
private static final long DISCOVERY_ADDITIONAL_TIMEOUT = SecurityUtils.getLong(SystemProperties.DISCOVERY_ADDITIONAL_NODE_TIMEOUT, 0L);
8281

8382
/**
8483
* This interceptor's priority.
@@ -87,7 +86,7 @@ public final class DiscoveryEJBClientInterceptor implements EJBClientInterceptor
8786

8887
private static final AttachmentKey<Set<URI>> BL_KEY = new AttachmentKey<>();
8988
private static final Map<URI, Long> blacklist = new ConcurrentHashMap<>();
90-
private static final long BLACKLIST_TIMEOUT = TimeUnit.MILLISECONDS.toNanos(SystemProperties.getLong(SystemProperties.DISCOVERY_BLACKLIST_TIMEOUT, 5000L));
89+
private static final long BLACKLIST_TIMEOUT = TimeUnit.MILLISECONDS.toNanos(SecurityUtils.getLong(SystemProperties.DISCOVERY_BLACKLIST_TIMEOUT, 5000L));
9190

9291
/**
9392
* Construct a new instance.

src/main/java/org/jboss/ejb/client/EJBInvocationHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import javax.ejb.EJBObject;
3434

3535
import org.jboss.ejb._private.Logs;
36-
import org.jboss.ejb._private.SystemProperties;
3736
import org.wildfly.common.Assert;
3837
import org.wildfly.discovery.Discovery;
3938
import org.wildfly.security.auth.client.AuthenticationContext;
@@ -50,7 +49,7 @@ final class EJBInvocationHandler<T> extends Attachable implements InvocationHand
5049

5150
private static final Supplier<Discovery> DISCOVERY_SUPPLIER = doPrivileged((PrivilegedAction<Supplier<Discovery>>) Discovery.getContextManager()::getPrivilegedSupplier);
5251

53-
private static final int MAX_RETRIES = SystemProperties.getInteger(SystemProperties.MAX_ENTRIES, 8);
52+
private static final int MAX_RETRIES = SecurityUtils.getInteger(SystemProperties.MAX_ENTRIES, 8);
5453

5554
private final transient boolean async;
5655

src/main/java/org/jboss/ejb/client/EJBProxyInformation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import javax.ejb.EJBHome;
3737
import javax.ejb.EJBObject;
3838

39-
import org.jboss.ejb._private.SystemProperties;
4039
import org.jboss.ejb.client.annotation.ClientAsynchronous;
4140
import org.jboss.ejb.client.annotation.ClientInterceptors;
4241
import org.jboss.ejb.client.annotation.ClientTransaction;
@@ -51,7 +50,7 @@
5150
*/
5251
final class EJBProxyInformation<T> {
5352

54-
static final boolean ENABLE_SCANNING = SystemProperties.getBoolean(SystemProperties.VIEW_ANNOTATION_SCAN_ENABLED, true);
53+
static final boolean ENABLE_SCANNING = SecurityUtils.getBoolean(SystemProperties.VIEW_ANNOTATION_SCAN_ENABLED, true);
5554

5655
static final Class<?>[] JUST_INV_HANDLER = new Class<?>[] { InvocationHandler.class };
5756

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2021 Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.jboss.ejb.client;
19+
20+
import org.wildfly.security.manager.WildFlySecurityManager;
21+
22+
/**
23+
* Security sensitive operations being used in this package.
24+
*
25+
* @author <a href="mailto:[email protected]">Richard Opálka</a>
26+
*/
27+
final class SecurityUtils {
28+
29+
private SecurityUtils() {
30+
// forbidden instantiation
31+
}
32+
33+
static boolean getBoolean(final String propertyName) {
34+
return getBoolean(propertyName, false);
35+
}
36+
37+
static boolean getBoolean(final String propertyName, final boolean defaultValue) {
38+
try {
39+
final String propertyValue = getString(propertyName);
40+
return propertyValue != null ? Boolean.valueOf(propertyValue) : defaultValue;
41+
} catch (Throwable t) {
42+
return defaultValue;
43+
}
44+
}
45+
46+
static int getInteger(final String propertyName, final int defaultValue) {
47+
try {
48+
final String propertyValue = getString(propertyName);
49+
return propertyValue != null ? Integer.parseInt(propertyValue) : defaultValue;
50+
} catch (Throwable t) {
51+
return defaultValue;
52+
}
53+
}
54+
55+
static long getLong(final String propertyName, final long defaultValue) {
56+
try {
57+
final String propertyValue = getString(propertyName);
58+
return propertyValue != null ? Long.parseLong(propertyValue) : defaultValue;
59+
} catch (Throwable t) {
60+
return defaultValue;
61+
}
62+
}
63+
64+
static String getString(final String propertyName) {
65+
return getString(propertyName, null);
66+
}
67+
68+
static String getString(final String propertyName, final String defaultValue) {
69+
return WildFlySecurityManager.getPropertyPrivileged(propertyName, defaultValue);
70+
}
71+
72+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2021 Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.jboss.ejb.client;
19+
20+
/**
21+
* System properties being used in this package.
22+
*
23+
* @author <a href="mailto:[email protected]">Richard Opálka</a>
24+
*/
25+
final class SystemProperties {
26+
27+
static final String DISCOVERY_ADDITIONAL_NODE_TIMEOUT = "org.jboss.ejb.client.discovery.additional-node-timeout";
28+
static final String DISCOVERY_BLACKLIST_TIMEOUT = "org.jboss.ejb.client.discovery.blacklist.timeout";
29+
static final String DISCOVERY_TIMEOUT = "org.jboss.ejb.client.discovery.timeout";
30+
static final String JBOSS_NODE_NAME = "jboss.node.name";
31+
static final String MAX_ENTRIES = "org.jboss.ejb.client.max-retries";
32+
static final String VIEW_ANNOTATION_SCAN_ENABLED = "org.jboss.ejb.client.view.annotation.scan.enabled";
33+
static final String WILDFLY_TESTSUITE_HACK = "org.jboss.ejb.client.wildfly-testsuite-hack";
34+
35+
private SystemProperties() {
36+
// forbidden instantiation
37+
}
38+
39+
}

src/main/java/org/jboss/ejb/client/legacy/ElytronLegacyConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import javax.security.auth.callback.CallbackHandler;
2525

2626
import org.jboss.ejb._private.Logs;
27-
import org.jboss.ejb._private.SystemProperties;
2827
import org.kohsuke.MetaInfServices;
2928
import org.wildfly.common.function.ExceptionSupplier;
3029
import org.wildfly.security.auth.client.AuthenticationConfiguration;
@@ -47,7 +46,7 @@
4746
@MetaInfServices
4847
public final class ElytronLegacyConfiguration implements LegacyConfiguration {
4948

50-
private static final boolean QUIET_AUTH = SystemProperties.getBoolean(SystemProperties.QUIET_AUTH);
49+
private static final boolean QUIET_AUTH = SecurityUtils.getBoolean(SystemProperties.QUIET_AUTH);
5150
private static final String[] NO_STRINGS = new String[0];
5251

5352
public AuthenticationContext getConfiguredAuthenticationContext() {

src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import javax.security.auth.callback.CallbackHandler;
4747

4848
import org.jboss.ejb._private.Logs;
49-
import org.jboss.ejb._private.SystemProperties;
5049
import org.jboss.ejb.client.ClusterNodeSelector;
5150
import org.jboss.ejb.client.DeploymentNodeSelector;
5251
import org.wildfly.common.Assert;
@@ -112,8 +111,8 @@ public final class JBossEJBProperties implements Contextual<JBossEJBProperties>
112111
private static final String PROPERTY_KEY_PROTOCOL = "protocol";
113112
private static final String DEFAULT_PROTOCOL = "http-remoting";
114113

115-
private static final boolean EXPAND_PASSWORDS = SystemProperties.getBoolean(SystemProperties.EXPAND_PASSWORDS);
116-
private static final String CONFIGURED_PATH_NAME = SystemProperties.getString(SystemProperties.PROPERTIES_FILE_PATH);
114+
private static final boolean EXPAND_PASSWORDS = SecurityUtils.getBoolean(SystemProperties.EXPAND_PASSWORDS);
115+
private static final String CONFIGURED_PATH_NAME = SecurityUtils.getString(SystemProperties.PROPERTIES_FILE_PATH);
117116

118117
private static final String PROPERTY_KEY_HTTP_CONNECTIONS = "http.connections";
119118

@@ -131,7 +130,7 @@ public final class JBossEJBProperties implements Contextual<JBossEJBProperties>
131130
if (CONFIGURED_PATH_NAME != null) try {
132131
File propertiesFile = new File(CONFIGURED_PATH_NAME);
133132
if (! propertiesFile.isAbsolute()) {
134-
propertiesFile = new File(SystemProperties.getString(SystemProperties.USER_DIR), propertiesFile.toString());
133+
propertiesFile = new File(SecurityUtils.getString(SystemProperties.USER_DIR), propertiesFile.toString());
135134
}
136135
value = JBossEJBProperties.fromFile(propertiesFile);
137136
} catch (IOException e) {

0 commit comments

Comments
 (0)