mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 11:45:49 +01:00
Remove AccessController.doPrivileged calls (#3271)
The `AccessController` and the `SecurityManager` is deprecated for removal in Java 17. We don't make use of the `SecurityManager` anyway, so we can safely remove it. Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
parent
d115032940
commit
98b4902c4a
@ -18,9 +18,6 @@ import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.time.Instant;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -137,7 +134,7 @@ public class OAuthConnector {
|
||||
* @return Access Token
|
||||
* @throws IOException IO/ network exceptions
|
||||
* @throws OAuthException Other exceptions
|
||||
* @throws OAuthErrorException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
|
||||
* @throws OAuthResponseException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
|
||||
* Response
|
||||
*/
|
||||
public AccessTokenResponse grantTypePassword(String tokenUrl, String username, String password,
|
||||
@ -171,7 +168,7 @@ public class OAuthConnector {
|
||||
* @return Access Token
|
||||
* @throws IOException IO/ network exceptions
|
||||
* @throws OAuthException Other exceptions
|
||||
* @throws OAuthErrorException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
|
||||
* @throws OAuthResponseException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
|
||||
* Response
|
||||
*/
|
||||
public AccessTokenResponse grantTypeRefreshToken(String tokenUrl, String refreshToken, @Nullable String clientId,
|
||||
@ -206,7 +203,7 @@ public class OAuthConnector {
|
||||
* @return Access Token
|
||||
* @throws IOException IO/ network exceptions
|
||||
* @throws OAuthException Other exceptions
|
||||
* @throws OAuthErrorException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
|
||||
* @throws OAuthResponseException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
|
||||
* Response
|
||||
*/
|
||||
public AccessTokenResponse grantTypeAuthorizationCode(String tokenUrl, String authorizationCode, String clientId,
|
||||
@ -240,7 +237,7 @@ public class OAuthConnector {
|
||||
* @return Access Token
|
||||
* @throws IOException IO/ network exceptions
|
||||
* @throws OAuthException Other exceptions
|
||||
* @throws OAuthErrorException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
|
||||
* @throws OAuthResponseException Error codes given by authorization provider, as in RFC 6749 section 5.2 Error
|
||||
* Response
|
||||
*/
|
||||
public AccessTokenResponse grantTypeClientCredentials(String tokenUrl, String clientId,
|
||||
@ -301,11 +298,8 @@ public class OAuthConnector {
|
||||
String content = "";
|
||||
try {
|
||||
final FormContentProvider entity = new FormContentProvider(fields);
|
||||
final ContentResponse response = AccessController
|
||||
.doPrivileged((PrivilegedExceptionAction<ContentResponse>) () -> {
|
||||
Request requestWithContent = request.content(entity);
|
||||
return requestWithContent.send();
|
||||
});
|
||||
Request requestWithContent = request.content(entity);
|
||||
final ContentResponse response = requestWithContent.send();
|
||||
|
||||
statusCode = response.getStatus();
|
||||
content = response.getContentAsString();
|
||||
@ -326,18 +320,15 @@ public class OAuthConnector {
|
||||
statusCode);
|
||||
throw new OAuthException("Bad http response, http code " + statusCode);
|
||||
}
|
||||
} catch (PrivilegedActionException pae) {
|
||||
Exception underlyingException = pae.getException();
|
||||
if (underlyingException instanceof InterruptedException || underlyingException instanceof TimeoutException
|
||||
|| underlyingException instanceof ExecutionException) {
|
||||
throw new IOException("Exception in oauth communication, grant type " + grantType, underlyingException);
|
||||
}
|
||||
// Dont know what exception it is, wrap it up and throw it out
|
||||
throw new OAuthException("Exception in oauth communication, grant type " + grantType, underlyingException);
|
||||
} catch (InterruptedException | TimeoutException | ExecutionException e) {
|
||||
throw new IOException("Exception in oauth communication, grant type " + grantType, e);
|
||||
} catch (JsonSyntaxException e) {
|
||||
throw new OAuthException(String.format(
|
||||
"Unable to deserialize json into AccessTokenResponse/ OAuthResponseException. httpCode: %i json: %s",
|
||||
"Unable to deserialize json into AccessTokenResponse/ OAuthResponseException. httpCode: %d json: %s",
|
||||
statusCode, content), e);
|
||||
} catch (Exception e) {
|
||||
// Dont know what exception it is, wrap it up and throw it out
|
||||
throw new OAuthException("Exception in oauth communication, grant type " + grantType, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -356,10 +347,7 @@ public class OAuthConnector {
|
||||
HttpClient httpClient = httpClientFactory.createHttpClient(HTTP_CLIENT_CONSUMER_NAME);
|
||||
if (!httpClient.isStarted()) {
|
||||
try {
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<@Nullable Void>) () -> {
|
||||
httpClient.start();
|
||||
return null;
|
||||
});
|
||||
httpClient.start();
|
||||
} catch (Exception e) {
|
||||
throw new OAuthException("Exception while starting httpClient, tokenUrl: " + tokenUrl, e);
|
||||
}
|
||||
@ -370,10 +358,7 @@ public class OAuthConnector {
|
||||
private void shutdownQuietly(@Nullable HttpClient httpClient) {
|
||||
try {
|
||||
if (httpClient != null) {
|
||||
AccessController.doPrivileged((PrivilegedExceptionAction<@Nullable Void>) () -> {
|
||||
httpClient.stop();
|
||||
return null;
|
||||
});
|
||||
httpClient.stop();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// there is nothing we can do here
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.automation.internal;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
@ -92,10 +90,7 @@ public class TriggerHandlerCallbackImpl implements TriggerHandlerCallback {
|
||||
|
||||
public void dispose() {
|
||||
synchronized (this) {
|
||||
AccessController.doPrivileged((PrivilegedAction<@Nullable Void>) () -> {
|
||||
executor.shutdownNow();
|
||||
return null;
|
||||
});
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.config.discovery;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -175,12 +173,7 @@ public class DiscoveryResultBuilder {
|
||||
}
|
||||
|
||||
private String getStackTrace(final Thread thread) {
|
||||
StackTraceElement[] elements = AccessController.doPrivileged(new PrivilegedAction<StackTraceElement[]>() {
|
||||
@Override
|
||||
public StackTraceElement[] run() {
|
||||
return thread.getStackTrace();
|
||||
}
|
||||
});
|
||||
StackTraceElement[] elements = thread.getStackTrace();
|
||||
return Arrays.stream(elements).map(element -> "\tat " + element.toString()).collect(Collectors.joining("\n"));
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.config.discovery.internal;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -254,13 +252,7 @@ public final class DiscoveryServiceRegistryImpl implements DiscoveryServiceRegis
|
||||
}
|
||||
for (final DiscoveryListener listener : listeners) {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedAction<@Nullable Void>() {
|
||||
@Override
|
||||
public @Nullable Void run() {
|
||||
listener.thingDiscovered(source, result);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
listener.thingDiscovered(source, result);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Cannot notify the DiscoveryListener '{}' on Thing discovered event!",
|
||||
listener.getClass().getName(), ex);
|
||||
@ -280,13 +272,7 @@ public final class DiscoveryServiceRegistryImpl implements DiscoveryServiceRegis
|
||||
}
|
||||
for (final DiscoveryListener listener : listeners) {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedAction<@Nullable Void>() {
|
||||
@Override
|
||||
public @Nullable Void run() {
|
||||
listener.thingRemoved(source, thingUID);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
listener.thingRemoved(source, thingUID);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Cannot notify the DiscoveryListener '{}' on Thing removed event!",
|
||||
listener.getClass().getName(), ex);
|
||||
@ -300,13 +286,8 @@ public final class DiscoveryServiceRegistryImpl implements DiscoveryServiceRegis
|
||||
Set<ThingUID> removedResults = new HashSet<>();
|
||||
for (final DiscoveryListener listener : listeners) {
|
||||
try {
|
||||
Collection<ThingUID> olderResults = AccessController
|
||||
.doPrivileged(new PrivilegedAction<@Nullable Collection<ThingUID>>() {
|
||||
@Override
|
||||
public @Nullable Collection<ThingUID> run() {
|
||||
return listener.removeOlderResults(source, timestamp, thingTypeUIDs, bridgeUID);
|
||||
}
|
||||
});
|
||||
Collection<ThingUID> olderResults = listener.removeOlderResults(source, timestamp, thingTypeUIDs,
|
||||
bridgeUID);
|
||||
if (olderResults != null) {
|
||||
removedResults.addAll(olderResults);
|
||||
}
|
||||
|
@ -12,11 +12,8 @@
|
||||
*/
|
||||
package org.openhab.core.io.net.http.internal;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
@ -188,160 +185,129 @@ public class WebClientFactoryImpl implements HttpClientFactory, WebSocketFactory
|
||||
}
|
||||
|
||||
private synchronized void initialize() {
|
||||
if (threadPool == null || commonHttpClient == null || commonWebSocketClient == null) {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<@Nullable Void>() {
|
||||
@Override
|
||||
public @Nullable Void run() {
|
||||
if (threadPool == null) {
|
||||
threadPool = createThreadPool("common", minThreadsShared, maxThreadsShared,
|
||||
keepAliveTimeoutShared);
|
||||
}
|
||||
|
||||
if (commonHttpClient == null) {
|
||||
commonHttpClient = createHttpClientInternal("common", true, threadPool);
|
||||
// we need to set the stop timeout AFTER the client has been started, because
|
||||
// otherwise the Jetty client sets it back to the default value.
|
||||
// We need the stop timeout in order to prevent blocking the deactivation of this
|
||||
// component, see https://github.com/eclipse/smarthome/issues/6632
|
||||
threadPool.setStopTimeout(0);
|
||||
logger.debug("Jetty shared http client created");
|
||||
}
|
||||
|
||||
if (commonWebSocketClient == null) {
|
||||
commonWebSocketClient = createWebSocketClientInternal("common", true, threadPool);
|
||||
logger.debug("Jetty shared web socket client created");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
} else {
|
||||
throw new HttpClientInitializationException(
|
||||
"unexpected checked exception during initialization of the jetty client", cause);
|
||||
}
|
||||
try {
|
||||
if (threadPool == null) {
|
||||
threadPool = createThreadPool("common", minThreadsShared, maxThreadsShared, keepAliveTimeoutShared);
|
||||
}
|
||||
|
||||
if (commonHttpClient == null) {
|
||||
commonHttpClient = createHttpClientInternal("common", true, threadPool);
|
||||
// we need to set the stop timeout AFTER the client has been started, because
|
||||
// otherwise the Jetty client sets it back to the default value.
|
||||
// We need the stop timeout in order to prevent blocking the deactivation of this
|
||||
// component, see https://github.com/eclipse/smarthome/issues/6632
|
||||
threadPool.setStopTimeout(0);
|
||||
logger.debug("Jetty shared http client created");
|
||||
}
|
||||
|
||||
if (commonWebSocketClient == null) {
|
||||
commonWebSocketClient = createWebSocketClientInternal("common", true, threadPool);
|
||||
logger.debug("Jetty shared web socket client created");
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new HttpClientInitializationException(
|
||||
"unexpected checked exception during initialization of the jetty client", e);
|
||||
}
|
||||
}
|
||||
|
||||
private HttpClient createHttpClientInternal(String consumerName, boolean startClient,
|
||||
@Nullable QueuedThreadPool threadPool) {
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<HttpClient>() {
|
||||
@Override
|
||||
public HttpClient run() {
|
||||
logger.debug("creating http client for consumer {}", consumerName);
|
||||
logger.debug("creating http client for consumer {}", consumerName);
|
||||
|
||||
HttpClient httpClient = new HttpClient(createSslContextFactory());
|
||||
HttpClient httpClient = new HttpClient(createSslContextFactory());
|
||||
|
||||
// If proxy is set as property (standard Java property), provide the proxy information to Jetty HTTP
|
||||
// Client
|
||||
String httpProxyHost = System.getProperty("http.proxyHost");
|
||||
String httpsProxyHost = System.getProperty("https.proxyHost");
|
||||
// If proxy is set as property (standard Java property), provide the proxy information to Jetty HTTP
|
||||
// Client
|
||||
String httpProxyHost = System.getProperty("http.proxyHost");
|
||||
String httpsProxyHost = System.getProperty("https.proxyHost");
|
||||
|
||||
if (httpProxyHost != null) {
|
||||
String sProxyPort = System.getProperty("http.proxyPort");
|
||||
if (sProxyPort != null) {
|
||||
try {
|
||||
int port = Integer.parseInt(sProxyPort);
|
||||
httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(httpProxyHost, port));
|
||||
} catch (NumberFormatException ex) {
|
||||
// this was not a correct port. Ignoring.
|
||||
logger.debug(
|
||||
"HTTP Proxy detected (http.proxyHost), but invalid proxyport. Ignoring proxy.");
|
||||
}
|
||||
}
|
||||
} else if (httpsProxyHost != null) {
|
||||
String sProxyPort = System.getProperty("https.proxyPort");
|
||||
if (sProxyPort != null) {
|
||||
try {
|
||||
int port = Integer.parseInt(sProxyPort);
|
||||
httpClient.getProxyConfiguration().getProxies()
|
||||
.add(new HttpProxy(httpsProxyHost, port));
|
||||
} catch (NumberFormatException ex) {
|
||||
// this was not a correct port. Ignoring.
|
||||
logger.debug(
|
||||
"HTTP Proxy detected (https.proxyHost), but invalid proxyport. Ignoring proxy.");
|
||||
}
|
||||
}
|
||||
if (httpProxyHost != null) {
|
||||
String sProxyPort = System.getProperty("http.proxyPort");
|
||||
if (sProxyPort != null) {
|
||||
try {
|
||||
int port = Integer.parseInt(sProxyPort);
|
||||
httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(httpProxyHost, port));
|
||||
} catch (NumberFormatException ex) {
|
||||
// this was not a correct port. Ignoring.
|
||||
logger.debug("HTTP Proxy detected (http.proxyHost), but invalid proxyport. Ignoring proxy.");
|
||||
}
|
||||
}
|
||||
} else if (httpsProxyHost != null) {
|
||||
String sProxyPort = System.getProperty("https.proxyPort");
|
||||
if (sProxyPort != null) {
|
||||
try {
|
||||
int port = Integer.parseInt(sProxyPort);
|
||||
httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(httpsProxyHost, port));
|
||||
} catch (NumberFormatException ex) {
|
||||
// this was not a correct port. Ignoring.
|
||||
logger.debug("HTTP Proxy detected (https.proxyHost), but invalid proxyport. Ignoring proxy.");
|
||||
}
|
||||
|
||||
httpClient.setMaxConnectionsPerDestination(2);
|
||||
|
||||
if (threadPool != null) {
|
||||
httpClient.setExecutor(threadPool);
|
||||
} else {
|
||||
final QueuedThreadPool queuedThreadPool = createThreadPool(consumerName, minThreadsCustom,
|
||||
maxThreadsCustom, keepAliveTimeoutCustom);
|
||||
httpClient.setExecutor(queuedThreadPool);
|
||||
}
|
||||
|
||||
if (startClient) {
|
||||
try {
|
||||
httpClient.start();
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not start Jetty http client", e);
|
||||
throw new HttpClientInitializationException("Could not start Jetty http client", e);
|
||||
}
|
||||
}
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
} else {
|
||||
throw new HttpClientInitializationException(
|
||||
"unexpected checked exception during initialization of the Jetty http client", cause);
|
||||
}
|
||||
|
||||
httpClient.setMaxConnectionsPerDestination(2);
|
||||
|
||||
if (threadPool != null) {
|
||||
httpClient.setExecutor(threadPool);
|
||||
} else {
|
||||
final QueuedThreadPool queuedThreadPool = createThreadPool(consumerName, minThreadsCustom,
|
||||
maxThreadsCustom, keepAliveTimeoutCustom);
|
||||
httpClient.setExecutor(queuedThreadPool);
|
||||
}
|
||||
|
||||
if (startClient) {
|
||||
try {
|
||||
httpClient.start();
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not start Jetty http client", e);
|
||||
throw new HttpClientInitializationException("Could not start Jetty http client", e);
|
||||
}
|
||||
}
|
||||
|
||||
return httpClient;
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new HttpClientInitializationException(
|
||||
"unexpected checked exception during initialization of the Jetty http client", e);
|
||||
}
|
||||
}
|
||||
|
||||
private WebSocketClient createWebSocketClientInternal(String consumerName, boolean startClient,
|
||||
@Nullable QueuedThreadPool threadPool) {
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<WebSocketClient>() {
|
||||
@Override
|
||||
public WebSocketClient run() {
|
||||
logger.debug("creating web socket client for consumer {}", consumerName);
|
||||
logger.debug("creating web socket client for consumer {}", consumerName);
|
||||
|
||||
HttpClient httpClient = new HttpClient(createSslContextFactory());
|
||||
if (threadPool != null) {
|
||||
httpClient.setExecutor(threadPool);
|
||||
} else {
|
||||
final QueuedThreadPool queuedThreadPool = createThreadPool(consumerName, minThreadsCustom,
|
||||
maxThreadsCustom, keepAliveTimeoutCustom);
|
||||
httpClient.setExecutor(queuedThreadPool);
|
||||
}
|
||||
|
||||
WebSocketClient webSocketClient = new WebSocketClient(httpClient);
|
||||
|
||||
if (startClient) {
|
||||
try {
|
||||
webSocketClient.start();
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not start Jetty web socket client", e);
|
||||
throw new HttpClientInitializationException("Could not start Jetty web socket client", e);
|
||||
}
|
||||
}
|
||||
|
||||
return webSocketClient;
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof RuntimeException) {
|
||||
throw (RuntimeException) cause;
|
||||
HttpClient httpClient = new HttpClient(createSslContextFactory());
|
||||
if (threadPool != null) {
|
||||
httpClient.setExecutor(threadPool);
|
||||
} else {
|
||||
throw new HttpClientInitializationException(
|
||||
"unexpected checked exception during initialization of the Jetty web socket client", cause);
|
||||
final QueuedThreadPool queuedThreadPool = createThreadPool(consumerName, minThreadsCustom,
|
||||
maxThreadsCustom, keepAliveTimeoutCustom);
|
||||
httpClient.setExecutor(queuedThreadPool);
|
||||
}
|
||||
|
||||
WebSocketClient webSocketClient = new WebSocketClient(httpClient);
|
||||
|
||||
if (startClient) {
|
||||
try {
|
||||
webSocketClient.start();
|
||||
} catch (Exception e) {
|
||||
logger.error("Could not start Jetty web socket client", e);
|
||||
throw new HttpClientInitializationException("Could not start Jetty web socket client", e);
|
||||
}
|
||||
}
|
||||
|
||||
return webSocketClient;
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new HttpClientInitializationException(
|
||||
"unexpected checked exception during initialization of the Jetty web socket client", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,6 @@
|
||||
package org.openhab.core.thing.internal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -454,23 +452,20 @@ public class ThingManagerImpl
|
||||
throw new IllegalArgumentException(MessageFormat.format(
|
||||
"Cannot update thing {0} because it is not known to the registry", thing.getUID().getAsString()));
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedAction<@Nullable Void>) () -> {
|
||||
final Provider<Thing> provider = thingRegistry.getProvider(thing);
|
||||
if (provider == null) {
|
||||
throw new IllegalArgumentException(MessageFormat.format(
|
||||
"Provider for thing {0} cannot be determined because it is not known to the registry",
|
||||
thing.getUID().getAsString()));
|
||||
}
|
||||
if (provider instanceof ManagedProvider) {
|
||||
final ManagedProvider<Thing, ThingUID> managedProvider = (ManagedProvider<Thing, ThingUID>) provider;
|
||||
managedProvider.update(thing);
|
||||
} else {
|
||||
logger.debug("Only updating thing {} in the registry because provider {} is not managed.",
|
||||
thing.getUID().getAsString(), provider);
|
||||
thingRegistry.updated(provider, oldThing, thing);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
final Provider<Thing> provider = thingRegistry.getProvider(thing);
|
||||
if (provider == null) {
|
||||
throw new IllegalArgumentException(MessageFormat.format(
|
||||
"Provider for thing {0} cannot be determined because it is not known to the registry",
|
||||
thing.getUID().getAsString()));
|
||||
}
|
||||
if (provider instanceof ManagedProvider) {
|
||||
final ManagedProvider<Thing, ThingUID> managedProvider = (ManagedProvider<Thing, ThingUID>) provider;
|
||||
managedProvider.update(thing);
|
||||
} else {
|
||||
logger.debug("Only updating thing {} in the registry because provider {} is not managed.",
|
||||
thing.getUID().getAsString(), provider);
|
||||
thingRegistry.updated(provider, oldThing, thing);
|
||||
}
|
||||
thingUpdatedLock.remove(thing.getUID());
|
||||
}
|
||||
|
||||
@ -1119,10 +1114,7 @@ public class ThingManagerImpl
|
||||
// call asynchronous to avoid deadlocks in thing handler
|
||||
ThreadPoolManager.getPool(FORCE_REMOVE_THREAD_POOL_NAME).execute(() -> {
|
||||
try {
|
||||
AccessController.doPrivileged((PrivilegedAction<@Nullable Void>) () -> {
|
||||
thingRegistry.forceRemove(thing.getUID());
|
||||
return null;
|
||||
});
|
||||
thingRegistry.forceRemove(thing.getUID());
|
||||
} catch (IllegalStateException ex) {
|
||||
logger.debug("Could not remove thing {}. Most likely because it is not managed.", thing.getUID(), ex);
|
||||
} catch (Exception ex) {
|
||||
|
@ -14,8 +14,6 @@ package org.openhab.core.internal.common;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@ -130,13 +128,8 @@ abstract class AbstractInvocationHandler<T> {
|
||||
}
|
||||
|
||||
private String getStacktrace(final Thread thread) {
|
||||
StackTraceElement[] elements = AccessController.doPrivileged(new PrivilegedAction<StackTraceElement[]>() {
|
||||
@Override
|
||||
public StackTraceElement[] run() {
|
||||
return thread.getStackTrace();
|
||||
}
|
||||
});
|
||||
return Arrays.stream(elements).map(element -> "\tat " + element.toString()).collect(Collectors.joining("\n"));
|
||||
StackTraceElement[] elements = thread.getStackTrace();
|
||||
return Arrays.stream(elements).map(element -> "\tat " + element).collect(Collectors.joining("\n"));
|
||||
}
|
||||
|
||||
String toString(Method method) {
|
||||
|
@ -14,8 +14,6 @@ package org.openhab.core.internal.common;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
@ -56,25 +54,23 @@ public class SafeCallerBuilderImpl<T> implements SafeCallerBuilder<T> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T build() {
|
||||
return AccessController.doPrivileged((PrivilegedAction<T>) () -> {
|
||||
InvocationHandler handler;
|
||||
if (async) {
|
||||
handler = new InvocationHandlerAsync<>(manager, target, identifier, timeout, exceptionHandler,
|
||||
timeoutHandler);
|
||||
} else {
|
||||
handler = new InvocationHandlerSync<>(manager, target, identifier, timeout, exceptionHandler,
|
||||
timeoutHandler);
|
||||
}
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
if (classLoader == null) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot create proxy because '" + getClass().getName() + "' class loader is null");
|
||||
}
|
||||
return (T) Proxy.newProxyInstance(
|
||||
CombinedClassLoader.fromClasses(classLoader,
|
||||
Stream.concat(Stream.of(target.getClass()), Arrays.stream(interfaceTypes))),
|
||||
interfaceTypes, handler);
|
||||
});
|
||||
InvocationHandler handler;
|
||||
if (async) {
|
||||
handler = new InvocationHandlerAsync<>(manager, target, identifier, timeout, exceptionHandler,
|
||||
timeoutHandler);
|
||||
} else {
|
||||
handler = new InvocationHandlerSync<>(manager, target, identifier, timeout, exceptionHandler,
|
||||
timeoutHandler);
|
||||
}
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
if (classLoader == null) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot create proxy because '" + getClass().getName() + "' class loader is null");
|
||||
}
|
||||
return (T) Proxy.newProxyInstance(
|
||||
CombinedClassLoader.fromClasses(classLoader,
|
||||
Stream.concat(Stream.of(target.getClass()), Arrays.stream(interfaceTypes))),
|
||||
interfaceTypes, handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,9 +12,6 @@
|
||||
*/
|
||||
package org.openhab.core.internal.events;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
|
||||
@ -54,23 +51,17 @@ public class OSGiEventPublisher implements EventPublisher {
|
||||
|
||||
private void postAsOSGiEvent(final EventAdmin eventAdmin, final Event event) throws IllegalStateException {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
|
||||
@Override
|
||||
public Void run() throws Exception {
|
||||
Dictionary<String, Object> properties = new Hashtable<>(3);
|
||||
properties.put("type", event.getType());
|
||||
properties.put("payload", event.getPayload());
|
||||
properties.put("topic", event.getTopic());
|
||||
String source = event.getSource();
|
||||
if (source != null) {
|
||||
properties.put("source", source);
|
||||
}
|
||||
eventAdmin.postEvent(new org.osgi.service.event.Event("openhab", properties));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException pae) {
|
||||
Exception e = pae.getException();
|
||||
Dictionary<String, Object> properties = new Hashtable<>(3);
|
||||
properties.put("type", event.getType());
|
||||
properties.put("payload", event.getPayload());
|
||||
properties.put("topic", event.getTopic());
|
||||
String source = event.getSource();
|
||||
if (source != null) {
|
||||
properties.put("source", source);
|
||||
}
|
||||
eventAdmin.postEvent(new org.osgi.service.event.Event("openhab", properties));
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Cannot post the event via the event bus. Error message: " + e.getMessage(),
|
||||
e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user