tomcat 集成 WINDOWS域验证的第三方插件的方法

在网上找这方面的教程,真的不多, 或许是找的姿势不对。在此记录一下使用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 认证失败的错误页面

转载于:https://my.oschina.net/33876402/blog/875280

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值