- What is waffle?
- Jetty Increased Waffle support
- DEMO
- Summary
What is waffle?
Waffle is a Windows authentication framework that supports negotiate, NTLM, and Kerberos authentication. Waffle contains Windows authentication-related C # and Java libraries. Waffle Home http://dblock.github.io/waffle/
Jetty Introduction See http://www.cnblogs.com/leo100w/p/3809880.html
Jetty supports Windows authentication
Jetty is a Web server and servlet container that supports custom filter and servlet. Instead, waffle implements Windows authentication through filter. Therefore, it is easy to make jetty support Windows authentication, as long as you add waffle as a custom filter to jetty.
DEMO
- Download jetty, waffle, and unzip; Download the Jetty-all package (download http://central.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/here)
- Create a new Java project
- Will waffle\bin in the Guava-13.0.1.jar, Jna-3.5.0.jar, Platform-3.5.0.jar, Slf4j-api-1.7.2.jar, Waffle-jetty.jar, Waffle-jna.jar Library added to the project's build path
- Add Jetty\lib\servlet-api-3.1.jar and Jetty-all-9.2.1.v20140609.jar to the project's build path
- create HelloServlet class
import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;public class HelloServlet Extends HttpServlet {/** * */private static final long serialversionuid = -2345771005431135205l; @Overrideprotected void D Oget (httpservletrequest request,httpservletresponse response) throws Servletexception, IOException { Response.setcontenttype ("Text/html;charset=utf-8"); Response.setstatus (HTTPSERVLETRESPONSE.SC_OK); Response.getwriter (). println ("
- Creating the Jettywaffletest Class
Import Java.util.enumset;import Javax.servlet.dispatchertype;import Org.eclipse.jetty.server.server;import Org.eclipse.jetty.servlet.servletcontexthandler;public class Jettywaffletest {public static void main (string[] args) Throws Exception {Server server = new server (8080); Enumset<dispatchertype> dispatches = Enumset.allof (Dispatchertype.class); Servletcontexthandler context = new Servletcontexthandler (servletcontexthandler.sessions); Context.addfilter ( Waffle.servlet.NegotiateSecurityFilter.class, "/*", dispatches); Context.addservlet (Helloservlet.class, "/"); Context.setcontextpath ("/"); Server.sethandler (context); Server.start (); Server.join ();}}
- Run. The results are as follows
Hello demo! Role:demo
Summary
As you can see from the demo, we can get the Windows user to log in by Request.getremoteuser (), or we can get principal through Request.getuserprincipal (), The principal is a Waffle.servlet.WindowsPrincipal type that allows for further information about various Windows certifications.