From 04cf8614c2ad95cc8b14924b6da86af5aef36a93 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 17 Nov 2023 11:37:44 +0100 Subject: [PATCH] fix: Fixed web ui access for identity with limited permissions [backport release-5.4.0] (#4989) fix: Fixed web ui access for identity with limited permissions (#4988) Signed-off-by: Nicola Timeus (cherry picked from commit 5a5a9b3de2f8197525d816433edf7d13dedac518) Co-authored-by: nicolatimeus --- .../web/client/ui/device/DevicePanelUi.java | 5 ++- .../kura/web/client/ui/device/LogTabUi.java | 25 +++++++++--- .../client/ui/firewall/FirewallPanelUi.java | 4 +- .../web/client/ui/network/NetworkPanelUi.java | 25 +++++++++++- .../web/client/ui/network/NetworkTabsUi.java | 38 +++++-------------- .../kura/web/client/ui/network/TabIp4Ui.java | 36 +++++------------- .../web/client/ui/network/TabWirelessUi.java | 21 ++-------- 7 files changed, 72 insertions(+), 82 deletions(-) diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/DevicePanelUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/DevicePanelUi.java index 176c487c737..eb350f4480f 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/DevicePanelUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/DevicePanelUi.java @@ -88,13 +88,14 @@ public DevicePanelUi() { this.systemProperties.addClickHandler(new Tab.RefreshHandler(this.systemPropertiesPanel)); this.containers.addClickHandler(new Tab.RefreshHandler(this.dockerContainersPanel)); - this.containers.setVisible(false); //hidden by default - checkIfContainerOrchestratorIsAvaliable(); + this.containers.setVisible(false); // hidden by default } public void initDevicePanel() { this.profilePanel.refresh(); this.commandPanel.setSession(this.session); + this.logPanel.initialize(); + checkIfContainerOrchestratorIsAvaliable(); } public void setSession(GwtSession currentSession) { diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.java index a49f39f29fb..769ef6332b3 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.java @@ -30,11 +30,11 @@ import org.eclipse.kura.web.shared.service.GwtSecurityTokenServiceAsync; import org.gwtbootstrap3.client.ui.Button; import org.gwtbootstrap3.client.ui.CheckBox; +import org.gwtbootstrap3.client.ui.Form; import org.gwtbootstrap3.client.ui.FormLabel; import org.gwtbootstrap3.client.ui.ListBox; import org.gwtbootstrap3.client.ui.Panel; import org.gwtbootstrap3.client.ui.Row; -import org.gwtbootstrap3.client.ui.Form; import com.google.gwt.core.client.GWT; import com.google.gwt.uibinder.client.UiBinder; @@ -90,6 +90,7 @@ interface LogTabUiUiBinder extends UiBinder { private final LinkedList logs = new LinkedList<>(); private boolean hasLogProvider = false; private boolean autoFollow = true; + private boolean initialized = false; private final String nonce = Integer.toString(Random.nextInt()); @@ -159,13 +160,23 @@ public void onSuccess(GwtXSRFToken token) { this.logTextArea.setReadOnly(true); this.logTextArea.addFocusHandler(focus -> LogTabUi.this.autoFollow = false); - initLogProviderListBox(); - this.showStackTraceCheckbox.setValue(true); this.showMoreInfoCheckbox.setValue(false); this.showStackTraceCheckbox.addClickHandler(click -> displayLogs()); this.showMoreInfoCheckbox.addClickHandler(click -> displayLogs()); + this.openNewWindow.addClickHandler(handler -> { + Window.open(Window.Location.getHref(), "_blank", ""); + }); + } + + public void initialize() { + if (initialized) { + return; + } + + initLogProviderListBox(); + LogPollService.subscribe(entries -> { if (LogTabUi.this.logs.size() + entries.size() > CACHE_SIZE_LIMIT) { for (int i = 0; i < entries.size(); i++) { @@ -177,9 +188,7 @@ public void onSuccess(GwtXSRFToken token) { displayLogs(); }); - this.openNewWindow.addClickHandler(handler -> { - Window.open(Window.Location.getHref(), "_blank", ""); - }); + initialized = true; } @Override @@ -233,6 +242,10 @@ public void onSuccess(List pids) { } LogTabUi.this.logProviderListBox.addChangeHandler(changeEvent -> displayLogs()); + + if (isAttached()) { + LogPollService.startLogPolling(); + } } } diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/firewall/FirewallPanelUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/firewall/FirewallPanelUi.java index 941694aaa6c..6ff4364afe2 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/firewall/FirewallPanelUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/firewall/FirewallPanelUi.java @@ -91,7 +91,7 @@ interface FirewallPanelUiUiBinder extends UiBinder { public FirewallPanelUi() { initWidget(uiBinder.createAndBindUi(this)); - detectIfNet2(); + this.firewallIntro.add(new Span("

" + MSGS.firewallIntro() + "

")); this.openPorts.setText(MSGS.firewallOpenPorts()); @@ -133,6 +133,8 @@ public void initFirewallPanel() { } this.openPorts.showTab(); + + detectIfNet2(); } public boolean isDirty() { diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkPanelUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkPanelUi.java index 81b25df2225..47cdaeaa6ee 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkPanelUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkPanelUi.java @@ -13,7 +13,10 @@ package org.eclipse.kura.web.client.ui.network; import org.eclipse.kura.web.client.messages.Messages; +import org.eclipse.kura.web.client.util.FailureHandler; import org.eclipse.kura.web.shared.model.GwtSession; +import org.eclipse.kura.web.shared.service.GwtNetworkService; +import org.eclipse.kura.web.shared.service.GwtNetworkServiceAsync; import org.gwtbootstrap3.client.ui.Container; import org.gwtbootstrap3.client.ui.Panel; import org.gwtbootstrap3.client.ui.PanelBody; @@ -22,6 +25,7 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.Widget; @@ -29,6 +33,7 @@ public class NetworkPanelUi extends Composite { private static NetworkPanelUiUiBinder uiBinder = GWT.create(NetworkPanelUiUiBinder.class); + private final GwtNetworkServiceAsync gwtNetworkService = GWT.create(GwtNetworkService.class); interface NetworkPanelUiUiBinder extends UiBinder { } @@ -58,8 +63,26 @@ public NetworkPanelUi() { } public void initNetworkPanel() { + + this.gwtNetworkService.isNet2(new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + initNetworkPanel(false); + FailureHandler.handle(caught); + } + + @Override + public void onSuccess(Boolean result) { + initNetworkPanel(result); + } + }); + } + + private void initNetworkPanel(final boolean isNet2) { + if (!this.isInitialized) { - this.tabs = new NetworkTabsUi(this.session); + this.tabs = new NetworkTabsUi(this.session, isNet2); this.tabsPanel.add(this.tabs); table = new NetworkInterfacesTableUi(this.session, this.tabs); diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkTabsUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkTabsUi.java index ece754a28c1..7744f794d90 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkTabsUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/NetworkTabsUi.java @@ -16,7 +16,6 @@ import java.util.List; import org.eclipse.kura.web.client.messages.Messages; -import org.eclipse.kura.web.client.util.FailureHandler; import org.eclipse.kura.web.client.util.MessageUtils; import org.eclipse.kura.web.shared.model.GwtModemInterfaceConfig; import org.eclipse.kura.web.shared.model.GwtNetIfStatus; @@ -34,7 +33,6 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; -import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Widget; @@ -94,38 +92,22 @@ interface NetworkTabsUiUiBinder extends UiBinder { * Initialization */ - public NetworkTabsUi(GwtSession session) { + public NetworkTabsUi(GwtSession session, final boolean isNet2) { initWidget(uiBinder.createAndBindUi(this)); this.visibleTabs = new LinkedList<>(); this.session = session; - detectIfNet2(); - initTabs(); + this.isNet2 = isNet2; + initTabs(isNet2); } - private void detectIfNet2() { - this.gwtNetworkService.isNet2(new AsyncCallback() { - - @Override - public void onFailure(Throwable caught) { - NetworkTabsUi.this.isNet2 = false; - FailureHandler.handle(caught); - } - - @Override - public void onSuccess(Boolean result) { - NetworkTabsUi.this.isNet2 = result; - } - }); - } - - private void initTabs() { + private void initTabs(final boolean isNet2) { this.tabsPanel.clear(); this.visibleTabs.clear(); - initIp4Tab(); + initIp4Tab(isNet2); initIp6Tab(); initWireless8021xTab(); - initWirelessTab(); + initWirelessTab(isNet2); initModemTab(); initModemGpsTab(); initModemAntennaTab(); @@ -138,9 +120,9 @@ private void initTabs() { this.content.add(this.ip4Tab); } - private void initIp4Tab() { + private void initIp4Tab(final boolean isNet2) { this.ip4TabAnchorItem = new AnchorListItem(MSGS.netIPv4()); - this.ip4Tab = new TabIp4Ui(this.session, this); + this.ip4Tab = new TabIp4Ui(this.session, this, isNet2); this.ip4TabAnchorItem.addClickHandler(event -> { setSelected(NetworkTabsUi.this.ip4TabAnchorItem); @@ -162,10 +144,10 @@ private void initIp6Tab() { }); } - private void initWirelessTab() { + private void initWirelessTab(final boolean isNet2) { this.wirelessTabAnchorItem = new AnchorListItem(MSGS.netWifiWireless()); this.wirelessTab = new TabWirelessUi(this.session, this.ip4Tab, this.set8021xTab, this.net8021xTabAnchorItem, - this); + this, isNet2); this.wirelessTabAnchorItem.addClickHandler(event -> { setSelected(NetworkTabsUi.this.wirelessTabAnchorItem); diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp4Ui.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp4Ui.java index c7ee383f8ba..e24250bb221 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp4Ui.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabIp4Ui.java @@ -155,7 +155,6 @@ interface TabTcpIpUiUiBinder extends UiBinder { IntegerBox priority; @UiField ListBox configure; - @UiField Button renew; @@ -171,7 +170,7 @@ interface TabTcpIpUiUiBinder extends UiBinder { @UiField FormControlStatic dnsRead; - + @UiField IntegerBox mtu; @@ -201,11 +200,15 @@ interface TabTcpIpUiUiBinder extends UiBinder { @UiField HelpButton mtuHelp; - public TabIp4Ui(GwtSession currentSession, NetworkTabsUi netTabs) { + public TabIp4Ui(GwtSession currentSession, NetworkTabsUi netTabs, final boolean isNet2) { initWidget(uiBinder.createAndBindUi(this)); this.tabs = netTabs; this.helpTitle.setText(MSGS.netHelpTitle()); - detectIfNet2(); + + this.isNet2 = isNet2; + + initNet2FeaturesOnly(isNet2); + initForm(); this.dnsRead.setVisible(false); @@ -385,23 +388,6 @@ public void clear() { // ---------------Private Methods------------ - private void detectIfNet2() { - this.gwtNetworkService.isNet2(new AsyncCallback() { - - @Override - public void onFailure(Throwable caught) { - TabIp4Ui.this.isNet2 = false; - FailureHandler.handle(caught); - } - - @Override - public void onSuccess(Boolean result) { - TabIp4Ui.this.isNet2 = result; - initNet2FeaturesOnly(result); - } - }); - } - private void initNet2FeaturesOnly(boolean isNet2) { this.labelPriority.setVisible(isNet2); this.priority.setVisible(isNet2); @@ -454,7 +440,7 @@ private void initForm() { initDnsServersField(); initDHCPLeaseField(); - + initMtuField(); } @@ -672,7 +658,7 @@ private void initConfigureField() { this.renew.setEnabled(false); } } - + private void initMtuField() { this.mtu.addMouseOverHandler(event -> { TabIp4Ui.this.helpText.clear(); @@ -703,7 +689,7 @@ private void initMtuField() { TabIp4Ui.this.helpMtu.setText(""); } }); - } + } private void initStatusField() { initStatusValues(); @@ -791,8 +777,6 @@ private void update() { this.mtu.setValue(this.selectedNetIfConfig.getMtu()); } - - this.tabs.updateTabs(); this.ip.setText(this.selectedNetIfConfig.getIpAddress()); this.subnet.setText(this.selectedNetIfConfig.getSubnetMask()); diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabWirelessUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabWirelessUi.java index 453a1b950bb..372bf24e801 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabWirelessUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/network/TabWirelessUi.java @@ -345,7 +345,7 @@ interface TabWirelessUiUiBinder extends UiBinder { Text unavailableChannelErrorText; public TabWirelessUi(GwtSession currentSession, TabIp4Ui tcp, Tab8021xUi wireless8021x, - AnchorListItem wireless8021xTabAnchorItem, NetworkTabsUi tabs) { + AnchorListItem wireless8021xTabAnchorItem, NetworkTabsUi tabs, final boolean isNet2) { this.ssidInit = false; initWidget(uiBinder.createAndBindUi(this)); this.session = currentSession; @@ -354,7 +354,8 @@ public TabWirelessUi(GwtSession currentSession, TabIp4Ui tcp, Tab8021xUi wireles this.wireless8021x = wireless8021x; this.wireless8021xTabAnchorItem = wireless8021xTabAnchorItem; - detectIfNet2(); + this.isNet2 = isNet2; + changeRadioModeToBand(isNet2); initForm(); initHelpButtons(); @@ -513,22 +514,6 @@ public void clear() { // -----Private methods-------// - private void detectIfNet2() { - this.gwtNetworkService.isNet2(new AsyncCallback() { - - @Override - public void onFailure(Throwable caught) { - FailureHandler.handle(caught); - } - - @Override - public void onSuccess(Boolean isNet2) { - TabWirelessUi.this.isNet2 = isNet2; - changeRadioModeToBand(isNet2); - } - }); - } - private void changeRadioModeToBand(boolean isNet2) { if (isNet2) { this.radioHelp.setHelpText(MSGS.netWifiToolTipBand());