proxy progress

This commit is contained in:
rusefi 2020-07-18 16:06:08 -04:00
parent 35799e0332
commit 61ce495482
6 changed files with 20 additions and 15 deletions

View File

@ -22,7 +22,6 @@ import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import static com.rusefi.TestHelper.createIniField;
import static com.rusefi.TestHelper.prepareImage;
@ -50,7 +49,7 @@ public class ServerTest {
public void testControllerSessionTimeout() throws InterruptedException, IOException {
int serverPortForControllers = 7000;
int httpPort = 8000;
Function<String, UserDetails> userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
CountDownLatch serverCreated = new CountDownLatch(1);
CountDownLatch allClientsDisconnected = new CountDownLatch(1);
@ -92,7 +91,7 @@ public class ServerTest {
@Test
public void testInvalidApplicationRequest() throws InterruptedException, IOException {
Function<String, UserDetails> userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
int httpPort = 8001;
int serverPortForRemoteUsers = 6801;
CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1);
@ -120,7 +119,7 @@ public class ServerTest {
public void testAuthenticatorRequestUnknownSession() throws InterruptedException, IOException {
int serverPortForRemoteUsers = 6800;
Function<String, UserDetails> userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), authToken.charAt(6));
int httpPort = 8001;
CountDownLatch disconnectedCountDownLatch = new CountDownLatch(1);
@ -157,7 +156,7 @@ public class ServerTest {
CountDownLatch controllerRegistered = new CountDownLatch(1);
Function<String, UserDetails> userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), userId);
UserDetailsResolver userDetailsResolver = authToken -> new UserDetails(authToken.substring(0, 5), userId);
int httpPort = 8001;
Backend backend = new Backend(userDetailsResolver, httpPort, logger) {
@Override

View File

@ -42,10 +42,10 @@ public class Backend {
// guarded by clients
private HashMap<ControllerKey, ControllerConnectionState> byId = new HashMap<>();
// private final int clientTimeout;
private final Function<String, UserDetails> userDetailsResolver;
private final UserDetailsResolver userDetailsResolver;
private final Logger logger;
public Backend(Function<String, UserDetails> userDetailsResolver, int httpPort, Logger logger) {
public Backend(UserDetailsResolver userDetailsResolver, int httpPort, Logger logger) {
// this.clientTimeout = clientTimeout;
this.userDetailsResolver = userDetailsResolver;
this.logger = logger;
@ -166,7 +166,7 @@ public class Backend {
return new RsJson(builder.build());
}
public Function<String, UserDetails> getUserDetailsResolver() {
public UserDetailsResolver getUserDetailsResolver() {
return userDetailsResolver;
}

View File

@ -4,7 +4,6 @@ import com.opensr5.Logger;
import java.io.File;
import java.net.MalformedURLException;
import java.util.function.Function;
public class BackendLauncher {
/**
@ -13,7 +12,7 @@ public class BackendLauncher {
public static void start(String[] args) throws MalformedURLException {
rusEFISSLContext.setupCertificates(new File("keystore.jks"), System.getProperty("RUSEFI_PROXY_PASSWORD"));
Function<String, UserDetails> userDetailsFunction = new JsonUserDetailsResolver();
UserDetailsResolver userDetailsFunction = new JsonUserDetailsResolver();
Backend backend = new Backend(userDetailsFunction, Backend.HTTP_PORT, Logger.CONSOLE);
backend.runApplicationConnector(Backend.SERVER_PORT_FOR_APPLICATIONS, parameter -> {

View File

@ -11,12 +11,11 @@ import com.rusefi.io.tcp.TcpIoStream;
import java.io.Closeable;
import java.io.IOException;
import java.net.Socket;
import java.util.function.Function;
public class ControllerConnectionState {
private final Socket clientSocket;
private final Logger logger;
private final Function<String, UserDetails> userDetailsResolver;
private final UserDetailsResolver userDetailsResolver;
private boolean isClosed;
private IoStream stream;
@ -31,7 +30,7 @@ public class ControllerConnectionState {
private UserDetails userDetails;
private ControllerKey controllerKey;
public ControllerConnectionState(Socket clientSocket, Logger logger, Function<String, UserDetails> userDetailsResolver) {
public ControllerConnectionState(Socket clientSocket, Logger logger, UserDetailsResolver userDetailsResolver) {
this.clientSocket = clientSocket;
this.logger = logger;
this.userDetailsResolver = userDetailsResolver;
@ -71,6 +70,9 @@ public class ControllerConnectionState {
logger.info(sessionDetails.getAuthToken() + " New client: " + sessionDetails.getControllerInfo());
userDetails = userDetailsResolver.apply(sessionDetails.getAuthToken());
if (userDetails == null) {
throw new IOException("Unable to resolve " + sessionDetails.getAuthToken());
}
controllerKey = new ControllerKey(userDetails.getUserId(), sessionDetails.getControllerInfo());
logger.info("User " + userDetails);
}

View File

@ -7,9 +7,8 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.util.function.Function;
public class JsonUserDetailsResolver implements Function<String, UserDetails> {
public class JsonUserDetailsResolver implements UserDetailsResolver {
@Override
@Nullable
public UserDetails apply(String authToken) {

View File

@ -0,0 +1,6 @@
package com.rusefi.server;
import java.util.function.Function;
public interface UserDetailsResolver extends Function<String, UserDetails> {
}