ad域Waffle及Jetty简单测试代码

Waffle介绍

下载地址:https://github.com/Waffle/waffle
WAFFLE is a native Windows Authentication Framework consisting of two C# and Java libraries that perform functions related to Windows authentication, supporting Negotiate, NTLM and Kerberos. Waffle also includes libraries that enable drop-in Windows Single Sign On for popular Java web servers, when running on Windows. While Waffle makes it ridiculously easy to do Windows Authentication in Java, on Windows, *Waffle does not work on nix(UNIX-like).

Unlike many other implementations Waffle on Windows does not require any server-side Kerberos keytab setup, it’s a drop-in solution. You can see it in action in this slightly blurry video produced for TeamShatter.com.

以上是官网里的readme内容,注意标重的那两句。waffle是不能在linux下运行的,也就是说,除非你是windows服务器;而且,他是对于本地windows的认证,也就是说除非你的javaweb应用跟域在同一个服务器上,才会有域验证一说,举个例子:假设你的web应用在域下的一台windows子机上,那么你就只能输入子机的用户名和密码才能进入,输入任何其他账号都不会有效果!!!

综上,所以,如果你要搭建本地windows认证服务,可以考虑waffle,否则做了也是走弯路。

Jetty介绍

Jetty 是一个开源的servlet容器,它为基于Java的web容器,例如JSP和servlet提供运行环境。Jetty是使用Java语言编写的,它的API以一组JAR包的形式发布。

上面是百度百科的介绍,我们把jetty简单理解为一个容器即可,即想象成tomcat就好,只不过它是jar包形式的。

测试程序

1.需要的jar包

在这里插入图片描述

2.HelloServlet.java

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet
public class HelloServlet extends HttpServlet {
	/**
     * 
     */
	private static final long serialVersionUID = -2345771005431135205L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String requestUrl = request.getRequestURL().toString();//得到请求的URL地址
		System.out.println(requestUrl);
        String requestUri = request.getRequestURI();//得到请求的资源
        System.out.println(requestUri);
        String queryString = request.getQueryString();//得到请求的URL地址中附带的参数
        System.out.println(queryString);  
        String remoteAddr = request.getRemoteAddr();//得到来访者的IP地址
        System.out.println(remoteAddr);
        String remoteHost = request.getRemoteHost();
        System.out.println(remoteHost);
        int remotePort = request.getRemotePort();
        System.out.println(remotePort);
        String remoteUser = request.getRemoteUser();
        System.out.println(remoteUser);
        String method = request.getMethod();//得到请求URL地址时使用的方法
        System.out.println(method);
        String pathInfo = request.getPathInfo();
        System.out.println(pathInfo);
        String localAddr = request.getLocalAddr();//获取WEB服务器的IP地址
        System.out.println(localAddr);
        String localName = request.getLocalName();//获取WEB服务器的主机名
        System.out.println(localName);
		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>");
	}
}

3.JettyWaffleTest.java

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(8055);
		// http://localhost:8055/hello
		EnumSet<DispatcherType> dispatches = EnumSet.allOf(DispatcherType.class);
		ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
		context.addFilter(waffle.servlet.NegotiateSecurityFilter.class, "/*", dispatches);
		context.addServlet(HelloServlet.class, "/hello");
		context.setContextPath("/");
		server.setHandler(context);
		server.start();
		server.join();
		System.out.println(">>>>启动结束>>>");
	}
}

4.效果

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值