当我的用户使用一些Spring社交提供商(例如Twitter)成功登录时,我需要更改重定向URL.
我进入每一组*** Url(“”)一个空指针异常
有时设置它也不起作用
我到目前为止尝试设置:
public ProviderSignInController signInController(ConnectionFactoryLocator connectionFactoryLocator,UsersConnectionRepository usersConnectionRepository) {
ProviderSignInController providerSignInController = new ProviderSignInController(connectionFactoryLocator,usersConnectionRepository,new CSignInAdapter(requestCache()));
providerSignInController.setPostSignInUrl("/home");
providerSignInController.setApplicationUrl("localhost:8080/home");
return providerSignInController;
}
我分别尝试了setPostSignInUrl和setApplicationUrl中的每一个.
还尝试过:
@Bean
public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator,ConnectionRepository connectionRepository) {
ConnectController connectController = new ConnectController(connectionFactoryLocator,connectionRepository);
connectController.addInterceptor(new TweetAfterConnectInterceptor());
connectController.setApplicationUrl("/home");
return connectController;
}
我正在使用Spring Social showcase和Security作为基础来做到这一点.
如果需要,我发布HttpSecurity配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginPage("/signin")
.loginProcessingUrl("/signin/authenticate")
.failureUrl("/signin?param.error=bad_credentials")
.defaultSuccessUrl("/home")
.and()
.csrf()
.and()
.logout()
.logoutUrl("/signout")
.deleteCookies("JSESSIONID")
.and()
.authorizeRequests()
.antMatchers("/admin/**","/favicon.ico","/resources/**","/auth/**","/signin/**","/signup/**","/disconnect/facebook").permitAll()
.antMatchers("/**").authenticated()
.and()
.rememberMe()
.and()
.apply(new SpringSocialConfigurer());
}
最佳答案
试试这个:
原文链接:https://www.f2er.com/spring/431517.htmlprivate SpringSocialConfigurer getSpringSocialConfigurer() {
SpringSocialConfigurer config = new SpringSocialConfigurer();
config.alwaysUsePostLoginUrl(true);
config.postLoginUrl("/home");
return config;
}
然后更改配置方法:
.apply(getSpringSocialConfigurer());