在网上找这方面的教程,真的不多, 或许是找的姿势不对。在此记录一下使用spnego第三方插件的部署过程。
首先,下载这个插件 tomcatspnego 插件, 不过CodePlex这网站已计划关闭了。
由于我使用的是dll的方式,就是tomcat是部署在WINDOWS下的方法。
将 SSPAuthentification*.dll 的2个dll 文件复制到 tomcat\bin 目录下。
将frdoumesspitc8dll.jar 复制到 tomcat\lib 目录下(因为我使用的是tomcat8,所以使用的是这个版本,请按自己的tomcat版本而选择相应的文件)
然后,在应用的 web.xml中增加内容,只针对 /auth.do 会去调用WINDOWS域集成验证
<security-constraint>
<display-name>Example Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/auth.do</url-pattern>
<!-- If you list http methods, only those methods are protected -->
<http-method>DELETE</http-method>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
</web-resource-collection>
<auth-constraint>
<!-- Anyone with one of the listed roles may access this area
<role-name>utilisateurs</role-name>
<role-name>users</role-name>
<role-name>everyone</role-name>-->
<role-name>everyone</role-name>
</auth-constraint>
</security-constraint>
<!-- Default login configuration -->
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Example Spnego</realm-name>
</login-config>
在你的应用目录下新建文件 META-INF/context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context> <Valve className="fr.doume.jna.authenticator.SSPAuthenticator"/>
<Realm className="fr.doume.jna.realm.WindowsRealm"/>
</Context>
在/auth.do 的页面中 request.getUserPrincipal().getName() 就能获得当能登录的用户ID,若是未登录,则返回401 认证失败的错误页面