Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web2): Updated web2 for the new network service #4353

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kura/org.eclipse.kura.web2/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Import-Package: com.eclipsesource.json;version="0.9.5",
org.eclipse.kura.log.listener;version="[1.0,2.0)",
org.eclipse.kura.marshalling;version="[1.0,2.0)",
org.eclipse.kura.net;version="[2.1,3.0)",
org.eclipse.kura.net.admin;version="[1.6,3.0)",
org.eclipse.kura.net.dhcp;version="[1.0,2.0)",
org.eclipse.kura.net.firewall;version="[2.0,3.0)",
org.eclipse.kura.net.modem;version="[2.2,3.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
import org.eclipse.kura.web.server.GwtKeystoreServiceImpl;
import org.eclipse.kura.web.server.GwtLogServiceImpl;
import org.eclipse.kura.web.server.GwtLoginInfoServiceImpl;
import org.eclipse.kura.web.server.GwtNetworkServiceImpl;
import org.eclipse.kura.web.server.GwtPackageServiceImpl;
import org.eclipse.kura.web.server.GwtNetworkServiceImplFacade;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update copyright header

import org.eclipse.kura.web.server.GwtPasswordAuthenticationServiceImpl;
import org.eclipse.kura.web.server.GwtSecurityServiceImpl;
import org.eclipse.kura.web.server.GwtSecurityTokenServiceImpl;
Expand All @@ -62,6 +61,7 @@
import org.eclipse.kura.web.server.GwtUserServiceImpl;
import org.eclipse.kura.web.server.GwtWireGraphServiceImpl;
import org.eclipse.kura.web.server.KuraRemoteServiceServlet;
import org.eclipse.kura.web.server.GwtPackageServiceImpl;
import org.eclipse.kura.web.server.servlet.ChannelServlet;
import org.eclipse.kura.web.server.servlet.DeviceSnapshotsServlet;
import org.eclipse.kura.web.server.servlet.FileServlet;
Expand Down Expand Up @@ -389,28 +389,33 @@ private HttpContext initSessionContext(final HttpContext defaultContext) {
final SecurityHandler sessionExpirationHandler = new SessionExpirationSecurityHandler();
final SecurityHandler sessionLockedSecurityHandler = new SessionLockedSecurityHandler();

// default session handler requires an authenticated session and handles session expiration, handles session
// default session handler requires an authenticated session and handles session
// expiration, handles session
// lock
final SecurityHandler defaultHandler = chain(baseHandler, sessionAuthHandler, sessionLockedSecurityHandler,
sessionExpirationHandler);

final RoutingSecurityHandler routingHandler = new RoutingSecurityHandler(
defaultHandler.sendErrorOnFailure(401));

// exception on authentication paths, allow access without authenticaton but create a session
// exception on authentication paths, allow access without authenticaton but
// create a session
routingHandler.addRouteHandler(
p -> this.authenticationPaths.contains(p)
|| this.loginServlets.stream().anyMatch(r -> r.path.contentEquals(p)),
chain(baseHandler, new CreateSessionSecurityHandler()));

// exception on event paths, activity on these paths does not count towards session expiration
// exception on event paths, activity on these paths does not count towards
// session expiration
routingHandler.addRouteHandler(eventPaths::contains,
chain(baseHandler, sessionAuthHandler).sendErrorOnFailure(401));

// exception on admin console path, redirect to login page on failure instead of sending 401 status
// exception on admin console path, redirect to login page on failure instead of
// sending 401 status
routingHandler.addRouteHandler(CONSOLE_PATH::equals, defaultHandler.redirectOnFailure(AUTH_PATH));

// exception on login session and xsrf path, like default but without locked session checking
// exception on login session and xsrf path, like default but without locked
// session checking
routingHandler.addRouteHandler(
Arrays.asList(LOGIN_MODULE_PATH + SESSION, LOGIN_MODULE_PATH + "/xsrf")::contains,
chain(baseHandler, sessionAuthHandler, sessionExpirationHandler));
Expand Down Expand Up @@ -468,7 +473,7 @@ private synchronized void initHTTPService() throws NamespaceException, ServletEx
this.sessionContext);
this.httpService.registerServlet(DENALI_MODULE_PATH + "/logservice", new GwtLogServiceImpl(), null,
this.sessionContext);
this.httpService.registerServlet(DENALI_MODULE_PATH + "/network", new GwtNetworkServiceImpl(), null,
this.httpService.registerServlet(DENALI_MODULE_PATH + "/network", new GwtNetworkServiceImplFacade(), null,
this.sessionContext);
this.httpService.registerServlet(DENALI_MODULE_PATH + "/component", new GwtComponentServiceImpl(), null,
this.sessionContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
/*******************************************************************************
* Copyright (c) 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.web.server;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.eclipse.kura.net.NetworkAdminService;
import org.eclipse.kura.web.server.util.ServiceLocator;
import org.eclipse.kura.web.shared.GwtKuraException;
import org.eclipse.kura.web.shared.model.GwtFirewallNatEntry;
import org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry;
import org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry;
import org.eclipse.kura.web.shared.model.GwtModemPdpEntry;
import org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig;
import org.eclipse.kura.web.shared.model.GwtWifiChannelFrequency;
import org.eclipse.kura.web.shared.model.GwtWifiConfig;
import org.eclipse.kura.web.shared.model.GwtWifiHotspotEntry;
import org.eclipse.kura.web.shared.model.GwtWifiRadioMode;
import org.eclipse.kura.web.shared.model.GwtXSRFToken;
import org.eclipse.kura.web.shared.service.GwtNetworkService;

public class GwtNetworkServiceImplFacade extends OsgiRemoteServiceServlet implements GwtNetworkService {

private static final long serialVersionUID = -4188750359099902616L;

private static Optional<Boolean> isNet2 = Optional.empty();

@Override
public List<GwtNetInterfaceConfig> findNetInterfaceConfigurations(boolean recompute)
throws GwtKuraException {

if (isNet2()) {
return org.eclipse.kura.web.server.net2.GwtNetworkServiceImpl.findNetInterfaceConfigurations(recompute);
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.findNetInterfaceConfigurations(recompute);
}
}

@Override
public void updateNetInterfaceConfigurations(GwtXSRFToken xsrfToken, GwtNetInterfaceConfig config)
throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
org.eclipse.kura.web.server.net2.GwtNetworkServiceImpl.updateNetInterfaceConfigurations(config);
} else {
org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.updateNetInterfaceConfigurations(config);
}
}

@Override
public ArrayList<GwtFirewallOpenPortEntry> findDeviceFirewallOpenPorts(GwtXSRFToken xsrfToken)
throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
return (ArrayList<GwtFirewallOpenPortEntry>) org.eclipse.kura.web.server.net2.GwtNetworkServiceImpl
.findDeviceFirewallOpenPorts();
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.findDeviceFirewallOpenPorts();
}
}

@Override
public ArrayList<GwtWifiHotspotEntry> findWifiHotspots(GwtXSRFToken xsrfToken, String interfaceName,
String wirelessSsid) throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
// TODO
return new ArrayList<>();
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.findWifiHotspots(interfaceName, wirelessSsid);
}
}

@Override
public List<GwtModemPdpEntry> findPdpContextInfo(GwtXSRFToken xsrfToken, String interfaceName)
throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
// TODO
return new ArrayList<>();
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.findPdpContextInfo(interfaceName);
}
}

@Override
public boolean verifyWifiCredentials(GwtXSRFToken xsrfToken, String interfaceName, GwtWifiConfig gwtWifiConfig)
throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
// TODO
return false;
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.verifyWifiCredentials(interfaceName,
gwtWifiConfig);
}
}

@Override
public ArrayList<GwtFirewallPortForwardEntry> findDeviceFirewallPortForwards(GwtXSRFToken xsrfToken)
throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
return (ArrayList<GwtFirewallPortForwardEntry>) org.eclipse.kura.web.server.net2.GwtNetworkServiceImpl
.findDeviceFirewallPortForwards();
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.findDeviceFirewallPortForwards();
}
}

@Override
public ArrayList<GwtFirewallNatEntry> findDeviceFirewallNATs(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
return (ArrayList<GwtFirewallNatEntry>) org.eclipse.kura.web.server.net2.GwtNetworkServiceImpl
.findDeviceFirewallNATs();
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.findDeviceFirewallNATs();
}
}

@Override
public void updateDeviceFirewallOpenPorts(GwtXSRFToken xsrfToken, List<GwtFirewallOpenPortEntry> entries)
throws GwtKuraException {
checkXSRFToken(xsrfToken);

org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.updateDeviceFirewallOpenPorts(entries);
}

@Override
public void updateDeviceFirewallPortForwards(GwtXSRFToken xsrfToken, List<GwtFirewallPortForwardEntry> entries)
throws GwtKuraException {
checkXSRFToken(xsrfToken);

org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.updateDeviceFirewallPortForwards(entries);
}

@Override
public void updateDeviceFirewallNATs(GwtXSRFToken xsrfToken, List<GwtFirewallNatEntry> entries)
throws GwtKuraException {
checkXSRFToken(xsrfToken);

org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.updateDeviceFirewallNATs(entries);
}

@Override
public void renewDhcpLease(GwtXSRFToken xsrfToken, String interfaceName) throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
// TODO
} else {
org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.renewDhcpLease(interfaceName);
}
}

@Override
public List<GwtWifiChannelFrequency> findFrequencies(GwtXSRFToken xsrfToken, String interfaceName,
GwtWifiRadioMode radioMode) throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
// TODO
return new ArrayList<>();
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.findFrequencies(interfaceName, radioMode);
}
}

@Override
public String getWifiCountryCode(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
// TODO
return "";
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.getWifiCountryCode();
}
}

@Override
public boolean isIEEE80211ACSupported(GwtXSRFToken xsrfToken, String ifaceName) throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
// TODO
return false;
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.isIEEE80211ACSupported(ifaceName);
}
}

@Override
public List<String> getDhcpLeases(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);

if (isNet2()) {
// TODO
return new ArrayList<>();
} else {
return org.eclipse.kura.web.server.net.GwtNetworkServiceImpl.getDhcpLeases();
}
}

private static boolean isNet2() {
if (isNet2.isPresent()) {
return isNet2.get();
}

try {
ServiceLocator.getInstance().getService(NetworkAdminService.class);
isNet2 = Optional.of(false);
return false;
} catch (GwtKuraException networkAdminServiceNotFound) {
isNet2 = Optional.of(true);
return true;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2011, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -269,7 +269,7 @@ private static List<GwtGroupedNVPair> getNetworkStatus(boolean recompute) throws
String nl = "<br />";
String tab = "&nbsp&nbsp&nbsp&nbsp";

GwtNetworkServiceImpl gwtNetworkService = new GwtNetworkServiceImpl();
GwtNetworkServiceImplFacade gwtNetworkService = new GwtNetworkServiceImplFacade();

List<GwtNetInterfaceConfig> gwtNetInterfaceConfigs;

Expand Down
Loading