- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道如何将 Spring Security Kerberos 与 Spring Boot 2.0 结合使用。
我们目前正在尝试让 SPNego 过滤器正常工作。
这是错误:
o.s.s.k.w.a.SpnegoAuthenticationProcessingFilter : Negotiate Header was invalid: Negotiate YHoGBisGAQUFAqBwMG6gMDAuBgorBgEEAYI3AgIKBgkqhkiC9xIBAgIGCSqGSIb3EgECAgYKKwYBBAGCNwICHqI6BDhOVExNU1NQAAEAAACXsgjiAwADADUAAAANAA0AKAAAAAYBsR0AAAAPSU5CT01WRDgxMTAzMURCRw==
org.springframework.security.authentication.BadCredentialsException: GSSContext name of the context initiator is null
at org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator$KerberosValidateAction.run(SunJaasKerberosTicketValidator.java:173)
at org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator$KerberosValidateAction.run(SunJaasKerberosTicketValidator.java:153)
at java.security.AccessController.doPrivileged(Native Method)
目前,我们尝试仅对单个端点 (/protected
) 进行身份验证,但我们需要使用 kerberos 身份验证来保护所有端点。这是 Web 安全配置(相同的代码适用于 Spring Boot 1.5.13.RELEASE,但不适用于 Spring Boot 2.0.3.RELEASE):
package com.findwise.kerberos.config;
import com.findwise.kerberos.localhost.LocalhostAuthFilter;
import com.findwise.kerberos.localhost.LocalhostAuthProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
import org.springframework.security.kerberos.client.config.SunJaasKrb5LoginConfig;
import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
import org.springframework.security.ldap.userdetails.LdapUserDetailsService;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import java.util.Collection;
/**
* SpringSecurityConfig:
* <p>
* This is our main security configuration - It follows very closely the
* examples provided by Spring.IO - Spring Security Kerberos.
*
* @author Peter Gylling - email: peter.jorgensen@findwise.com
* @link http://docs.spring.io/spring-security-kerberos/docs/current/reference/htmlsingle/
*/
@Configuration
@EnableWebSecurity
public class SpringSecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${app.service-principal}")
private String servicePrincipal;
@Value("${app.keytab-location}")
private String keytabLocation;
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.exceptionHandling()
.authenticationEntryPoint(spnegoEntryPoint())
.and().authorizeRequests().anyRequest().authenticated()
.and().addFilterBefore( spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
BasicAuthenticationFilter.class);
}
/**
* This ensures a global configuration for the security of the application.
*
* @param auth
* @param kerbServiceProvider
*/
@Autowired
protected void configureGlobal(AuthenticationManagerBuilder auth,
LocalhostAuthProvider localhostAuthProvider,
KerberosServiceAuthenticationProvider kerbServiceProvider) {
auth
.authenticationProvider(localhostAuthProvider)
.authenticationProvider(kerbServiceProvider);
}
/**
* Provide the default Spring Authentication Manager bean.
* This is used by the SpnegoAuthenticationProcessingFilter as
* part of the configuration.
*
* @return
* @throws Exception
* @see SpnegoAuthenticationProcessingFilter
*/
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
/**
* LocalhostAuthProvider:
* Provided with the username from the LocalAuthFilter the LocalhostAuthProvider
* calls Ldap and extracts the roles of the current user.
*
* @return a configured localhost auth provider
*/
@Bean
public LocalhostAuthProvider localhostAuthProvider() {
LocalhostAuthProvider localhostAuthProvider = new LocalhostAuthProvider();
localhostAuthProvider.setUserDetailsService(new KerberosUserDetailsService());
return localhostAuthProvider;
}
/**
* LocalhostAuthFilter:
* Graps the SPNEGO request before the Kerberos based SPNEGO authentication filter
* and shortcuts the system to allow for local users. (The developer use cae).
*
* @param authenticationManager - Standard Spring Security
* @return a configured LocalHostAuth filter.
*/
@Bean
public LocalhostAuthFilter localhostAuthFilter(AuthenticationManager authenticationManager) {
LocalhostAuthFilter localhostAuthFilter = new LocalhostAuthFilter();
localhostAuthFilter.setAuthenticationManager(authenticationManager);
return localhostAuthFilter;
}
/**
* Setup SpnegoEntryPoint to point to the login
* page provided by the login.jsp page.
*
* @return
*/
@Bean
public SpnegoEntryPoint spnegoEntryPoint() {
return new SpnegoEntryPoint("/protected");
}
/**
* SpnegoAuthenticationProcessingFilter:
* <p>
* This is your friendly SSO filter, that kindly automatically
* logs the user in if the Browser provides the actual credentials
*
* @param authenticationManager - with BeanIds.AUTHENTICATION_MANAGER
* @return
* @See AuthenticationManager
*/
@Bean
public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
AuthenticationManager authenticationManager) {
SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter();
filter.setAuthenticationManager(authenticationManager);
return filter;
}
/**
* KerberosServiceAuthenticationProvider:
* <p>
* This bean is needed by the global AuthenticationManager bean as the only
* accepted authentication providers.
* <p>
* To actually provide Spring Security with the required user details the
* LdapUserDetailsService is provided to the service auth provider.
* <p>
* The Ldap service will not be used until the TicketValidator has granted
* general access.
*
* @return - A configured Kerberos Service Auth Provider
* @see SunJaasKerberosTicketValidator
* @see LdapUserDetailsService
*/
@Bean
public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() {
KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider();
provider.setTicketValidator(sunJaasKerberosTicketValidator());
provider.setUserDetailsService(new KerberosUserDetailsService());
return provider;
}
/**
* SunJaasKerberosTicketValidator
* <p>
* This bean will on behalf of the web application validate the visiting users provided
* Kerberos Ticket. This will not kick in if the underlying JAAS and KRB5 configuration is
* not working as expected.
* <p>
* Find the values of the servicePrincipal and keytabLocation in application.properties
*
* @return - A Kerberos Ticket Validator
* @see KerberosGlobalConfig
*/
@Bean
public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() {
SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
ticketValidator.setServicePrincipal(servicePrincipal);
ticketValidator.setKeyTabLocation(new FileSystemResource(keytabLocation));
ticketValidator.setDebug(true);
return ticketValidator;
}
/**
* SunJaasKrb5LoginConfig
* <p>
* This is what you would previously find in a JAAS Conf file.
* <p>
* Find the servicePrincipal and keytabLocation is application.properties
*
* @return a configured JAAS login
* @see SunJaasKrb5LoginConfig
*/
@Bean
public SunJaasKrb5LoginConfig loginConfig() {
SunJaasKrb5LoginConfig loginConfig = new SunJaasKrb5LoginConfig();
loginConfig.setKeyTabLocation(new FileSystemResource(keytabLocation));
loginConfig.setServicePrincipal(servicePrincipal);
loginConfig.setDebug(true);
loginConfig.setIsInitiator(true);
loginConfig.setUseTicketCache(true);
return loginConfig;
}
protected static class KerberosUserDetailsService implements UserDetailsService {
@Override
public UserDetails loadUserByUsername(final String s) throws UsernameNotFoundException {
return new UserDetails() {
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return null;
}
@Override
public String getPassword() {
return null;
}
@Override
public String getUsername() {
return s;
}
@Override
public boolean isAccountNonExpired() {
return true;
}
@Override
public boolean isAccountNonLocked() {
return true;
}
@Override
public boolean isCredentialsNonExpired() {
return true;
}
@Override
public boolean isEnabled() {
return true;
}
};
}
}
}
最佳答案
Kerberos 服务主体未正确设置。现在工作正常。
基本配置步骤:
1)Krb5conf应该正确加载(它包含KDC和领域相关信息)。
2) 必须创建服务主体 (HTTP/xyz),并且应提供 keytab 作为配置。
3) 如果您通过客户端程序调用任何 REST 服务,则需要提供用户主体和 key 表,或者您可以使用本地 Kerberos 缓存 (krb5_123x)。
关于java - Spring Boot 2 kerberos 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51704843/
在 JSF2 应用程序中遇到验证属性的问题时,有两种主要方法。 使用 Annotation 在 ManagedBean 上定义验证 @ManagedBean public class MyBean {
我想实现一个不常见的功能,我认为 jquery 验证插件将是最好的方法(如果您在没有插件的情况下建议和回答,我们也会欢迎)。我想在用户在输入字段中输入正确的单词后立即隐藏表单。我试过这个: $("
我有几个下拉菜单(类名为month_dropdown),并且下拉菜单的数量不是恒定的。我怎样才能为它们实现 NotEqual 验证。我正在使用 jQuery 验证插件。 这就是我写的 - jQuery
我设法制作了这个网址验证代码并且它起作用了。但我面临着一个问题。我认为 stackoverflow 是获得解决方案的最佳场所。 function url_followers(){ var url=do
我目前正在使用后端服务,该服务允许用户在客户端应用程序上使用 Google Games 库登录。 用户可以通过他们的 gplay ID 向我们发送信息,以便登录或恢复旧帐户。用户向我们发送以下内容,包
我正在尝试验证输入以查看它是否是有效的 IP 地址(可能是部分地址)。 可接受的输入:172、172.112、172.112.113、172.112.113.114 Not Acceptable 输入
我从 Mongoose 验证中得到这条消息: 'Validator failed for path phone with value ``' 这不应该发生,因为不需要电话。 这是我的模型架构: var
我一直在尝试使用Python-LDAP (版本 2.4.19)在 MacOS X 10.9.5 和 Python 2.7.9 下 我想在调用 .start_tls_s() 后验证与给定 LDAP 服务
我正在处理一个仅与 IE6 兼容的旧 javascript 项目(抱歉...),我想仅在 VS 2017 中禁用此项目的 ESLint/CSLint/Javascript 验证/CSS 验证。 我知道
我正在寻找一种方法来验证 Spring 命令 bean 中的 java.lang.Double 字段的最大值和最小值(一个值必须位于给定的值范围之间),例如, public final class W
我正在尝试在 springfuse(JavaEE 6 + Spring Framework (针对 Jetty、Tomcat、JBoss 等)) 和 maven 的帮助下构建我的 webapps 工作
我试图在我们的项目中使用 scalaz 验证,但遇到了以下情况: def rate(username: String, params: Map[String, String]): Validation
我有一个像这样的 Yaml 文件 name: hhh_aaa_bbb arguments: - !argument name: inputsss des
我有一个表单,人们可以单击并向表单添加字段,并且我需要让它在单击时验证这些字段中的值。 假设我单击它两次并获取 2 个独立的字段集,我需要旋转 % 以确保它在保存时等于 100。 我已放入此函数以使其
在我的页面中有一个选项可以创建新的日期字段输入框。用户可以根据需要创建尽可能多的“截止日期”和“起始日期”框。就像, 日期_to1 || date_from1 日期到2 ||日期_from2 date
我有一个像这样的 Yaml 文件 name: hhh_aaa_bbb arguments: - !argument name: inputsss des
有没有办法在动态字段上使用 jquery 验证表单。 我想将其设置为必填字段 我正在使用 Jsp 动态创建表单字段。 喜欢 等等...... 我想使用必需的表单字段验证此表单字段。 最佳答
嗨,任何人都可以通过提供 JavaScript 代码来帮助我验证用户名文本框不应包含数字,它只能包含一个字符。 最佳答案 使用正则表达式: (\d)+ 如果找到匹配项,则字符串中就有一个数字。 关于J
我有两个输入字段holidayDate和Description(id=tags) $(document).ready(function() {
我遇到了这个问题,这些验证从电子邮件验证部分开始就停止工作。 我只是不明白为什么即使经过几天的观察,只是想知道是否有人可以在这里指出我的错误? Javascript部分: function valid
我是一名优秀的程序员,十分优秀!