Java Web 系统和域用户结合

雪域幽狐 2010-11-19 16:30 阅读:7576


现有一个现成的组件,见附件。配置较简单。
1、引入附件里的jar
2、在web.xml里配置需要验证的filter
        <filter>
                <filter-name>NtlmHttpFilter</filter-name>
                <filter-class>jcifs.http.NtlmHttpFilter</filter-class>
                <init-param>
                        <param-name>jcifs.http.domainController</param-name>
                        <param-value>域服务器地址</param-value>
                </init-param>
                <init-param>  
                  <param-name>jcifs.util.loglevel</param-name>  
                  <param-value>3</param-value>  
                </init-param>
        </filter>
        <filter-mapping>
                <filter-name>NtlmHttpFilter</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>

3、这样访问相关资源时就会提示输入用户名、密码,如果客户端把中间件服务器的IP配置为了信任站点,就不用再输入用户名、密码,可以直接获取到登录到域的用户名。
获取方式
NtlmPasswordAuthentication ntlm = (NtlmPasswordAuthentication) request
                .getSession().getAttribute("NtlmHttpAuth");
        if (ntlm != null)
        {
            request.setAttribute("Username", ntlm.getName());
        }


附件:
jcifs-1.3.14.jar

0条评论

登陆后可评论