Spring Social SocialAuthenticationFilter
处理网址/auth
。我该如何更改此网址?
方法SocialAuthenticationFilter.setFilterProcessesUrl(String filterProcessesUrl)
。如何访问SocialAuthenticationFilter
对象以使用此方法? (我使用SpringSocialConfigurer
,自动将SocialAuthenticationFilter
添加到链中。)
答案 0 :(得分:1)
不幸的是,使用原始SpringSocialConfigurer
您无法设置已处理的网址。查看代码,您可能只会"流利地配置postLoginUrl
,postFailureUrl
,signupUrl
,connectionAddedRedirectUrl
,defaultFailureUrl
和alwaysUsePostLoginUrl
等内容。
Imho在SpringSocialConfigurer
中遗漏了您可能想要在https://github.com/spring-projects/spring-social/issues提交问题。
目前,只需使用SpringSocialConfigurer
中的代码,然后提出自己的(小)课程。
答案 1 :(得分:1)
根据用户“Hille”的提议,我现在通过执行以下操作创建了自己的SpringSocialConfigurer
:
a)通过github(see here)我复制了源代码并将其粘贴到我的自定义类中。
b)然后我可以设置filterProcessesUrl
- 这是一个例子:
public class MySpringSocialConfigurer extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
@Override
public void configure(HttpSecurity http) throws Exception {
ApplicationContext applicationContext = http.getSharedObject(ApplicationContext.class);
UserIdSource userIdSource = getDependency(applicationContext, UserIdSource.class);
UsersConnectionRepository usersConnectionRepository = getDependency(applicationContext, UsersConnectionRepository.class);
SocialAuthenticationServiceLocator authServiceLocator = getDependency(applicationContext, SocialAuthenticationServiceLocator.class);
SocialUserDetailsService socialUsersDetailsService = getDependency(applicationContext, SocialUserDetailsService.class);
SocialAuthenticationFilter filter = new SocialAuthenticationFilter(
http.getSharedObject(AuthenticationManager.class),
userIdSource,
usersConnectionRepository,
authServiceLocator);
...
filter.setFilterProcessesUrl("/mysociallogin");
...
http.authenticationProvider(
new SocialAuthenticationProvider(usersConnectionRepository, socialUsersDetailsService))
.addFilterBefore(postProcess(filter), AbstractPreAuthenticatedProcessingFilter.class);
}
private <T> T getDependency(ApplicationContext applicationContext, Class<T> dependencyType) {
try {
T dependency = applicationContext.getBean(dependencyType);
return dependency;
} catch (NoSuchBeanDefinitionException e) {
throw new IllegalStateException("SpringSocialConfigurer depends on " + dependencyType.getName() +". No single bean of that type found in application context.", e);
}
}
}