Spring Security Kerberos 配置IWA的关键步骤备忘

本文档介绍了在Windows域环境下,如何利用Spring Security Kerberos (SSK) 实现Integrated Windows Authentication (IWA)。主要内容包括SSK的功能,如Authentication Provider、Spnego Negotiate等,并详细阐述了配置IWA的关键步骤,包括SpnegoAuthenticationProcessingFilter的使用,KerberosServiceAuthenticationProvider的校验过程,以及在搭建过程中Windows Domain Controller的安装、keytab文件的生成和应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

IWA: integrated windows authentication
简介:Windows域环境下,终端用户在使用电脑windows系统时已经通过域账户登录了,在使用一些application的时候,也想通过这种方式做认证,不需要在每个application再输入用户名密码。

Kerberos的认证原理貌似比较复杂,我也没看太懂,反正刚开始先用别人的封装把环境搭起来,这里使用了Spring Security Kerberos(以下简称SSK):
http://docs.spring.io/spring-security-kerberos/docs/1.0.1.RELEASE/reference/htmlsingle/

文档比较详细了,主要提供以下功能:
1. Authentication Provider
2. Spnego Negotiate
3. Using KerberosRestTemplate
4. Authentication with LDAP Services

在项目中使用了功能2,用户在访问我们登陆页面时,由SSK提供的Filter:SpnegoAuthenticationProcessingFilter负责检查用户Http Request中的Authorization Header,如果认证失败,会在entryPoint(SpnegoEntryPoint)的commence方法中执行以下代码,浏览器获取这个response后会自动发送kerberos ticket给当前url(这里流程可能不太严谨,没细看过negotiate的整个过程)
response.addHeader("WWW-Authenticate", "Negotiate");
response.setStatus(401);


回到Filter,如果浏览器发来了kerberos ticket,就会有如下的逻辑去检查这个ticket:
if ((header != nu
### Java Spring Security Kerberos SSO 实现指南 #### 配置环境变量 为了使应用程序能够成功连接到Kerberos服务器,需设置特定的安全属性: ```java System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");[^1] ``` 此配置允许Java应用信任操作系统级别的认证凭证。 #### 添加依赖项 在`pom.xml`文件中加入必要的Maven依赖来支持Spring Security以及Jaas(Java Authentication and Authorization Service),这是处理Kerberos所需的基础库之一。对于Spring Boot项目来说,则应考虑使用starter包简化集成过程。 ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!-- Other dependencies --> <dependency> <groupId>org.springframework.security.kerberos</groupId> <artifactId>spring-security-kerberos-web</artifactId> <version>${spring-security-kerberos.version}</version> </dependency> ``` #### 创建JAAS配置文件 创建名为`jaas.conf`的文件并放置于类路径下,定义服务端所需的登录模块及其参数。该文件通常包含如下内容: ``` com.sun.security.jgss.initiate { com.sun.security.auth.module.Krb5LoginModule required; }; ``` #### 自定义WebSecurityConfigurerAdapter 通过继承`WebSecurityConfigurerAdapter`来自定义安全策略,在其中指定Kerberos相关的过滤器和其他必要组件。 ```java @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/login").permitAll() // Allow access to login page without authentication. .anyRequest().authenticated(); // Require all other requests be authenticated. http .addFilterBefore(kerberosAuthenticationProcessingFilter(), BasicAuthenticationFilter.class); } private Filter kerberosAuthenticationProcessingFilter(){ final SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter = new SpnegoAuthenticationProcessingFilter(); // Additional configurations... return spnegoAuthenticationProcessingFilter; } } ``` #### 设置SPNEGO入口点 为了让客户端浏览器知道应该发起哪种类型的HTTP请求来进行身份验证,还需要注册一个特殊的入口处理器——即`SpnegoEntryPoint`. ```java @Bean public SpnegoEntryPoint spengoEntryPoint() { return new SpnegoEntryPoint("/login"); } ``` 以上就是基于Java平台利用Spring Security框架完成Kerberos协议下的单点登录功能的一个基本实现方案概述[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值