如何从SPNEGO内标识获取角色名称? [英] Kerb4j - How to get role name from SPNEGO Token?
本文介绍了如何从SPNEGO内标识获取角色名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从Active Directory返回的SPNEGO令牌中获取角色名称,以便与Spring Security授权一起使用。我使用kerb4j进行身份验证,因为我的理解是它可以通过使用this code从令牌中获取组(即角色)信息(而不是后续的ldap查询)。
在我的Spring Web安全配置中,我有以下内容:
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${app.service-principal}")
private String servicePrincipal;
@Value("${app.keytab-location}")
private String keytabLocation;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.exceptionHandling()
.authenticationEntryPoint(spnegoEntryPoint())
.and()
.authorizeRequests().antMatchers("/", "/home").permitAll()
.antMatchers("/hello").access("hasRole('ROLE_ADMIN')")
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login").permitAll()
.and()
.logout().permitAll().and() //spring
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
BasicAuthenticationFilter.class);
}
@Bean
public SpnegoAuthenticationProvider kerberosServiceAuthenticationProvider() {
SpnegoAuthenticationProvider provider = new SpnegoAuthenticationProvider();
provider.setTicketValidator(sunJaasKerberosTicketValidator());
provider.setExtractGroupsUserDetailsService(new ExtractGroupsUserDetailsService());
provider.setServerSpn(servicePrincipal);
return provider;
}
ExtractGroupsUserDetailsService
仅获得SID,如(S-1-2-20-132925241-12333...)而不是AD组名称,例如ADMIN。如何编写ExtractGroupsUserDetailsService
来提取组的名称?此信息在SPNEGO内标识中可用吗?
更新
简单地将hasRole
Spel中的Role_admin替换为SID不起作用。
更新2
给定的SID字符串与传递到hasRole
中的SID字符串不匹配,因为hasRole
追加了传入的字符串。将ExtractGroupsUserDetailsService
更改为前缀&Role_&Quot;更改为SID(例如,Role_S-1-2-20-132925241-12333...)后,匹配起作用。
尽管如此……如何在ExtractGroupsUserDetailsService
而不是SID中获取组名(例如admin)?
推荐答案
ExtractGroupsUserDetailsService仅获取SID,如(S-1-2-20-132925241-12333...)而不是AD组名称,例如ADMIN。如何编写ExtractGroupsUserDetailsService来提取组的名称?此信息在SPNEGO内标识中可用吗?否,Kerberos PAC仅包含SID,不包含名称。(Windows访问控制从不基于名称。)您仍需要对这些内容进行LDAP搜索。
这篇关于如何从SPNEGO内标识获取角色名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文