我想修改Spring Boot 1.3.2中OAuth2ClientAuthenticationProcessingFilter
配置创建的@EnableOAuth2Sso
。据我所知,OAuth2ClientAuthenticationProcessingFilter
类是在内部构造的,没有任何应用程序上下文连接。有没有办法做到这一点?
答案 0 :(得分:2)
不确定这是最好的方法,但您可以使用BeanPostProcessor执行此操作:
public static class DefaultRolesPrefixPostProcessor implements BeanPostProcessor, PriorityOrdered {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof FilterChainProxy) {
FilterChainProxy chains = (FilterChainProxy) bean;
for (SecurityFilterChain chain : chains.getFilterChains()) {
for (Filter filter : chain.getFilters()) {
if (filter instanceof OAuth2ClientAuthenticationProcessingFilter) {
OAuth2ClientAuthenticationProcessingFilter oAuth2ClientAuthenticationProcessingFilter = (OAuth2ClientAuthenticationProcessingFilter) filter;
oAuth2ClientAuthenticationProcessingFilter
.setAuthenticationSuccessHandler(authenticationSuccessHandler());
}
}
}
}
return bean;
}
}