Package samples.authentication

Source Code of samples.authentication.SimplePasswordsExample

package samples.authentication;

import org.webbitserver.*;
import org.webbitserver.handler.StaticFileHandler;
import org.webbitserver.handler.authentication.BasicAuthenticationHandler;
import org.webbitserver.handler.authentication.InMemoryPasswords;

import java.io.IOException;

import static org.webbitserver.WebServers.createWebServer;

/**
* This example demonstrates restricting access using HTTP BASIC authentication.
*
* Passwords are known in advance and stored in memory.
*/
public class SimplePasswordsExample {

    public static void main(String[] args) throws IOException {
        InMemoryPasswords passwords = new InMemoryPasswords()
                .add("joe", "secret")
                .add("jeff", "somepassword");

        WebServer webServer = createWebServer(45453)
                .add(new BasicAuthenticationHandler(passwords))
                .add("/whoami", new WhoAmIHttpHandler())
                .add("/whoami-ws", new WhoAmIWebSocketHandler())
                .add(new StaticFileHandler("src/test/java/samples/authentication/content"))
                .start();

        System.out.println("Running on " + webServer.getUri());
    }

}
TOP

Related Classes of samples.authentication.SimplePasswordsExample

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.