From 93e74224667c0cef73d176f464ea1490a3c30889 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 4 Oct 2022 14:15:48 -0700 Subject: [PATCH] GUACAMOLE-1224: Extract base interface for events affecting objects stored in a Directory. --- .../guacamole/net/event/DirectoryEvent.java | 41 +++++------- .../net/event/DirectoryObjectEvent.java | 65 +++++++++++++++++++ .../guacamole/event/AffectedObject.java | 6 +- 3 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 guacamole-ext/src/main/java/org/apache/guacamole/net/event/DirectoryObjectEvent.java diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/event/DirectoryEvent.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/event/DirectoryEvent.java index 2ff74bf94..725c75048 100644 --- a/guacamole-ext/src/main/java/org/apache/guacamole/net/event/DirectoryEvent.java +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/event/DirectoryEvent.java @@ -24,13 +24,14 @@ import org.apache.guacamole.net.auth.Identifiable; /** * Abstract basis for events which involve a modification made to the objects - * within a {@link Directory}. + * within a {@link Directory} through the operations exposed by the Directory + * interface. * * @param * The type of object stored within the {@link Directory}. */ public interface DirectoryEvent - extends AuthenticationProviderEvent, UserEvent { + extends DirectoryObjectEvent { /** * The types of directory operations that may be represented by a @@ -70,15 +71,6 @@ public interface DirectoryEvent } - /** - * Returns the type of objects stored within the {@link Directory} - * affected by the operation. - * - * @return - * The type of objects stored within the {@link Directory}. - */ - Directory.Type getDirectoryType(); - /** * Returns the operation that was performed/attempted. * @@ -88,24 +80,25 @@ public interface DirectoryEvent Operation getOperation(); /** - * Returns the identifier of the object affected by the operation. If the - * object was just created, this will be the identifier of the new object. - * - * @return - * The identifier of the object affected by the operation. + * {@inheritDoc} + *

+ * If the object was just created, this will be the identifier of the new + * object. */ + @Override String getObjectIdentifier(); /** - * Returns the object affected by the operation, if available. For - * deletions, there is no guarantee that the affected object will be - * available within this event. If the object is not available, null is - * returned. - * - * @return - * The object affected by the operation performed, or null if that - * object is not available in the context of this event. + * {@inheritDoc} + *

+ * Currently, for object creation ({@link Operation#ADD}), retrieval + * ({@link Operation#GET}), modification and ({@link Operation#UPDATE}), + * it can be expected that the affected object will be available, however + * the caller should verify this regardless. For deletions + * ({@link Operation#REMOVE}), the object can only be made available for + * single deletions, and cannot be made available for batch deletions. */ + @Override ObjectType getObject(); } diff --git a/guacamole-ext/src/main/java/org/apache/guacamole/net/event/DirectoryObjectEvent.java b/guacamole-ext/src/main/java/org/apache/guacamole/net/event/DirectoryObjectEvent.java new file mode 100644 index 000000000..812fcbe60 --- /dev/null +++ b/guacamole-ext/src/main/java/org/apache/guacamole/net/event/DirectoryObjectEvent.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.apache.guacamole.net.event; + +import org.apache.guacamole.net.auth.Directory; +import org.apache.guacamole.net.auth.Identifiable; + +/** + * Abstract basis for events which affect or directly relate to objects that + * may be stored within a {@link Directory}. + * + * @param + * The type of object stored within the {@link Directory}. + */ +public interface DirectoryObjectEvent + extends AuthenticationProviderEvent, UserEvent { + + /** + * Returns the type of {@link Directory} that contains the object affected + * by the operation. + * + * @return + * The type of objects stored within the {@link Directory}. + */ + Directory.Type getDirectoryType(); + + /** + * Returns the identifier of the object affected by the operation. + * + * @return + * The identifier of the object affected by the operation. + */ + String getObjectIdentifier(); + + /** + * Returns the object affected by the operation, if available. Whether the + * affected object is available is context- and implementation-dependent. + * There is no general guarantee across all implementations of this event + * that the affected object will be available. If the object is not + * available, null is returned. + * + * @return + * The object affected by the operation performed, or null if that + * object is not available in the context of this event. + */ + ObjectType getObject(); + +} diff --git a/guacamole/src/main/java/org/apache/guacamole/event/AffectedObject.java b/guacamole/src/main/java/org/apache/guacamole/event/AffectedObject.java index 572a9693a..aec678be2 100644 --- a/guacamole/src/main/java/org/apache/guacamole/event/AffectedObject.java +++ b/guacamole/src/main/java/org/apache/guacamole/event/AffectedObject.java @@ -20,9 +20,9 @@ package org.apache.guacamole.event; import org.apache.guacamole.net.auth.Nameable; -import org.apache.guacamole.net.event.DirectoryEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.guacamole.net.event.DirectoryObjectEvent; /** * Loggable representation of the object affected by an operation. @@ -37,7 +37,7 @@ public class AffectedObject implements LoggableDetail { /** * The event representing the requested operation. */ - private final DirectoryEvent event; + private final DirectoryObjectEvent event; /** * Creates a new AffectedObject representing the object affected by the @@ -46,7 +46,7 @@ public class AffectedObject implements LoggableDetail { * @param event * The event representing the operation. */ - public AffectedObject(DirectoryEvent event) { + public AffectedObject(DirectoryObjectEvent event) { this.event = event; }