Spring 如何在使用社交提供商成功登录后设置重定向url

Spring 如何在使用社交提供商成功登录后设置重定向url,spring,spring-social,Spring,Spring Social,当我的用户成功地使用一些Spring社交提供商登录时,我需要更改重定向url,比如在本例中的Twitter 我在每个集合***Url(“”)中都会得到一个空指针异常 有时,设置此选项也不起作用 到目前为止,我尝试设置: public ProviderSignInController signInController(ConnectionFactoryLocator connectionFactoryLocator,

当我的用户成功地使用一些Spring社交提供商登录时,我需要更改重定向url,比如在本例中的Twitter

我在每个集合***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;
    }
我使用SpringSocialShowcase和安全性作为基础来实现这一点。 如果需要,我将发布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());
    }
试试这个:

private SpringSocialConfigurer getSpringSocialConfigurer() {
        SpringSocialConfigurer config = new SpringSocialConfigurer();
        config.alwaysUsePostLoginUrl(true);
        config.postLoginUrl("/home");

        return config;
}
然后更改配置方法:

.apply(getSpringSocialConfigurer());

对于SpringSocial,您可以将登录后URL配置为默认URL,例如“/home”

但在某些情况下,您希望将用户指向不同的URL。为了在成功登录后动态更改重定向URL,只需在SignInAdapter实现类的signIn方法中返回一个表示所需URL的字符串:

import org.springframework.social.connect.web.SignInAdapter;
公共类SocialSignalinaDapter实现SignalinaDapter{
公共字符串签名(字符串localUserId、连接、NativeWebRequest){
布尔标志=真;
如果(标志){
返回“/一个不同的url”;
}
返回null;//默认值,这意味着使用默认的登录后URL
}
}

我用Spring社交版1.1.0验证了这一点。发布版

大家好,我有一个疑问。我将获得一个动态url。类似于这个.config.postLoginUrl(“/event?eventid=4”)。此事件id号将动态更改。有可能吗?请解释一下上面的问题。当你有时间的时候。