spring – 如何使用Social Providers成功登录后设置重定向URL

前端之家收集整理的这篇文章主要介绍了spring – 如何使用Social Providers成功登录后设置重定向URL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

当我的用户使用一些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()
                .@R_502_395@ut()
                .@R_502_395@utUrl("/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());

猜你在找的Spring相关文章