Jetty supports Windows authentication

Source: Internet
Author: User

    • 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
  1. Download jetty, waffle, and unzip; Download the Jetty-all package (download http://central.maven.org/maven2/org/eclipse/jetty/aggregate/jetty-all/here)
  2. Create a new Java project
  3. 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
  4. Add Jetty\lib\servlet-api-3.1.jar and Jetty-all-9.2.1.v20140609.jar to the project's build path
  5. 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 (" 
  6. 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 ();}}
  7. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.