Skip to content

Commit

Permalink
fix: Fixed web ui access for identity with limited permissions [backp…
Browse files Browse the repository at this point in the history
…ort release-5.4.0] (#4989)

fix: Fixed web ui access for identity with limited permissions (#4988)

Signed-off-by: Nicola Timeus <[email protected]>
(cherry picked from commit 5a5a9b3)

Co-authored-by: nicolatimeus <[email protected]>
  • Loading branch information
github-actions[bot] and nicolatimeus authored Nov 17, 2023
1 parent a2741e1 commit 04cf861
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,6 +90,7 @@ interface LogTabUiUiBinder extends UiBinder<Widget, LogTabUi> {
private final LinkedList<GwtLogEntry> logs = new LinkedList<>();
private boolean hasLogProvider = false;
private boolean autoFollow = true;
private boolean initialized = false;

private final String nonce = Integer.toString(Random.nextInt());

Expand Down Expand Up @@ -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++) {
Expand All @@ -177,9 +188,7 @@ public void onSuccess(GwtXSRFToken token) {
displayLogs();
});

this.openNewWindow.addClickHandler(handler -> {
Window.open(Window.Location.getHref(), "_blank", "");
});
initialized = true;
}

@Override
Expand Down Expand Up @@ -233,6 +242,10 @@ public void onSuccess(List<String> pids) {
}

LogTabUi.this.logProviderListBox.addChangeHandler(changeEvent -> displayLogs());

if (isAttached()) {
LogPollService.startLogPolling();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ interface FirewallPanelUiUiBinder extends UiBinder<Widget, FirewallPanelUi> {
public FirewallPanelUi() {

initWidget(uiBinder.createAndBindUi(this));
detectIfNet2();

this.firewallIntro.add(new Span("<p>" + MSGS.firewallIntro() + "</p>"));

this.openPorts.setText(MSGS.firewallOpenPorts());
Expand Down Expand Up @@ -133,6 +133,8 @@ public void initFirewallPanel() {
}

this.openPorts.showTab();

detectIfNet2();
}

public boolean isDirty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,13 +25,15 @@
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;

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<Widget, NetworkPanelUi> {
}
Expand Down Expand Up @@ -58,8 +63,26 @@ public NetworkPanelUi() {
}

public void initNetworkPanel() {

this.gwtNetworkService.isNet2(new AsyncCallback<Boolean>() {

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -94,38 +92,22 @@ interface NetworkTabsUiUiBinder extends UiBinder<Widget, NetworkTabsUi> {
* 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<Boolean>() {

@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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ interface TabTcpIpUiUiBinder extends UiBinder<Widget, TabIp4Ui> {
IntegerBox priority;
@UiField
ListBox configure;


@UiField
Button renew;
Expand All @@ -171,7 +170,7 @@ interface TabTcpIpUiUiBinder extends UiBinder<Widget, TabIp4Ui> {

@UiField
FormControlStatic dnsRead;

@UiField
IntegerBox mtu;

Expand Down Expand Up @@ -201,11 +200,15 @@ interface TabTcpIpUiUiBinder extends UiBinder<Widget, TabIp4Ui> {
@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);

Expand Down Expand Up @@ -385,23 +388,6 @@ public void clear() {

// ---------------Private Methods------------

private void detectIfNet2() {
this.gwtNetworkService.isNet2(new AsyncCallback<Boolean>() {

@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);
Expand Down Expand Up @@ -454,7 +440,7 @@ private void initForm() {
initDnsServersField();

initDHCPLeaseField();

initMtuField();
}

Expand Down Expand Up @@ -672,7 +658,7 @@ private void initConfigureField() {
this.renew.setEnabled(false);
}
}

private void initMtuField() {
this.mtu.addMouseOverHandler(event -> {
TabIp4Ui.this.helpText.clear();
Expand Down Expand Up @@ -703,7 +689,7 @@ private void initMtuField() {
TabIp4Ui.this.helpMtu.setText("");
}
});
}
}

private void initStatusField() {
initStatusValues();
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ interface TabWirelessUiUiBinder extends UiBinder<Widget, TabWirelessUi> {
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;
Expand All @@ -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();
Expand Down Expand Up @@ -513,22 +514,6 @@ public void clear() {

// -----Private methods-------//

private void detectIfNet2() {
this.gwtNetworkService.isNet2(new AsyncCallback<Boolean>() {

@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());
Expand Down

0 comments on commit 04cf861

Please sign in to comment.