GUACAMOLE-1224: Extract base interface for events affecting objects stored in a Directory.

This commit is contained in:
Michael Jumper
2022-10-04 14:15:48 -07:00
parent e5761551e4
commit 93e7422466
3 changed files with 85 additions and 27 deletions

View File

@@ -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 <ObjectType>
* The type of object stored within the {@link Directory}.
*/
public interface DirectoryEvent<ObjectType extends Identifiable>
extends AuthenticationProviderEvent, UserEvent {
extends DirectoryObjectEvent<ObjectType> {
/**
* The types of directory operations that may be represented by a
@@ -70,15 +71,6 @@ public interface DirectoryEvent<ObjectType extends Identifiable>
}
/**
* 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<ObjectType extends Identifiable>
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}
* <p>
* 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}
* <p>
* 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();
}

View File

@@ -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 <ObjectType>
* The type of object stored within the {@link Directory}.
*/
public interface DirectoryObjectEvent<ObjectType extends Identifiable>
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();
}

View File

@@ -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;
}