RuedigerMoeller / kontraktor

distributed Actors for Java 8 / JavaScript
GNU Lesser General Public License v3.0
343 stars 48 forks source link

Providing a secure connection for sensitive data #30

Closed davidwynter closed 8 years ago

davidwynter commented 8 years ago

Hi,

I am doing a webapp using websockets that has a typical sequence for registering a new user.

  1. User submits a username and password in the initial contract
  2. More information is gathered from the user in a follow up contract and validated against an external service.

So I need 2 characteristics for this, session management and a secure connection. I had a look at undertow and found they support secure websocket, DefaultWebSocketClientSslProvider. But unclear on how to approach both my requirements for session management and security. Any pointers? The code for building the http handler is below: Excuse the markdown not working as it should.

` BldFourK bld4k = Http4K.Build("localhost", 8080).fileRoot("/", root).fileRoot("/jsk", jsroot).httpAPI("/api", csHttpApp) .serType(SerializerType.JsonNoRef).setSessionTimeout(30_000).build().websocket("/ws", csHttpApp) .serType(SerializerType.JsonNoRef).build().build();

    bld4k.httpHandler("/rst", 
            (new HttpHandler() {
                @Override
                public void handleRequest(final HttpServerExchange exchange) throws Exception {
                    Map<String,Deque<String>> params = exchange.getPathParameters();
                    Recover result = csHttpApp.checkRecover(params.get("k").getFirst());
                    if(result != null) {
                        // A valid request, load the right page
                        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                        exchange.getResponseSender().send("Screen here");
                    } else {
                        // Not a valid request
                        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                        exchange.getResponseSender().send("False identfication");
                    }
                }
            })
    );`
davidwynter commented 8 years ago

Somehow I managed to miss the builder for Http4k that includes the sslContext completely dooh!