Frank Kobzik has uploaded a new change for review. Change subject: engine: Display warning before overtaking spice console ......................................................................
engine: Display warning before overtaking spice console This patch adds a displaying popup window when an user is overtaking (spice or VNC) console that has been already in use. The popup window is displayed if these conditions hold: - "allow console reconnect" feature is disabled - there is a user currently connected to the console and following conditions hold: - the user currently connected to the console is different from the user who is trying to connect - the user currently connected to the console has not permissions to reconnect (steal) console Changes on backend: - Added command for getting role action groups for user. Changes on frontend: - Added methods for checking safeness of console connecting operation and displaying confirm popup. Change-Id: Iffce89a0c7bdd0cccb71943f398f0f907fbed002 Signed-off-by: Frantisek Kobzik <fkob...@redhat.com> Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=868297 --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CanUpdateFieldGenericQuery.java A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetRoleActionGroupsByUserIdQuery.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmConsoleDataCommand.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetRoleActionGroupsByUserIdParameters.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java M frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java 11 files changed, 195 insertions(+), 37 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/70/10770/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CanUpdateFieldGenericQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CanUpdateFieldGenericQuery.java index 6413e13..f08822e 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CanUpdateFieldGenericQuery.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CanUpdateFieldGenericQuery.java @@ -1,7 +1,7 @@ package org.ovirt.engine.core.bll; -import org.ovirt.engine.core.common.queries.*; -import org.ovirt.engine.core.utils.*; +import org.ovirt.engine.core.common.queries.CanUpdateFieldGenericParameters; +import org.ovirt.engine.core.utils.ObjectIdentityChecker; public class CanUpdateFieldGenericQuery<P extends CanUpdateFieldGenericParameters> extends QueriesCommandBase<P> { public CanUpdateFieldGenericQuery(P parameters) { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetRoleActionGroupsByUserIdQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetRoleActionGroupsByUserIdQuery.java new file mode 100644 index 0000000..c301ee9 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetRoleActionGroupsByUserIdQuery.java @@ -0,0 +1,36 @@ +package org.ovirt.engine.core.bll; + +import java.util.ArrayList; +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.ActionGroup; +import org.ovirt.engine.core.common.businessentities.permissions; +import org.ovirt.engine.core.common.queries.GetRoleActionGroupsByUserIdParameters; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.compat.NGuid; + +public class GetRoleActionGroupsByUserIdQuery<P extends GetRoleActionGroupsByUserIdParameters> + extends QueriesCommandBase<P> +{ + + public GetRoleActionGroupsByUserIdQuery(P parameters) { + super(parameters); + } + + @Override + protected void executeQueryCommand() { + NGuid userId = getParameters().getUserId(); + + List <permissions> permissions = getDbFacade().getPermissionDao().getAllForAdElement(userId.getValue()); + List<ActionGroup> result = new ArrayList<ActionGroup>(); + for (permissions permission : permissions) { + Guid roleId = permission.getrole_id(); + List<ActionGroup> actionGroups = getDbFacade().getActionGroupDao().getAllForRole(roleId); + + result.addAll(actionGroups); + } + + getQueryReturnValue().setReturnValue(result); + } + +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmConsoleDataCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmConsoleDataCommand.java index 2207655..7ff7fce 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmConsoleDataCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmConsoleDataCommand.java @@ -31,7 +31,7 @@ vm.setConsoleCurrentUserName(getParameters().getConsoleUserName()); VDSParametersBase updateVmDynamicParams = - new UpdateVmDynamicDataVDSCommandParameters(getVdsId(), vm.getDynamicData()); + new UpdateVmDynamicDataVDSCommandParameters(getVm().getRunOnVds().getValue(), vm.getDynamicData()); runVdsCommand(VDSCommandType.UpdateVmDynamicData, updateVmDynamicParams); setSucceeded(true); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetRoleActionGroupsByUserIdParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetRoleActionGroupsByUserIdParameters.java new file mode 100644 index 0000000..15f9996 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetRoleActionGroupsByUserIdParameters.java @@ -0,0 +1,25 @@ +package org.ovirt.engine.core.common.queries; + +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.compat.NGuid; + +public class GetRoleActionGroupsByUserIdParameters extends VdcQueryParametersBase { + + private static final long serialVersionUID = -2361449851899615454L; + + private NGuid userId; + + public GetRoleActionGroupsByUserIdParameters(NGuid nGuid) { + super(); + this.userId = nGuid; + } + + public NGuid getUserId() { + return userId; + } + + public void setUserId(Guid userId) { + this.userId = userId; + } + +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java index 5c18ced..85c3fa3 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/VdcQueryType.java @@ -206,6 +206,7 @@ GetRolesByAdElementId, GetPermissionsByAdElementId(VdcQueryAuthType.User), GetRoleActionGroupsByRoleId(VdcQueryAuthType.User), + GetRoleActionGroupsByUserId(VdcQueryAuthType.User), IsUserPowerUserOrAbove, GetRolesForDelegationByUser, GetPermissionsForObject(VdcQueryAuthType.User), diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java index d0f40fa..3e872da 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/userportal/IUserPortalListModel.java @@ -173,9 +173,9 @@ { SpiceConsoleModel spiceConsoleModel = new SpiceConsoleModel(); spiceConsoleModel.getErrorEvent().addListener(this); - spiceConsoleModel.setModel(this); + spiceConsoleModel.setParentModel(this); VncConsoleModel vncConsoleModel = new VncConsoleModel(); - vncConsoleModel.setModel(this); + vncConsoleModel.setParentModel(this); RdpConsoleModel rdpConsoleModel = new RdpConsoleModel(); cachedConsoleModels.put(vm.getId(), diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java index d4ae410..cc26f12 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/ConsoleModel.java @@ -1,15 +1,27 @@ package org.ovirt.engine.ui.uicommonweb.models.vms; +import java.util.List; + +import org.ovirt.engine.core.common.businessentities.ActionGroup; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VMStatus; +import org.ovirt.engine.core.common.queries.GetRoleActionGroupsByUserIdParameters; +import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; +import org.ovirt.engine.core.common.queries.VdcQueryType; import org.ovirt.engine.core.compat.Event; import org.ovirt.engine.core.compat.EventDefinition; import org.ovirt.engine.core.compat.PropertyChangedEventArgs; +import org.ovirt.engine.ui.frontend.AsyncQuery; +import org.ovirt.engine.ui.frontend.Frontend; +import org.ovirt.engine.ui.frontend.INewAsyncCallback; +import org.ovirt.engine.ui.uicommonweb.BaseCommandTarget; import org.ovirt.engine.ui.uicommonweb.UICommand; +import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel; import org.ovirt.engine.ui.uicommonweb.models.EntityModel; +import org.ovirt.engine.ui.uicommonweb.models.Model; +import org.ovirt.engine.ui.uicompat.ConstantsManager; -public abstract class ConsoleModel extends EntityModel -{ +public abstract class ConsoleModel extends EntityModel { public static final String EjectLabel = "[Eject]"; //$NON-NLS-1$ public static EventDefinition ErrorEventDefinition; @@ -103,6 +115,16 @@ super.setEntity(value); } + /** + * This attribute is a workaround for displaying popup dialogs + * in console models. + */ + protected Model parentModel; + + public void setParentModel(Model parentModel) { + this.parentModel = parentModel; + } + static { ErrorEventDefinition = new EventDefinition("Error", ConsoleModel.class); //$NON-NLS-1$ @@ -176,4 +198,70 @@ return false; } } + + /** + * Executes given command. The confirmation dialog is displayed when it's + * not safe to take over the console. + * + * @param command + */ + protected void executeCommandWithConsoleSafenessWarning(final UICommand command) { + VM vm = getEntity(); + if (vm.getAllowConsoleReconnect() || vm.getConsoleUserId() == null || + vm.getConsoleUserId().equals(Frontend.getLoggedInUser().getUserId())) { + command.Execute(); + return; + } + + //now we ask if the currently connected user has permission to reconnect (async) + GetRoleActionGroupsByUserIdParameters params = + new GetRoleActionGroupsByUserIdParameters(vm.getConsoleUserId()); + + AsyncQuery query = new AsyncQuery(); + query.setModel(this); + query.asyncCallback = new INewAsyncCallback() { + @Override + public void OnSuccess(Object model, Object result) + { + VdcQueryReturnValue returnValue = (VdcQueryReturnValue) result; + List<ActionGroup> resultList = ((List<ActionGroup>) returnValue.getReturnValue()); + if (resultList.contains(ActionGroup.RECONNECT_TO_VM)) { + command.Execute(); + } else { + displayConsoleConnectConfirmPopup(command); + } + } + }; + Frontend.RunQuery(VdcQueryType.GetRoleActionGroupsByUserId, params, query); + } + + private void displayConsoleConnectConfirmPopup(final UICommand onConfirmCommand) { + ConfirmationModel model = new ConfirmationModel(); + parentModel.setWindow(model); + model.setTitle(ConstantsManager.getInstance().getConstants().confirmConsoleConnect()); + model.setHashName("confirm_console_connect"); //$NON-NLS-1$ + model.setMessage(ConstantsManager.getInstance().getConstants().confirmConsoleConnectMessage()); + + UICommand confirmAndCloseCommand = new UICommand("Confirm", new BaseCommandTarget() { //$NON-NLS-1$ + @Override + public void ExecuteCommand(UICommand uiCommand) { + onConfirmCommand.Execute(); + parentModel.setWindow(null); + } + }); + confirmAndCloseCommand.setTitle(ConstantsManager.getInstance().getConstants().ok()); + confirmAndCloseCommand.setIsDefault(true); + model.getCommands().add(confirmAndCloseCommand); + + UICommand cancelCommand = new UICommand("Cancel", new BaseCommandTarget() { //$NON-NLS-1$ + @Override + public void ExecuteCommand(UICommand uiCommand) { + parentModel.setWindow(null); + } + }); + cancelCommand.setTitle(ConstantsManager.getInstance().getConstants().cancel()); + cancelCommand.setIsCancel(true); + model.getCommands().add(cancelCommand); + } + } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java index ff723e2..0779b0e 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/SpiceConsoleModel.java @@ -44,7 +44,6 @@ import org.ovirt.engine.ui.uicommonweb.TypeResolver; import org.ovirt.engine.ui.uicommonweb.UICommand; import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider; -import org.ovirt.engine.ui.uicommonweb.models.Model; import org.ovirt.engine.ui.uicompat.ConstantsManager; import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult; import org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult; @@ -63,7 +62,6 @@ private SpiceMenu menu; private ISpice privatespice; - private Model model; public ISpice getspice() { return privatespice; @@ -126,7 +124,14 @@ getspice().setIsWanOptionsEnabled(false); } - SendVmTicket(); + UICommand setVmTicketCommand = new UICommand("setVmCommand", new BaseCommandTarget() { //$NON-NLS-1$ + @Override + public void ExecuteCommand(UICommand uiCommand) { + setVmTicket(); + } + }); + executeCommandWithConsoleSafenessWarning(setVmTicketCommand); + } } @@ -520,7 +525,7 @@ _asyncQuery); } - private void SendVmTicket() { + private void setVmTicket() { // Create ticket for single sign on. Frontend.RunAction(VdcActionType.SetVmTicket, new SetVmTicketParameters(getEntity().getId(), null, 120), new IFrontendActionAsyncCallback() { @@ -570,14 +575,14 @@ logonCommandReturnValue.getDescription() : ""); //$NON-NLS-1$ spiceConsoleModel.ExecuteQuery(getEntity()); - model.setWindow(null); + parentModel.setWindow(null); } }); UICommand cancelCommand = new UICommand("SpiceWithoutAgentCancel", new BaseCommandTarget() { //$NON-NLS-1$ @Override public void ExecuteCommand(UICommand uiCommand) { - model.setWindow(null); + parentModel.setWindow(null); } }); @@ -616,7 +621,7 @@ cancelCommand.setIsCancel(true); spiceWithoutAgentModel.getCommands().add(cancelCommand); - model.setWindow(spiceWithoutAgentModel); + parentModel.setWindow(spiceWithoutAgentModel); } private void logSsoOnDesktopFailedAgentNonResp(ILogger logger, String vmName) { @@ -636,10 +641,6 @@ } catch (RuntimeException ex) { getLogger().Error("Exception on Spice connect", ex); //$NON-NLS-1$ } - } - - public void setModel(Model model) { - this.model = model; } private static final String CommandStop = "Stop"; //$NON-NLS-1$ diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java index 840a602..fd8fa4a 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java @@ -743,9 +743,10 @@ if (!cachedConsoleModels.containsKey(vm.getId())) { SpiceConsoleModel spiceConsoleModel = new SpiceConsoleModel(); + spiceConsoleModel.setParentModel(this); spiceConsoleModel.getErrorEvent().addListener(this); VncConsoleModel vncConsoleModel = new VncConsoleModel(); - vncConsoleModel.setModel(this); + vncConsoleModel.setParentModel(this); RdpConsoleModel rdpConsoleModel = new RdpConsoleModel(); cachedConsoleModels.put(vm.getId(), diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java index 04a2f88..837eb56 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VncConsoleModel.java @@ -12,9 +12,9 @@ import org.ovirt.engine.ui.frontend.AsyncQuery; import org.ovirt.engine.ui.frontend.Frontend; import org.ovirt.engine.ui.frontend.INewAsyncCallback; +import org.ovirt.engine.ui.uicommonweb.BaseCommandTarget; import org.ovirt.engine.ui.uicommonweb.TypeResolver; import org.ovirt.engine.ui.uicommonweb.UICommand; -import org.ovirt.engine.ui.uicommonweb.models.Model; import org.ovirt.engine.ui.uicompat.ConstantsManager; import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult; import org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback; @@ -24,7 +24,6 @@ { private final IVnc vnc; String otp64 = null; - private Model model; private static final int seconds = 120; public VncConsoleModel() @@ -37,16 +36,23 @@ @Override protected void Connect() { - if (getEntity() != null) - { - getLogger().Debug("VNC console info..."); //$NON-NLS-1$ + if (getEntity() == null || getEntity().getRunOnVds() == null) { + return; + } + getLogger().Debug("VNC console info..."); //$NON-NLS-1$ - // Don't connect if there VM is not running on any host. - if (getEntity().getRunOnVds() == null) - { - return; + UICommand setVmTicketCommand = new UICommand("setVmCommand", new BaseCommandTarget() { //$NON-NLS-1$ + @Override + public void ExecuteCommand(UICommand uiCommand) { + setVmTicket(); } - Frontend.RunAction(VdcActionType.SetVmTicket, new SetVmTicketParameters(getEntity().getId(), + }); + + executeCommandWithConsoleSafenessWarning(setVmTicketCommand); + } + + private void setVmTicket() { + Frontend.RunAction(VdcActionType.SetVmTicket, new SetVmTicketParameters(getEntity().getId(), null, seconds), new IFrontendActionAsyncCallback() { @@ -81,7 +87,6 @@ } } }); - } } protected void postGetHost(String hostName) { @@ -94,10 +99,10 @@ (getEntity().getDisplay() == null ? 0 : getEntity().getDisplay()), otp64, seconds)); - infoModel.setCloseCommand(new UICommand("closeVncInfo", model)); //$NON-NLS-1$ + infoModel.setCloseCommand(new UICommand("closeVncInfo", parentModel)); //$NON-NLS-1$ infoModel.getCloseCommand().setTitle(ConstantsManager.getInstance().getConstants().close()); infoModel.getCommands().add(infoModel.getCloseCommand()); - model.setWindow(infoModel); + parentModel.setWindow(infoModel); } @Override @@ -111,9 +116,5 @@ && (getEntity().getStatus() == VMStatus.PoweringUp || getEntity().getStatus() == VMStatus.Up || getEntity().getStatus() == VMStatus.RebootInProgress || getEntity().getStatus() == VMStatus.PoweringDown || getEntity().getStatus() == VMStatus.Paused)); - } - - public void setModel(Model model) { - this.model = model; } } diff --git a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java index d553103..9fb1811 100644 --- a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java +++ b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/Constants.java @@ -1675,7 +1675,6 @@ String detachGlusterHostsTitle(); // Vnic - @DefaultStringValue("In order to change 'Type' please Unplug and then Plug again") String hotTypeUpdateNotPossible(); @@ -1690,4 +1689,10 @@ @DefaultStringValue("Updating 'Port Mirroring' on a running virtual machine while the NIC is plugged is not supported") String hotPortMirroringUpdateNotSupported(); + + @DefaultStringValue("Console connect") + String confirmConsoleConnect(); + + @DefaultStringValue("There are users who will not be able to reconnect connected to the console. Do you want to proceed?") + String confirmConsoleConnectMessage(); } -- To view, visit http://gerrit.ovirt.org/10770 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iffce89a0c7bdd0cccb71943f398f0f907fbed002 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Frank Kobzik <fkob...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches