- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有 SPNEGO 的 spring 安全配置,它正在“破解”。它看起来如下:
@Configuration
@EnableWebSecurity
public class SpnegoConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
...
.addFilterBefore(
spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
BasicAuthenticationFilter.class); // 1
}
@Override
@Autowired // 3
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth
.authenticationProvider(kerberosAuthenticationProvider())
.authenticationProvider(kerberosServiceAuthenticationProvider());
}
@Bean
public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(
AuthenticationManager authenticationManager) { // 2
SpnegoAuthenticationProcessingFilter filter =
new SpnegoAuthenticationProcessingFilter();
filter.setAuthenticationManager(authenticationManager);
return filter;
}
...
}
发生了什么:
点在这个类中,它是 WebSecurityConfigurerAdapter
我正在覆盖 2 个方法:
configure(HttpSecurity http)
- 这依赖于通过自定义过滤器构建的 AuthenticationManager
configure(AuthenticationManagerBuilder auth)
- 这显然与尚未构建的 AuthenticationManager
相关 - 我们正在构建它如果我在方法 (3) 上没有 @Autowired
,则 AuthenticationManager
构建得太早,我添加了 AuthenticationProvider
没有效果。身份验证失败,异常情况是没有合适的 AuthenticationProvider
。
使用 @Autowired
可以正常工作,但如果感觉不对。我什至不确定为什么它会在那时开始工作。
请就正确的方法提出建议。
编辑:它实际上可以在没有@Autowired 的情况下工作。但重点在于公认的答案。如果您在 @Configuration
中依赖于 AuthenticationManager
,请确保通过 authenticationManagerBean()
方法公开或引用它。
最佳答案
您使用了错误的 AuthenticationManager
。
如果你想使用 SpnegoConfig
中的 AuthenticationManager
进行依赖注入(inject),你必须公开它,参见 JavaDoc :
Override this method to expose the AuthenticationManager from configure(AuthenticationManagerBuilder) to be exposed as a Bean. For example:
@Bean(name name="myAuthenticationManager")
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
如果你想配置全局AuthenticationManager
,你必须 Autowiring AuthenticationMangerBuilder
,见Spring Security 3.2.0.RC2 Released
For example, if you want to configure global authentication (i.e. you only have a single AuthenticationManager) you should autowire the AuthenticationMangerBuilder:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
// ... configure it ...
}
关于java - 具有自定义身份验证过滤器的 WebSecurityConfigurerAdapter - 依赖性问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39259086/
我有这个问题使用 SpringBoot 和 SpringBoot-Security 实现自定义登录身份验证。我做了一个Bitbucket repository作为该线程的引用(在 CustomSecu
我已经实现了 UserDetailsService 来为我的 Spring Boot REST 服务返回带有 SimpleGrantedAuthority 的 UserDetails 实例。我有
我尝试将 Spring Security 添加到我的项目中,但没有成功。我仍然可以在没有任何登录的情况下访问我的网络应用程序。 主要配置 public class SpittrWebAppInitia
这是我的测试,我正在添加额外的 header 测试 after testing my filter @RunWith( SpringJUnit4ClassRunner.class ) @WebAppC
我们有一个看起来像这样的配置: @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter {
我正在尝试为我的应用程序配置多种身份验证类型,为每种类型的身份验证使用单独的 WebSecurityConfigurerAdapter。 总体思路是使用 WebSecurityConfigurerAd
我的 build.gradle 包含: compile('org.springframework.security:spring-security-web:4.1.3.RELEASE') “刷新所有
我目前正在使用 Spring Security 进行 Oauth2 实现,并且我发现了许多使用 ResourceServerConfigurerAdapter 的文档。随着WebSecurityCon
过去几天我一直在玩 Spring,事情变得很有趣。我现在正在与安全部门合作,但遇到了一些小问题。基本上,我希望通过 API 调用而不是表单进行身份验证。有没有一种巧妙的方法来做到这一点? 我已经像这样
我有 SPNEGO 的 spring 安全配置,它正在“破解”。它看起来如下: @Configuration @EnableWebSecurity public class SpnegoConfig
正如他们对我们的描述 here ,WebSecurityConfigurerAdapter 将在一段时间内弃用。 由于我想实现 JWT 模式,我尝试使用 SecurityFilterChain 重构
我正在构建一个需要处理两种类型身份验证的应用程序,所以我这样做了 @Autowired UserService userService; @Autowired public void configAu
我正在尝试在扩展 WebSecurityConfigurerAdapter 的类中使用 Spring 的 Security 的 Java 配置。我使用的是 3.2.0.RELEASE 版本。 在 Ht
我正在使用WebSecurityConfigurerAdapter,我想知道是否有办法配置WebSecurityConfigurerAdapter 中的错误处理程序就像以前在 web.xml 中一样我
我使用 SpringBoot 从事一个学校项目,并在添加了一些在互联网上看到的安全功能(WebSecurityConfigurerAdapter)后,我想知道是否有可能提取当前登录用户的用户名,因为我
In Spring security when I am using WebSecurityConfigurerAdapter, throws the following error. Anyone
构建 Spring 应用程序后,我遇到了这个问题: .../WebSecurityConfigurerAdapter.class] cannot be opened because it does
这些类之间有什么区别?我知道 WebSecurityConfigurerAdapter 用于自定义我们应用程序的“安全性”。 我做了什么: public class SecurityConfig ex
在我的 Spring Boot 应用程序中,我有以下两个类: @EnableWebSecurity public class AppSecurityConfig extends WebSecurity
我想为我网站上的某个“/interface”URL 启用 POST 请求。我已经通过 Class[] getRootConfigClasses() 成功加载了类(class), HttpSecurit
我是一名优秀的程序员,十分优秀!