Skip to content

Commit 0ad769e

Browse files
authored
IGNITE-28754 Replaced SecurityAwareCustomMessageWrapper with OperationContextMessage (#13346)
1 parent 1639c6e commit 0ad769e

16 files changed

Lines changed: 480 additions & 392 deletions

File tree

modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
3535
import org.apache.ignite.internal.managers.deployment.GridDeploymentRequest;
3636
import org.apache.ignite.internal.managers.deployment.GridDeploymentResponse;
37-
import org.apache.ignite.internal.managers.discovery.SecurityAwareCustomMessageWrapper;
3837
import org.apache.ignite.internal.managers.encryption.ChangeCacheEncryptionRequest;
3938
import org.apache.ignite.internal.managers.encryption.EncryptionDataBagItem;
4039
import org.apache.ignite.internal.managers.encryption.GenerateEncryptionKeyRequest;
@@ -443,7 +442,6 @@ public CoreMessagesProvider(Marshaller dfltMarsh, Marshaller schemaAwareMarsh, C
443442
withNoSchema(FullMessage.class);
444443
withNoSchema(InitMessage.class);
445444
withNoSchema(CacheStatisticsModeChangeMessage.class);
446-
withNoSchema(SecurityAwareCustomMessageWrapper.class);
447445
withNoSchema(MetadataRemoveAcceptedMessage.class);
448446
withNoSchema(MetadataRemoveProposedMessage.class);
449447
withNoSchema(WalStateFinishMessage.class);

modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
import org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage;
8989
import org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState;
9090
import org.apache.ignite.internal.processors.cluster.IGridClusterStateProcessor;
91-
import org.apache.ignite.internal.processors.security.IgniteSecurity;
9291
import org.apache.ignite.internal.processors.security.SecurityContext;
9392
import org.apache.ignite.internal.processors.tracing.messages.SpanContainer;
9493
import org.apache.ignite.internal.systemview.ClusterNodeViewWalker;
@@ -134,7 +133,6 @@
134133
import org.apache.ignite.spi.discovery.DiscoveryMetricsProvider;
135134
import org.apache.ignite.spi.discovery.DiscoveryNotification;
136135
import org.apache.ignite.spi.discovery.DiscoverySpi;
137-
import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
138136
import org.apache.ignite.spi.discovery.DiscoverySpiDataExchange;
139137
import org.apache.ignite.spi.discovery.DiscoverySpiHistorySupport;
140138
import org.apache.ignite.spi.discovery.DiscoverySpiListener;
@@ -558,9 +556,7 @@ private void updateClientNodes(UUID leftNodeId) {
558556
@Override public IgniteFuture<?> onDiscovery(DiscoveryNotification notification) {
559557
GridFutureAdapter<?> notificationFut = new GridFutureAdapter<>();
560558

561-
discoMsgNotifier.submit(notificationFut, ctx.security().enabled()
562-
? new SecurityAwareNotificationTask(notification)
563-
: new NotificationTask(notification));
559+
discoMsgNotifier.submit(notificationFut, new NotificationTask(notification));
564560

565561
IgniteFuture<?> fut = new IgniteFutureImpl<>(notificationFut);
566562

@@ -743,7 +739,7 @@ else if (customMsg instanceof ChangeGlobalStateMessage) {
743739
}
744740

745741
if (type == EVT_DISCOVERY_CUSTOM_EVT) {
746-
for (Class cls = customMsg.getClass(); cls != null; cls = cls.getSuperclass()) {
742+
for (Class<?> cls = customMsg.getClass(); cls != null; cls = cls.getSuperclass()) {
747743
List<CustomEventListener<DiscoveryCustomMessage>> list = customEvtLsnrs.get(cls);
748744

749745
if (list != null) {
@@ -917,43 +913,8 @@ else if (type == EVT_CLIENT_NODE_RECONNECTED) {
917913
discoEvtHnd.awaitDisconnectEvent();
918914
}
919915

920-
/**
921-
* Extends {@link NotificationTask} to run in a security context owned by the initiator of the
922-
* discovery event.
923-
*/
924-
class SecurityAwareNotificationTask extends NotificationTask {
925-
/** */
926-
public SecurityAwareNotificationTask(DiscoveryNotification notification) {
927-
super(notification);
928-
}
929-
930-
/** */
931-
@Override public void run() {
932-
DiscoverySpiCustomMessage customMsg = notification.customMessage();
933-
934-
if (customMsg instanceof SecurityAwareCustomMessageWrapper) {
935-
UUID secSubjId = ((SecurityAwareCustomMessageWrapper)customMsg).securitySubjectId();
936-
937-
try (Scope ignored = ctx.security().withContext(secSubjId)) {
938-
super.run();
939-
}
940-
}
941-
else {
942-
SecurityContext initiatorNodeSecCtx = nodeSecurityContext(
943-
marshaller,
944-
U.resolveClassLoader(ctx.config()),
945-
notification.getNode()
946-
);
947-
948-
try (Scope ignored = ctx.security().withContext(initiatorNodeSecCtx)) {
949-
super.run();
950-
}
951-
}
952-
}
953-
}
954-
955916
/** Represents task to handle discovery notification asynchronously. */
956-
class NotificationTask implements Runnable {
917+
private class NotificationTask implements Runnable {
957918
/** */
958919
protected final DiscoveryNotification notification;
959920

@@ -965,9 +926,31 @@ public NotificationTask(DiscoveryNotification notification) {
965926
/** {@inheritDoc} */
966927
@Override public void run() {
967928
synchronized (discoEvtMux) {
968-
onDiscovery0(notification);
929+
try (Scope ignored = withRemoteSecurityContext(notification.getNode())) {
930+
onDiscovery0(notification);
931+
}
969932
}
970933
}
934+
935+
/** */
936+
private Scope withRemoteSecurityContext(ClusterNode node) {
937+
if (ctx.security().enabled()) {
938+
if (ctx.security().isDefaultContext()) {
939+
SecurityContext initiatorNodeSecCtx = nodeSecurityContext(
940+
marshaller,
941+
U.resolveClassLoader(ctx.config()),
942+
node
943+
);
944+
945+
return ctx.security().withContext(initiatorNodeSecCtx);
946+
}
947+
948+
// Verify that the Security Context currently attached to the thread is valid.
949+
ctx.security().securityContext();
950+
}
951+
952+
return Scope.NOOP_SCOPE;
953+
}
971954
}
972955
});
973956

@@ -2340,11 +2323,7 @@ public GridFutureAdapter<DiscoveryLocalJoinData> localJoinFuture() {
23402323
*/
23412324
public void sendCustomEvent(DiscoveryCustomMessage msg) throws IgniteCheckedException {
23422325
try {
2343-
IgniteSecurity security = ctx.security();
2344-
2345-
getSpi().sendCustomEvent(security.enabled()
2346-
? new SecurityAwareCustomMessageWrapper(msg, security.securityContext().subject().id())
2347-
: msg);
2326+
getSpi().sendCustomEvent(msg);
23482327
}
23492328
catch (IgniteClientDisconnectedException e) {
23502329
IgniteFuture<?> reconnectFut = ctx.cluster().clientReconnectFuture();

modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/SecurityAwareCustomMessageWrapper.java

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

modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@
181181
import org.apache.ignite.internal.managers.deployment.GridDeploymentInfo;
182182
import org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage;
183183
import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
184-
import org.apache.ignite.internal.managers.discovery.SecurityAwareCustomMessageWrapper;
185184
import org.apache.ignite.internal.mxbean.IgniteStandardMXBean;
186185
import org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper;
187186
import org.apache.ignite.internal.processors.cache.CacheObjectContext;
@@ -7723,7 +7722,7 @@ public static void prepareAffinityField(BinaryObjectBuilder builder, CacheObject
77237722
/** */
77247723
public static <T extends IgniteDataTransferObject> IgniteDataTransferObjectSerializer<T> loadSerializer(Class<T> cls) {
77257724
try {
7726-
Class cls0 = IgniteUtils.class.getClassLoader()
7725+
Class<?> cls0 = IgniteUtils.class.getClassLoader()
77277726
.loadClass(cls.getPackage().getName() + "." + cls.getSimpleName() + "Serializer");
77287727

77297728
return (IgniteDataTransferObjectSerializer<T>)cls0.getDeclaredConstructor().newInstance();
@@ -7735,13 +7734,14 @@ public static <T extends IgniteDataTransferObject> IgniteDataTransferObjectSeria
77357734
}
77367735

77377736
/**
7738-
* Unwraps messsage if it is wrapped by {@link SecurityAwareCustomMessageWrapper}.
7737+
* Unwraps messsage as {@link DiscoveryCustomMessage}.
77397738
*
77407739
* @param msg Message.
77417740
*/
7742-
public static DiscoveryCustomMessage unwrapCustomMessage(DiscoverySpiCustomMessage msg) {
7743-
return msg instanceof SecurityAwareCustomMessageWrapper ?
7744-
((SecurityAwareCustomMessageWrapper)msg).delegate() : (DiscoveryCustomMessage)msg;
7741+
public static DiscoveryCustomMessage unwrapCustomMessage(@Nullable DiscoverySpiCustomMessage msg) {
7742+
assert msg == null || msg instanceof DiscoveryCustomMessage;
7743+
7744+
return (DiscoveryCustomMessage)msg;
77457745
}
77467746

77477747
/**

modules/core/src/main/resources/META-INF/classnames.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,6 @@ org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$1
725725
org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$3$1
726726
org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$6
727727
org.apache.ignite.internal.managers.discovery.GridDiscoveryManager$7
728-
org.apache.ignite.internal.managers.discovery.SecurityAwareCustomMessageWrapper
729728
org.apache.ignite.internal.managers.encryption.CacheGroupEncryptionKeys$TrackedWalSegment
730729
org.apache.ignite.internal.managers.encryption.CacheGroupPageScanner$1
731730
org.apache.ignite.internal.managers.encryption.CacheGroupPageScanner$2

modules/core/src/test/java/org/apache/ignite/internal/processors/security/NodeSecurityContextPropagationTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.ignite.failure.StopNodeOrHaltFailureHandler;
3131
import org.apache.ignite.internal.IgniteEx;
3232
import org.apache.ignite.internal.events.DiscoveryCustomEvent;
33-
import org.apache.ignite.internal.managers.discovery.SecurityAwareCustomMessageWrapper;
3433
import org.apache.ignite.internal.util.typedef.internal.U;
3534
import org.apache.ignite.spi.MessagesPluginProvider;
3635
import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
@@ -160,8 +159,6 @@ private boolean anyReceivedMessageMatch(IgniteEx ignite, Predicate<Object> predi
160159
if (msg instanceof TcpDiscoveryCustomEventMessage) {
161160
DiscoverySpiCustomMessage customMsg = ((TcpDiscoveryCustomEventMessage)msg).message();
162161

163-
assert customMsg instanceof SecurityAwareCustomMessageWrapper;
164-
165162
unwrappedMsg = U.unwrapCustomMessage(customMsg);
166163
}
167164

0 commit comments

Comments
 (0)