Skip to content

Commit

Permalink
functional web console
Browse files Browse the repository at this point in the history
Signed-off-by: Nicola Timeus <[email protected]>
  • Loading branch information
nicolatimeus committed Dec 23, 2024
1 parent dbdff5b commit 46b2c72
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyStore;
import java.security.cert.PKIXRevocationChecker;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.EventListener;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.Deflater;

import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
Expand Down Expand Up @@ -66,7 +71,8 @@ public class JettyServerHolder {
true);

private final HttpServiceOptions options;
private Server server;
private final Server server;
private final File workDir;

public JettyServerHolder(final HttpServiceOptions options, final Optional<KeystoreService> keystoreService,
final HttpServlet httpServlet, final EventListener eventListener) {
Expand All @@ -77,6 +83,11 @@ public JettyServerHolder(final HttpServiceOptions options, final Optional<Keysto
// TODO restore after debugging
// this.server.setErrorHandler(new KuraErrorHandler());

final BundleContext context = FrameworkUtil.getBundle(JettyServerHolder.class).getBundleContext();
this.workDir = new File(context.getDataFile(""), "jettyWorkDir_" + System.nanoTime()); // TODO evaluate
// configurability
this.workDir.mkdir();

for (int port : this.options.getHttpPorts()) {
ServerConnector httpConnector = createHttpConnector(port);
addConnector(httpConnector);
Expand All @@ -102,7 +113,9 @@ public JettyServerHolder(final HttpServiceOptions options, final Optional<Keysto
}

ServletHolder holder = new ServletHolder(httpServlet);
holder.setAsyncSupported(true);
holder.setInitOrder(0);

ServletContextHandler httpContext = createServletContextHandler();
httpContext.addServlet(holder, "/*");
httpContext.addEventListener(eventListener);
Expand All @@ -128,14 +141,10 @@ public JettyServerHolder(final HttpServiceOptions options, final Optional<Keysto
private ServletContextHandler createServletContextHandler() {

ServletContextHandler servletContextHandler = new ServletContextHandler();
servletContextHandler.setClassLoader(this.getClass().getClassLoader());
servletContextHandler.setClassLoader(JettyServerHolder.class.getClassLoader());
servletContextHandler.setContextPath("/"); // TODO evaluate configurability

BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
File jettyWorkDir = new File(context.getDataFile(""), "jettyWorkDir_"); // TODO evaluate configurability
jettyWorkDir.mkdir();

servletContextHandler.setAttribute("jakarta.servlet.context.tempdir", jettyWorkDir);
servletContextHandler.setAttribute("jakarta.servlet.context.tempdir", this.workDir);
SessionHandler handler = new SessionHandler();
// handler.setMaxInactiveInterval(-1); // TODO evaluate configurability
servletContextHandler.setSessionHandler(handler);
Expand Down Expand Up @@ -222,15 +231,15 @@ private void addCustomizer(final ServerConnector connector, final Customizer cus

private static class BlockHttpMethods implements HttpConfiguration.Customizer {

private final Set<HttpMethod> blockedMethods;
private final Set<String> blockedMethods;

public BlockHttpMethods(Set<HttpMethod> methods) {
this.blockedMethods = methods;
this.blockedMethods = methods.stream().map(m -> m.toString().toLowerCase()).collect(Collectors.toSet());
}

@Override
public Request customize(Request request, Mutable responseHeaders) {
if (this.blockedMethods.contains(HttpMethod.TRACE)) {
if (this.blockedMethods.contains(request.getMethod().toLowerCase())) {
return new ErrorRequest(request, HttpStatus.METHOD_NOT_ALLOWED_405, "Method now allowed.", null);
}

Expand Down Expand Up @@ -303,6 +312,12 @@ public void stop() {
} catch (Exception e) {
logger.warn("Unable to stop the Jetty server", e);
}

try (final Stream<Path> stream = Files.walk(this.workDir.toPath())) {
stream.map(Path::toFile).sorted(Comparator.reverseOrder()).forEach(File::delete);
} catch (Exception e) {
logger.warn("Unable to cleanp jetty workdir", e);
}
}

}
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 @@ -49,6 +49,7 @@ Import-Package: com.eclipsesource.json;version="0.9.5",
org.eclipse.kura.identity;version="[1.0,2.0)",
org.eclipse.kura.internal.wire.asset;version="[1.0,2.0)",
org.eclipse.kura.log;version="[1.1,1.2)",
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)";resolution:=optional,
Expand Down
1 change: 0 additions & 1 deletion kura/org.eclipse.kura.web2/OSGI-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<property name="kura.service.pid" type="String" value="org.eclipse.kura.web.Console"/>
<property name="kura.ui.service.hide" type="Boolean" value="true"/>
<service>
<provide interface="org.eclipse.kura.web.api.Console"/>
<provide interface="org.eclipse.kura.configuration.SelfConfiguringComponent"/>
</service>
<reference bind="setIdentityService" cardinality="1..1" interface="org.eclipse.kura.identity.IdentityService" name="IdentityService" policy="static"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Eurotech and/or its affiliates and others
* Copyright (c) 2024 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 All @@ -12,40 +12,16 @@
*******************************************************************************/
package org.eclipse.kura.web.client;

import java.util.List;

import org.eclipse.kura.web.client.ui.login.LoginUi;
import org.eclipse.kura.web.shared.model.GwtClientExtensionBundle;
import org.eclipse.kura.web.shared.service.GwtExtensionService;
import org.eclipse.kura.web.shared.service.GwtExtensionServiceAsync;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.ScriptInjector;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;

public class Login implements EntryPoint {

private final GwtExtensionServiceAsync gwtExtensionService = GWT.create(GwtExtensionService.class);

@Override
public void onModuleLoad() {
this.gwtExtensionService.getLoginExtensions(new AsyncCallback<List<GwtClientExtensionBundle>>() {

@Override
public void onFailure(Throwable caught) {
// do nothing
}

@Override
public void onSuccess(List<GwtClientExtensionBundle> result) {

for (final GwtClientExtensionBundle extension : result) {
ScriptInjector.fromUrl(extension.getEntryPointUrl()).inject();
}
}
});

RootPanel.get().add(GWT.create(LoginUi.class));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2021 Eurotech and/or its affiliates and others
* Copyright (c) 2024 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 All @@ -17,16 +17,13 @@

import org.eclipse.kura.web.client.ui.EntryClassUi;
import org.eclipse.kura.web.client.util.FailureHandler;
import org.eclipse.kura.web.shared.model.GwtClientExtensionBundle;
import org.eclipse.kura.web.shared.model.GwtGroupedNVPair;
import org.eclipse.kura.web.shared.model.GwtSecurityCapabilities;
import org.eclipse.kura.web.shared.model.GwtSession;
import org.eclipse.kura.web.shared.model.GwtUserConfig;
import org.eclipse.kura.web.shared.model.GwtXSRFToken;
import org.eclipse.kura.web.shared.service.GwtDeviceService;
import org.eclipse.kura.web.shared.service.GwtDeviceServiceAsync;
import org.eclipse.kura.web.shared.service.GwtExtensionService;
import org.eclipse.kura.web.shared.service.GwtExtensionServiceAsync;
import org.eclipse.kura.web.shared.service.GwtSecurityService;
import org.eclipse.kura.web.shared.service.GwtSecurityServiceAsync;
import org.eclipse.kura.web.shared.service.GwtSecurityTokenService;
Expand All @@ -36,7 +33,6 @@

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.ScriptInjector;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.RootPanel;

Expand All @@ -49,7 +45,6 @@ public class denali implements EntryPoint {
private final GwtSecurityTokenServiceAsync gwtXSRFService = GWT.create(GwtSecurityTokenService.class);
private final GwtDeviceServiceAsync gwtDeviceService = GWT.create(GwtDeviceService.class);
private final GwtSecurityServiceAsync gwtSecurityService = GWT.create(GwtSecurityService.class);
private final GwtExtensionServiceAsync gwtExtensionService = GWT.create(GwtExtensionService.class);
private final GwtSessionServiceAsync gwtSessionService = GWT.create(GwtSessionService.class);

@Override
Expand Down Expand Up @@ -137,22 +132,6 @@ public void onSuccess(final GwtSecurityCapabilities result) {
RootPanel.get().add(entryUi);
entryUi.init();

gwtExtensionService
.getConsoleExtensions(new AsyncCallback<List<GwtClientExtensionBundle>>() {

@Override
public void onFailure(Throwable caught) {
FailureHandler.handle(caught);
}

@Override
public void onSuccess(List<GwtClientExtensionBundle> result) {

for (final GwtClientExtensionBundle extension : result) {
ScriptInjector.fromUrl(extension.getEntryPointUrl()).inject();
}
}
});
}
});
}
Expand Down

This file was deleted.

0 comments on commit 46b2c72

Please sign in to comment.