社交配置器的拦截器(SocialAuthenticationFilter):Spring Social

时间:2016-06-04 10:39:46

标签: java spring facebook spring-security spring-social

功能正常,但我无法在使用SocialAuthenticationFilter时添加拦截器(类似于我们可以为ConnectController添加的拦截器)。

特别是我想在facebook oauth reuqest中添加display:popup。

如果您有任何解决方案,请告诉我。 感谢

安全配置:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.formLogin().loginPage("/login").failureUrl("/login/error")
            .loginProcessingUrl("/login/authenticate").defaultSuccessUrl("/login/success")
            .and().logout().logoutUrl("/logout").logoutSuccessUrl("/login?logout").deleteCookies("JSESSIONID")
            .and().authorizeRequests().antMatchers("/", "/register/**", "/login/**", "/faq").permitAll()
            .antMatchers("/favicon.ico", "/resources/**").permitAll()
            .antMatchers("/fonts/**", "/img/**", "/css/**", "/js/**", "/templates/**").permitAll()
            .antMatchers("/admin/**").hasRole("ADMIN")
            .antMatchers("/**").authenticated()
            .and().exceptionHandling().accessDeniedPage("/error/403")
            .and().csrf().disable().headers()
            .addHeaderWriter(new XFrameOptionsHeaderWriter(XFrameOptionsHeaderWriter.XFrameOptionsMode.SAMEORIGIN))
            .and().rememberMe()
            .and().apply(getSpringSocialConfigurer());
}

private SpringSocialConfigurer getSpringSocialConfigurer() {
    SpringSocialConfigurer config = new SpringSocialConfigurer();
    config.postLoginUrl("/dashboard");
    config.defaultFailureUrl("/error/403");
    config.signupUrl("/register/social");
    return config;
}

社交配置类:

@Configuration
@EnableSocial
public class SocialConfig extends SocialConfigurerAdapter {

    @Inject
    private DataSource dataSource;

    @Override
    public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
        //cfConfig.addConnectionFactory(new TwitterConnectionFactory(env.getProperty("twitter.appKey"), env.getProperty("twitter.appSecret")));
        cfConfig.addConnectionFactory(new FacebookConnectionFactory(env.getProperty("facebook.appKey"), env.getProperty("facebook.appSecret")));
    }

    @Override
    public UserIdSource getUserIdSource() {
        return new AuthenticationNameUserIdSource();
    }

    @Override
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
        return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText());
    }

    @Bean
    @Scope(value="request", proxyMode= ScopedProxyMode.INTERFACES)
    public Facebook facebook(ConnectionRepository repository) {
        Connection<Facebook> connection = repository.findPrimaryConnection(Facebook.class);
        return connection != null ? connection.getApi() : null;
    }
}

0 个答案:

没有答案