标签:style blog http java color width
WAFFLE是一个Windows认证框架,支持Negotiate, NTLM和Kerberos认证。WAFFLE包含Windows认证相关的C#和Java库。WAFFLE主页 http://dblock.github.io/waffle/
Jetty简介参见 http://www.cnblogs.com/leo100w/p/3809880.html
Jetty作为web服务器和Servlet容器,支持自定义的Filter和Servlet。而Waffle通过Filter实现Windows认证。因此,要使Jetty支持Windows认证就很简单了,只要将Waffle作为自定义Filter加入Jetty就可以了。
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; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println( "<h1>Hello " + request.getRemoteUser() + "!<br/>Role: " + request.getUserPrincipal().getName() + "</h1>"); } }
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(); } }
Hello demo! Role: demo
从DEMO可以看出,我们可以通过request.getRemoteUser()获取远程用户登录的Windows用户,当然也可以通过request.getUserPrincipal()获取Principal,该Principal是一个waffle.servlet.WindowsPrincipal类型,通过该类型可以进一步获取各种Windows认证的相关信息。
Jetty支持Windows认证,布布扣,bubuko.com
标签:style blog http java color width
原文地址:http://www.cnblogs.com/leo100w/p/3817169.html